This is probably a rookie mistake, so if you could help me debug this I'd appreciate it greatly.
A few points of info regarding what's below:
A) "connect.php" contains the database name, username and password. It works with all my other pages so it's probably not the problem.
B) The variables are being passed from an update form. The idea is to pull the data out of the database via the earlier form, examine and update it and pass the changes to the database with this script.
C) When the update form is submitted, there are no error messages returned, and the echo "Record updated now" appears on the screen. It just simply doesn't change the data in the database.
D) The table name "schools" is correct and works great in my other "insert" form. There are only 4 fields in the table - id, name, city and region.
I'm sure I've just overlooked something...any suggestions? *bangs head on monitor*
I added the 'or die' you showed and there are still no error messages.
There are two forms involved in the process, so I will show both. First there is a search form to find the info out of the database. It appears to work fine, as it does pull the data out of the database and load it into a form for editing:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Untitled Document</title></head><body><form action="updateschoolname.php" method="POST" name="schoolnamesearch">
Search by school name:
<input name="search" type="text" size="50" maxlength="50" /><input name="submit" type="submit" value="Submit" /></form></body></html>
********************end of code*******************************************
Then the editing form (named "updateschoolname.php) allows the user to change the data and passes that changed data to my original script (named "updated.php") to be updated in the database. Here is the editing form:
<? include("connect.php"); $search=$_POST['search']; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to Select database"); $query="SELECT * FROM schools WHERE name='$search'"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close();
***************************end of code************************************
There HAS to be something I'm missing here. As I said, everything APPEARS to run just fine - there are no error messages returned anywhere - but the data in the database doesn't change.
I really appreciate any help anyone here can offer. Thanks so much!
include("connect.php"); $connection = mysql_connect('localhost', $username, $password) or die('Could not connect[IMG]http://kona.kontera.com/javascript/lib/imgs/grey_loader.gif[/IMG] to database.<br />'.mysql_error()); mysql_select_db($database) or die('Could not select database.<br />'.mysql_error()); $ud_id= $_POST['ud_id']; $ud_name=$_POST['ud_name']; $ud_city=$_POST['ud_city']; $ud_region=$_POST['ud_region']; $query= "UPDATE schools SET name='$ud_name', city='$ud_city', region='$ud_region' WHERE id='$ud_id'"; $result=mysql_query($query); echo "Record Updated Now<br/><br/> ID = $ud_id<br/> Name = $ud_name<br/> City = $ud_city<br/> Region = $ud_region "; mysql_close();
I just fixed this problem....after mdhall asked me to post the form code, I was looking at it from a new perspective and noticed there was no method defined in the form tag that called "updated.php" (if you look above you will notice this right away if you know to look for it). Hence the forms and scripts were working fine but it wouldn't update because no data was actually being passed via POST but the script was looking for POSTed data. Thanks for your help, it got me thinking on the right path instead of wondering what was wrong with the last .php script. Appreciate it!