homepage Welcome to WebmasterWorld Guest from 54.197.147.90
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
MySQL Not Updating
MySQL won't update from php process - no error received.
reffik024




msg:3940432
 7:01 pm on Jun 25, 2009 (gmt 0)

I'm trying to update tables with this form, not sure why it's not working.
Here's the form:

while ($row = mysql_fetch_array($result)) {
$first=$row['FIRST_NAME'];
$last=$row['LAST_NAME'];
$address=$row['ADDRESS'];
$city=$row['CITY'];
$phone=$row['PHONE'];
$email=$row['EMAIL'];
$ca_id=$row['CA_ID'];
$dname=$row['DOCTOR_NAME'];
$dlicense=$row['DOCTOR_LICENSE'];
$dphone=$row['DOCTOR_PHONE'];
$doh_id=$row['DOH_ID'];
$rec_i=$row['REC_ISSUE'];
$rec_e=$row['REC_EXP'];
$refer=$row['REFER'];
}
?>
<form action="updated.php" method="post">
<input type="hidden" name="name" value="<? echo $id; ?>">
First Name: <input type="text" name="FIRST_NAME" value="<? echo $first; ?>"><br>
Last Name: <input type="text" name="LAST_NAME" value="<? echo $last; ?>"><br>
Address: <input type="text" name="ADDRESS" value="<? echo $address; ?>"><br>
City: <input type="text" name="CITY" value="<? echo $city; ?>"><br>
Phone: <input type="text" name="PHONE" value="<? echo $phone; ?>"><br>
Email: <input type="text" name="EMAIL" value="<? echo $email; ?>"><br>
CA ID: <input type="text" name="CA_ID" value="<? echo $ca_id; ?>"><br>
Doctor's Name: <input type="text" name="DOCTOR_NAME" value="<? echo $dname; ?>"><br>
Doctor's License: <input type="text" name="DOCTOR_LICENSE" value="<? echo $dlicense; ?>"><br>
Doctor's Phone: <input type="text" name="DOCTOR_PHONE" value="<? echo $dphone; ?>"><br>
DOH ID: <input type="text" name="DOH_ID" value="<? echo $doh_id; ?>"><br>
Rec Issued: <input type="text" name="REC_I" value="<? echo $rec_i; ?>"><br>
Rec Expires: <input type="text" name="REC_E" value="<? echo $rec_e; ?>"><br>
Referred By: <input type="text" name="REFER" value="<? echo $refer; ?>"><br>
<input type="Submit" value="Update">
</form>

here's updated.php


if ($db_found) {
$SQL = "UPDATE patients SET (FIRST_NAME, LAST_NAME, BIRTHDATE, ADDRESS, CITY, PHONE, EMAIL, CA_ID, DOCTOR_NAME, DOCTOR_LICENSE, DOCTOR_PHONE, DOH_ID, REC_ISSUE, REC_EXP, REFER) VALUES ('$_POST[FIRST_NAME]', '$_POST[LAST_NAME]', '$_POST[BIRTHDATE]', '$_POST[ADDRESS]', '$_POST[CITY]', '$_POST[PHONE]', '$_POST[EMAIL]', '$_POST[CA_ID]', '$_POST[DOCTOR_NAME]', '$_POST[DOCTOR_LICENSE]', '$_POST[DOCTOR_PHONE]', '$_POST[DOH_ID]', '$_POST[REC_ISSUE]', '$_POST[REC_EXP]', '$_POST[REFER]')";

$result = mysql_query($SQL);

mysql_close($db_handle);

print "Records updated";
}
else {
print "Database NOT Found ";
mysql_close($db_handle);
}

[edited by: jatar_k at 8:31 pm (utc) on June 25, 2009]
[edit reason] fixed sidescroll [/edit]

 

LifeinAsia




msg:3940438
 7:12 pm on Jun 25, 2009 (gmt 0)

That's not the proper syntax for an UPDATE. Also, without a WHERE clause, you will updated EVERY row in the table with that information!

Proper UPDATE syntax:
UPDATE TableName SET
FieldName1=newvalue1,
FieldName2=newvalue2,
...
FieldNameN=newvalueN
WHERE condition

jatar_k




msg:3940491
 8:33 pm on Jun 25, 2009 (gmt 0)

another thing that is good while testing new queries, change

$result = mysql_query($SQL);

to

$result = mysql_query($SQL) or die ("<p>died: $SQL<br>" . mysql_error());

that will output the actual error from mysql

reffik024




msg:3941189
 7:10 pm on Jun 26, 2009 (gmt 0)

Thanks guys got it working!

Pico_Train




msg:3941470
 6:32 am on Jun 27, 2009 (gmt 0)

If you don't want to do $result = mysql_query($SQL) or die ("<p>died: $SQL<br>" . mysql_error());

You can echo your variable $SQL that way you get the exact query running. Then copy that query and try it in your phpMyadmin and it will give you the error messages as well.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved