lampquest Posted February 5, 2007 Share Posted February 5, 2007 Hello friends, I am having problem writing an update statement to modify data in a mysql table named clientlog. Just cant figure out what is wrong with my statement. Pls help me out. My current code is as follows: $sql = "update clientlog set unique_id = '$serial', customer_code = '$code', customer_name = '$name', customer_address = '$address', phone = '$phone', customer_email = '$email', service_type = '$service', description = '$description', quote_ammount = '$quote', remarks = '$remark' where unique_id = '$serial'"; $result = mysql_query($sql); if (!$result) { echo "<center><font color='red'>Query Error</font><br><br> Error Updating Entries !</center>"; } else { echo "<center><br><br> <font color='red'> <b>Update Okay!</b></font> <br><br> Client with serial no $unique_id has been successfully changed.</font> <br><br></center>"; } I always get error updating entries. Femi Link to comment https://forums.phpfreaks.com/topic/37146-solved-problem-updating-data-in-a-mysql-table/ Share on other sites More sharing options...
Balmung-San Posted February 5, 2007 Share Posted February 5, 2007 Set $result = mysql_query($sql); to $result = mysql_query($sql) or die(mysql_error()); and see if that generates an error. The query looks fine to me though, except you have quote_ammount, when it should probably be quote_amount. Link to comment https://forums.phpfreaks.com/topic/37146-solved-problem-updating-data-in-a-mysql-table/#findComment-177366 Share on other sites More sharing options...
lampquest Posted February 5, 2007 Author Share Posted February 5, 2007 Hello Balmung-San, your tip helped a lot. My tablename wasnt correct and when I corrected it, it says update okay but surprisingly it's not actually updating. Pls still help further if you can. this is what I have now: <?php $code = $HTTP_POST_VARS['customer_code']; $name = $HTTP_POST_VARS['customer_name']; $address = $HTTP_POST_VARS['customer_address']; $phone = $HTTP_POST_VARS['customer_phone']; $email = $HTTP_POST_VARS['customer_email']; $service = $HTTP_POST_VARS['service_type']; $description = $HTTP_POST_VARS['service_description']; $quote = $HTTP_POST_VARS['quote_ammount']; $remark = $HTTP_POST_VARS['staff_remark']; if ($code == "") {echo "<li> Pls, specify Customer Code"; $error = 1;} if ($name == "") {echo "<li> Pls, specify Customer Name"; $error = 1;} if ($address == "") {echo "<li> Pls, specify Customer Name"; $error = 1;} if ($phone == "") {echo "<li> Pls, specify Customer Phone"; $error = 1;} if ($email == "") {echo "<li> Pls, specify Customer Email Address"; $error = 1;} if ($service == "") {echo "<li> Pls, select a Service Type"; $error = 1;} if ($quote == "") {echo "<li> Pls, specify Quote Ammount"; $error = 1;} if (!eregi("@",$email) or !eregi("\.",$email)) {echo "<li> Pls, specify valid Email Address"; $error = 1;} if ($error==1) { echo "<br><br><a href='javascript:history.back(-1)'>Click here</a> to make necessary adjustments as stated above !"; } else { include "connect.php"; $date = date("y-m-d"); $unique_id = $service.$code.$date; $sql = "update client_log set customer_code = '$code', customer_name = '$name', customer_address = '$address', phone = '$phone', customer_email = '$email', service_type = '$service', description = '$description', quote_ammount = '$quote', remarks = '$remark' where unique_id = '$serial'"; $result = mysql_query($sql); if (!$result) { echo "<center><font color='red'>Query Error</font><br><br> Error Updating Entries !</center>"; } else { echo "<center><br><br> <font color='red'> <b>Update Okay!</b></font> <br><br> Client with serial no $unique_id has been successfully changed.</font> <br><br></center>"; } } ?> Femi Link to comment https://forums.phpfreaks.com/topic/37146-solved-problem-updating-data-in-a-mysql-table/#findComment-177433 Share on other sites More sharing options...
Balmung-San Posted February 5, 2007 Share Posted February 5, 2007 If possible avoid using $HTTP_POST_VARS, and instead use $_POST. Also, does that row actually exist? If not I believe MySQL will just return a result of 0 rows (which is still a valid result). Also, in your query, if the fields aren't strings, then don't put the single quotes around the variable. MySQL will interpret what the variable contains as a string, even if you meant for it to be an integer. Oh, and I find the following regex to be a bit better at evaluating valid emails: \b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b It literally checks for an email to be fully valid (anything before an @ sign, then any domain, then 2-4 characters after a dot, assuming I read that right). Link to comment https://forums.phpfreaks.com/topic/37146-solved-problem-updating-data-in-a-mysql-table/#findComment-177437 Share on other sites More sharing options...
lampquest Posted February 5, 2007 Author Share Posted February 5, 2007 \b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b sounds very good. But pls enlighten me more. How do I deploy that relative to my current one which: if (!eregi("@",$email) or !eregi("\.",$email)) {echo "<li> Pls, specify valid Email Address"; $error = 1;} . You have been very helpful. Thanx Link to comment https://forums.phpfreaks.com/topic/37146-solved-problem-updating-data-in-a-mysql-table/#findComment-177452 Share on other sites More sharing options...
Balmung-San Posted February 5, 2007 Share Posted February 5, 2007 Use this: if(!eregi("\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b", $email)) { echo "<li> pls, specify valid Email Address"; $error = 1;} Link to comment https://forums.phpfreaks.com/topic/37146-solved-problem-updating-data-in-a-mysql-table/#findComment-177455 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.