I know I am going get sticks from you guys for using mysql_**
but I have to at the moment as I am far into the project and I cannot go back and start again. So please be gentle.
Anyway, I don't understand why my update table doesn't work!!
This is the code:
<?php
$host="localhost"; // Host name
$username="mydetails"; // Mysql username
$password="XXXXXXX"; // Mysql password
$db_name="mydetails"; // Database name
$tbl_name="members"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// get value of id that sent from address bar
$id=$_GET['id'];
// Delete data in mysql from row that has this id
$result = mysql_query ("UPDATE $tbl_name SET balance='$balance' WHERE id='$id'");
// if successfully deleted
if($result){
echo "The user has been banned successfully!";
echo "<BR>";
echo "<a href='suspend_users.php'>Back to main page</a>";
}
else {
echo "ERROR";
}
?>
<?php
// close connection
mysql_close();
?>
If I remove the $balance
and leave ''
empty or replace $balance
with a text or number, it will enter it the balance column which means it does work and connects successfully to the database without any issue. But when I say balance='$balance'
it doesn't work at all.
I do have a input field with id="balance"
and name="balance"
as well so that is not missing.
Can someone please help me out with this without giving me a griff for using mysql_*
?
Thanks
Update:
my form code:
<tr>
<td bgcolor="#FFFFFF"><? echo $rows['id']; ?></td>
<td bgcolor="#FFFFFF"><? echo $rows['username']; ?></td>
<td bgcolor="#FFFFFF"><? echo $rows['email']; ?></td>
<td bgcolor="#FFFFFF"><? echo $rows['balance']; ?></td>
<td bgcolor="#FFFFFF"><input name="balance" type="text" id="balance" value="<? echo $rows['balance']; ?>" size="15"></td>
<td bgcolor="#FFFFFF"><a href="delete_ac.php?id=<? echo $rows['id']; ?>">Ban and Remove</a></td>
</tr>