Click to See Complete Forum and Search --> : Database Update Script


scottyrob
10-20-2006, 02:18 AM
Hi,
Ive just made the following but it dosent want to work... When i submit the information, the page just refreshes with the original old data. Any ideas how to fix it and improve the script?

Cheers,
Scott

update.php

<?php require("index_top.php"); require("index_left.php"); ?>

<?php

require("files/db_connect.php");

$result = @mysql_query("SELECT * FROM tbl_register WHERE reg_id = ".$_GET["reg_id"]);

while ($row = mysql_fetch_assoc($result))
{
echo "<form method='post' action='update_script.php'>";
echo "<input type='text' name='email_id' value='{$row['email_id']}';";
echo "<br><br><input type='text' name='reg_id' value='{$row['reg_id']}';";
echo "<br><br><input type='text' name='fullname' value='{$row['fullname']}';";
echo "<br><br><input type='text' name='username' value='{$row['username']}';";
echo "<br><br><input type='text' name='password' value='{$row['password']}';";
echo "<br><br><input type='text' name='status' value='{$row['status']}';";
echo "<input type='submit' name='update' value='Update' >";
echo "</form>";
}

?>

<?php require("index_right.php"); require("index_bottom.php"); ?>



update_script.php


<?php

require("files/db_connect.php");

$reg_id=$_POST['reg_id'];
$email_id=$_POST['email_id'];
$fullname=$_POST['fullname'];
$username=$_POST['username'];
$password=$_POST['password'];
$status=$_POST['status'];


$query = "UPDATE tbl_register SET email_id = '$email_id', fullname = '$fullname', username = '$username', password = '$password', status = '$status' WHERE reg_id = '$reg_id'";
mysql_query($query);
?>

theRamones
10-20-2006, 02:43 AM
1. $query = "UPDATE tbl_register SET email_id = '$email_id', fullname = '$fullname', username = '$username', password = '$password', staus = '$status' WHERE reg_id = '$reg_id'";
in this query, did you mean status = '$status' not staus = '$status'

2. maybe you forgot to add this line mysql_query($query) after that query(update_script.php)
$query = xxxx;
mysql_query($query);

scottyrob
10-20-2006, 03:06 AM
updates the above but it still seems to do the same

theRamones
10-20-2006, 03:27 AM
print out $query and try to update it manually on mysql, is the records values change (check with select) or error ??

scottyrob
10-21-2006, 02:26 AM
:s what did you mean by the last post?

chazzy
10-21-2006, 08:14 AM
Always, always check to see that your query worked. At the bare minimum, use a die() for development purposes.

$query = "UPDATE tbl_register SET email_id = '$email_id', fullname = '$fullname', username = '$username', password = '$password', status = '$status' WHERE reg_id = '$reg_id'";
mysql_query($query) or die("<pre>The query failed - $query : ".mysql_error()."</pre>");