我在提交時更新數據庫時遇到小問題。數據庫在提交時不更新數值
我在我的數據庫中有以下內容: 一個名爲iUserCash的varchar。
登錄後,我想編輯我的數據庫表中的這一行。
的HTML如下:
<form method="post">
<table class="sign_up_form" align="center" width="30%" border="0">
<tr>
<td>
<input type="text" name="cashBalance" placeholder="Nye beløb"/>
</td>
<td>
<button type="submit" name="btn-update" class="betting-btn">OPDATER</button>
</td>
<td>
</tr>
<tr>
</tr>
</table>
</form>
我的SQL是這樣的:
session_start();
include_once 'controllers/dbConnect.php';
if(!isset($_SESSION['user']))
{
header("Location: index.php");
}
$res=mysql_query("SELECT * FROM oneusers WHERE iUserId=".$_SESSION['user']);
$userRow=mysql_fetch_array($res);
if(isset($_POST['btn-update']))
{
$ucash = mysql_real_escape_string($_POST['cashBalance']);
if(mysql_query("UPDATE oneusers SET iUserCash = '$ucash' WHERE iUserId='$res'"))
{
?>
<script>alert('successfully registered ');</script>
<?php
}
else
{
?>
<script>alert('error while registering you...');</script>
<?php
}
}
它返回成功消息就好了,但它只是不進行任何更新。誰能告訴我我做錯了什麼? :) 在此先感謝。
'$ res'不是一個值,它是一個資源,所以'iUserId ='$ res''沒有任何意義。 –
在表單中傳遞隱藏字段中的iUserId並在更新查詢中使用它 – JYoThI
現在不推薦使用原始MySQL擴展,並且在連接到數據庫時會生成E_DEPRECATED錯誤。而是使用MYSQLi或PDO_MySQL擴展。準備好的聲明 – JYoThI