inosent Posted May 27, 2010 Share Posted May 27, 2010 hi, i am not a php guru, and need some help. i have one page, search.htm, that ties to search.php, which successfully infills a form. this form is what is subject to any changes, if any, and the submit button hits updated.php. but updated php doesnt update the db. here is the search page: <html> <head> <title>Search the Database</title> </head> <body> <form action="search.php" method="post"> Search: <input type="text" name="term" /><br /> <input type="submit" name="submit" value="Submit" /> </form> </body> </html> this is search.php, where the form contents are successfully filled in from the search: <?php include("dbinfo.inc.php"); mysql_connect(localhost,$username,$password); mysql_select_db($database) or die( "Unable to select database"); $term = $_POST['term']; $sql = mysql_query("select * from data1 where id = '$term'"); while ($row = mysql_fetch_array($sql)){ echo "Record: "; echo $term; ?> <form action="updated.php"> <input type="hidden" name="id" value="<?php echo $row['id']; ?>"> First Name: <input type="text" name="first" value="<?php echo $row['first'];?>"><br> Last Name: <input type="text" name="last" value="<?php echo $row['last'];?>"><br> Street: <input type="text" name="street" value="<?php echo $row['street'];?>"><br> City: <input type="text" name="city" value="<?php echo $row['city'];?>"><br> State: <input type="text" name="state" value="<?php echo $row['state'];?>"><br> Zip: <input type="text" name="zip" value="<?php echo $row['zip'];?>"><br> Fee Rcd (Y/N): <input type="text" name="fee_rcpt" value="<?php echo $row['fee_rcpt'];?>"><br> Date Rcd: <input type="text" name="date_rcd" value="<?php echo $row['date_rcd'];?>"><br> Opened By: <input type="text" name="opnd_by" value="<?php echo $row['opnd_by'];?>"><br> Check Encl (Y/N): <input type="text" name="check_encl" value="<?php echo $row['check_encl'];?>"><br> <input type="Submit" value="Update"> </form> <?php } ?> and this is the code for updated.php, which does not do anything <?php include("dbinfo.inc.php"); mysql_connect(localhost,$username,$password); mysql_select_db($database) or die( "Unable to select database"); mysql_query($query); $first = mysql_real_escape_string ($_POST['first']); echo $first; $last = mysql_real_escape_string($_POST['last']); $street = mysql_real_escape_string($_POST['street']); $city = mysql_real_escape_string($_POST['city']); $state = mysql_real_escape_string($_POST['state']); $zip = mysql_real_escape_string($_POST['zip']); $fee_rcpt = mysql_real_escape_string($_POST['fee_rcpt']); $date_rcd = mysql_real_escape_string($_POST['date_rcd']); $opnd_by = mysql_real_escape_string($_POST['opnd_by']); $check_encl = mysql_real_escape_string($_POST['check_encl']); $query="UPDATE data1 SET first='$first', last='$last', street='$street', city='$city', state='$state', zip='$zip', fee_rcpt='$fee_rcpt', date_rcd='$date_rcd', opnd_by='$opnd_by', check_encl='$check_encl' WHERE id=''"; echo "Record Updated"; mysql_close(); ?> what i want is the form contents to go into the MySQL db record indicated by the 'id' any ideas are welcome! Quote Link to comment https://forums.phpfreaks.com/topic/203034-revise-a-mysql-record-with-php-form-contents/ Share on other sites More sharing options...
Andy-H Posted May 27, 2010 Share Posted May 27, 2010 <?php include("dbinfo.inc.php"); mysql_connect(localhost,$username,$password); mysql_select_db($database) or die( "Unable to select database"); // mysql_query($query); you can't run the query until you build the query string... $id = (int)$_POST['id']; $first = mysql_real_escape_string ($_POST['first']); echo $first; $last = mysql_real_escape_string($_POST['last']); $street = mysql_real_escape_string($_POST['street']); $city = mysql_real_escape_string($_POST['city']); $state = mysql_real_escape_string($_POST['state']); $zip = mysql_real_escape_string($_POST['zip']); $fee_rcpt = mysql_real_escape_string($_POST['fee_rcpt']); $date_rcd = mysql_real_escape_string($_POST['date_rcd']); $opnd_by = mysql_real_escape_string($_POST['opnd_by']); $check_encl = mysql_real_escape_string($_POST['check_encl']); $query="UPDATE data1 SET first='$first', last='$last', street='$street', city='$city', state='$state', zip='$zip', fee_rcpt='$fee_rcpt', date_rcd='$date_rcd', opnd_by='$opnd_by', check_encl='$check_encl' WHERE id=$id"; if (mysql_query($query)) { echo "Record Updated"; } else { echo "An error has occured."; } mysql_close(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/203034-revise-a-mysql-record-with-php-form-contents/#findComment-1063890 Share on other sites More sharing options...
inosent Posted May 27, 2010 Author Share Posted May 27, 2010 it looks good but it wont fire here are the links to the site so you can see what i am seeing the database output where i can see if there are any changes or not http://inovacapitalmanagement.com/mysql this is the page to run the search http://inovacapitalmanagement.com/mysql/search.htm and from there search.php get the contents, but when i click 'update' the updated.php file isn't working. and when i try to echo something from the incoming search.php file nothing appears on the screen not sure how to connect the contents of search.php tp updated.php. thanks for the reply Quote Link to comment https://forums.phpfreaks.com/topic/203034-revise-a-mysql-record-with-php-form-contents/#findComment-1063901 Share on other sites More sharing options...
PFMaBiSmAd Posted May 27, 2010 Share Posted May 27, 2010 <form action="updated.php"> Your form has no method="..." attribute and the default method is GET, so none of your $_POST data exists. Add method="post" to your <form tag... Quote Link to comment https://forums.phpfreaks.com/topic/203034-revise-a-mysql-record-with-php-form-contents/#findComment-1063902 Share on other sites More sharing options...
inosent Posted May 27, 2010 Author Share Posted May 27, 2010 ah, dang it, completely missed that ... thank you! it works! Quote Link to comment https://forums.phpfreaks.com/topic/203034-revise-a-mysql-record-with-php-form-contents/#findComment-1063905 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.