Reputation: 411
I have a small issue with updating my database upon a submit.
I have the following in my Database: a varchar called iUserCash.
Upon login I would like to edit this row in my database table.
The html looks like this:
<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>
And my sql looks like this:
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
}
}
It returns the success message just fine, but it just doesnt update anything. Can anyone tell me what I am doing wrong? :) Thanks in advance.
Upvotes: 0
Views: 40
Reputation: 5316
you have a error at
mysql_query("UPDATE oneusers SET iUserCash = '$ucash' WHERE iUserId='$res'")
you are using $res for iUserId but it's a db resource...
it seems that, $_SESSION['user'] is the id that you need in query... so try it like
mysql_query("UPDATE oneusers SET iUserCash = '$ucash' WHERE iUserId=" . $_SESSION['user']);
Upvotes: 1