brainstorm Posted June 24, 2009 Share Posted June 24, 2009 Hi All, Please see the code for "update.php" below...I can't get this update script to actually update the DB. When I click the "update" link on "myadminaccount.php", it brings me over to "update.php" and displays the info from the DB. However, once I change the info and hit submit, it doesn't update the database! Additonally, I get no error. I know this is just something simple that I'm missing and any help you could offer would be much appreciated! Thanks! php: <? // START PHP CODES. THIS PART MUST ON THE TOP OF THIS PAGE. // Connect database. include("dbc.php"); // ***** This part will process when you Click on "Submit" button ***** if($_POST['Submit']){ // Get parameters from form. $id=$_GET['id']; $full_name=$_POST['full_name']; $user_email=$_POST['user_email']; $account_num=$_POST['account_num']; $due_date=$_POST['due_date']; $user_pwd=$_POST['user_pwd']; $address=$_POST['address']; $joined=$_POST['joined']; // Do update statement. mysql_query("UPDATE users SET full_name = '$full_name', account_num = '$account_num', user_email = '$user_email', amount_due = '$amount_due', due_date = '$due_date', user_pwd = '$user_pwd',address = '$address', joined = '$joined' where id = '$id'"); // Re-direct this page to select.php. header("location:myadminaccount.php"); exit; } // ************* End update part ************* // *** Select data to show on text fields in form. *** // Get id parameter (GET method) from update.php $id=$_GET['id']; // Get records in all columns from table where column id equal in $id and put it in $result. $result=mysql_query("select * from users where id='$id'"); // Split records in $result by table rows and put them in $row. $row=mysql_fetch_assoc($result); // Close database connection. mysql_close(); ?> Form: <p> <!-- set this form to POST method and target this form to itself ($PHP_SELF;)--> <form id="form1" name="form1" method="post" action="update.php"> <p>Account# : <!-- name of this text field is "account_num" --> <input name="account_num" type="text" id="account_num" value="<? echo $row['account_num']; ?>"/> <br /> Name : <!-- name of this text field is "full_name" --> <input name="full_name" type="text" id="full_name" value="<? echo $row['full_name']; ?>"/> <br /> User Password : <!-- name of this text field is "user_pwd" --> <input name="user_pwd" type="text" id="user_pwd" value="<? echo $row['user_pwd']; ?>"/> <br /> Email : <!-- name of this text field is "user_email" --> <input name="user_email" type="text" id="user_email" value="<? echo $row['user_email']; ?>"/> <br /> Address : <!-- name of this text field is "address" --> <input name="address" type="text" id="address" value="<? echo $row['address']; ?>"/> <br /> Origination Date : <!-- name of this text field is "joined" --> <input name="joined" type="text" id="joined" value="<? echo $row['joined']; ?>"/> <br /> Amount Due : <!-- name of this text field is "amount_due" --> <input name="amount_due" type="text" id="amount_due" value="<? echo $row['amount_due']; ?>"/> <br /> Due Date : <!-- name of this text field is "due_date" --> <input name="due_date" type="text" id="due_date" value="<? echo $row['due_date']; ?>"/> <br /> </p> <p> <input type="submit" name="Submit" value="Submit" /> </p> </form> </p> Quote Link to comment Share on other sites More sharing options...
J.Daniels Posted June 24, 2009 Share Posted June 24, 2009 If the UPDATE query fails, it will only return false. Check if there are any errors: mysql_query("UPDATE users SET full_name = '$full_name', account_num = '$account_num', user_email = '$user_email', amount_due = '$amount_due', due_date = '$due_date', user_pwd = '$user_pwd',address = '$address', joined = '$joined' where id = '$id'") or trigger_error('Error: '.mysql_error(), E_USER_ERROR); Quote Link to comment Share on other sites More sharing options...
brainstorm Posted June 25, 2009 Author Share Posted June 25, 2009 If the UPDATE query fails, it will only return false. Check if there are any errors: mysql_query("UPDATE users SET full_name = '$full_name', account_num = '$account_num', user_email = '$user_email', amount_due = '$amount_due', due_date = '$due_date', user_pwd = '$user_pwd',address = '$address', joined = '$joined' where id = '$id'") or trigger_error('Error: '.mysql_error(), E_USER_ERROR); I added the mysql_error syntax and still nothing...It just redirects to the "myadminaccount.php" page and doesn't update the database. Any thoughts? Thanks! Quote Link to comment Share on other sites More sharing options...
brainstorm Posted June 25, 2009 Author Share Posted June 25, 2009 I've got it to work now! Thanks! Apprently I was missing the $_GET variable and then also missing another variable called "amount_due"...As soon as I added them in, it worked perfectly! Thanks again! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.