aarontbarksdale Posted June 3, 2013 Share Posted June 3, 2013 Hey guys...it's me again...so, below you will find the script that I have that is supposed to update my database, however, it does NOTHING but return "Record Updated" and never updated anything. Any suggestions? $update = "UPDATE clients SET ( 'userid' = '{$_SESSION['myusername']}', 'cp_firstname' = '$_POST[cp_firstname]', 'cp_lastname' = '$_POST[cp_lastname]', 'cp_address' = '$_POST[cp_address]', 'cp_city' = '$_POST[cp_city]', 'cp_state' = ' $_POST[cp_state] ', 'cp_zip' = ' $_POST[cp_zip] ', 'cp_zip4' = ' $_POST[cp_zip4] ', 'cp_homeph' = '$_POST[cp_homeph] ', 'cp_workph' = '$_POST[cp_workph] ', 'cp_cellph' = '$_POST[cp_cellph] ', 'cp_email' = '$_POST[cp_email] ', 'alt_firstname' = '$_POST[alt_firstname] ', 'alt_lastname' = '$_POST[alt_lastname] ', 'alt_homeph' = '$_POST[alt_homeph] ', 'alt_cellph' = '$_POST[alt_cellph] ', 'non_firstname' = '$_POST[non_firstname] ', 'non_lastname' = '$_POST[non_lastname] ', 'non_home' = '$_POST[non_address] ', 'non_city' = '$_POST[non_city] ', 'non_state' = '$_POST[non_state] ', 'non_zip' = '$_POST[non_zip] ', 'non_zip4' = '$_POST[non_zip4] ', 'non_homeph' = '$_POST[non_homeph] ', 'non_workph' = '$_POST[non_workph] ', 'non_cellph' = '$_POST[non_cellph] ', 'non_email' = '$_POST[non_email] ', 'placeofemployment' = '$_POST[placeofemployment] ', 'datestart' = '$_POST[datestart] ', 'supportamount' = '$_POST[supportamount] ', 'judgmentdate' = '$_POST[judgmentdate] ', 'judge' = '$_POST[judge]', 'beg_bal' = '$_POST[beg_bal]' WHERE client_id='{$_SESSION['client_id']}')"; mysql_query($update);echo "Record updated"; Where'd I go wrong??? Link to comment Share on other sites More sharing options...
terryds Posted June 3, 2013 Share Posted June 3, 2013 Try this 'client_id' instead of client_id 1 Link to comment Share on other sites More sharing options...
aarontbarksdale Posted June 3, 2013 Author Share Posted June 3, 2013 Nope...didn't work Terryds. Link to comment Share on other sites More sharing options...
aarontbarksdale Posted June 3, 2013 Author Share Posted June 3, 2013 (edited) I have tried 'cp_address' = '". $_POST['cp_address'] ."' AND 'cp_address' = '{$_POST[cp_address]}' NOTHING has worked...all my tags and column names are correct, since I copied them from my INSERT code when adding the information for the first time. UPDATE:Okay, so using the BOTTOM code snippet, I added var_dump to check my variable and it IS reading the POST data, but not ADDING it... UPDATE #2:I even converted all the POST data to variables like $cp_address = $_POST['cp_address']; and again, the var_dump function shows that I DID type something in the form field. Below is the form page script: <form id="edit" name="edit" method="POST" action="edit_insert.php"> <table width="618" border="0" cellpadding="2" cellspacing="2" class="different" id="different"> <tr > <td colspan="2" align="center"><h2> <input type="hidden" name="user" value="<? echo $myusername ; ?>" /><input type="hidden" name="clientid" value="<? echo $clientid ; ?>" />Edit Client for User: <?php echo $row['cp_firstname'] ." ". $row['cp_lastname'] ; ?></h2></td> </tr> <tr> <td colspan="2" align="left"><blockquote> <h3>Custodial Parent Information</h3> </blockquote></td> </tr> <tr> <td width="354">First Name: <input type="text" name="cp_firstname" id="cp_firstname" value="<? echo "$row[cp_firstname]"?>" /></td> <td width="250"><label for="cp_firstname">Last Name: <input name="cp_lastname" type="text" id="cp_lastname" value="<? echo "$row[cp_lastname]"?>" /> </label></td> </tr> <tr> <td colspan="2"><p>Home Address: <input name="cp_address" type="text" id="cp_address" value="<? echo "$row[cp_address]"?>" size="50" /> </p></td> </tr> <tr> <td colspan="2">City: <input name="cp_city" type="text" id="cp_city" value="<? echo "$row[cp_city]"?>" /> State: <input name="cp_state" type="text" id="cp_state" value="<? echo "$row[cp_city]"?>" size="5" maxlength="2" /> Zip Code: <input name="cp_zip" type="text" id="cp_zip" value="<? echo "$row[cp_zip]"?>" size="9" maxlength="5" /> - <input name="cp_zip4" type="text" id="cp_zip4" value="<? echo "$row[cp_zip4]"?>" size="7" maxlength="4" /></td> </tr> <tr> <td>Home Phone: <input name="cp_homeph" type="text" id="cp_homeph" value="<? echo "$row[cp_homeph]"?>" /></td> <td>Work Phone: <input name="cp_workph" type="text" id="cp_workph" value="<? echo "$row[cp_workph]"?>" /></td> </tr> <tr> <td>Cell Phone: <input name="cp_cellph" type="text" id="cp_cellph" value="<? echo "$row[cp_cellph]"?>" /></td> <td>E-mail: <input name="cp_email" type="text" id="cp_email" value="<? echo "$row[cp_email]"?>" /></td> </tr> <tr> <td colspan="2"><blockquote> <blockquote> <p><em>Alternate Contact</em></p> </blockquote> </blockquote></td> </tr> <tr> <td>First Name: <input name="alt_firstname" type="text" id="alt_firstname" value="<? echo "$row[alt_firstname]"?>" /></td> <td>Last Name: <input name="alt_lastname" type="text" id="alt_lastname" value="<? echo "$row[alt_lastname]"?>" /></td> </tr> <tr> <td>Home Phone: <input name="alt_homeph" type="text" id="alt_homeph" value="<? echo "$row[alt_homeph]"?>" /></td> <td>Cell Phone: <input name="alt_cellph" type="text" id="alt_cellph" value="<? echo "$row[alt_cellph]"?>" /></td> </tr> <tr> <td colspan="2"> </td> </tr> <tr> <td colspan="2" ><blockquote> <h3>Non-Custodial Parent Information</h3> </blockquote></td> </tr> <tr> <td>First Name: <input name="non_firstname" type="text" id="non_firstname" value="<? echo "$row[non_firstname]"?>" /></td> <td><label for="textfield25">Last Name: <input name="non_lastname" type="text" id="non_lastname" value="<? echo "$row[non_lastname]"?>" /> </label></td> </tr> <tr> <td colspan="2"><p>Home Address: <input name="non_home" type="text" id="non_home" value="<? echo "$row[non_home]"?>" size="50" /> </p></td> </tr> <tr> <td colspan="2">City: <input name="non_city" type="text" id="non_city" value="<? echo "$row[non_city]"?>" /> State: <input name="non_state" type="text" id="non_state" value="<? echo "$row[non_state]"?>" size="5" maxlength="2" /> Zip Code: <input name="non_zip" type="text" id="non_zip" value="<? echo "$row[non_zip]"?>" size="9" maxlength="5" /> - <input name="non_zip4" type="text" id="non_zip4" value="<? echo "$row[non_zip4]"?>" size="7" maxlength="4" /></td> </tr> <tr> <td>Home Phone: <input name="non_homeph" type="text" id="non_homeph" value="<? echo "$row[non_homeph]"?>" /></td> <td>Work Phone: <input name="non_workph" type="text" id="non_workph" value="<? echo "$row[non_workph]"?>" /></td> </tr> <tr> <td>Cell Phone: <input name="non_cellph" type="text" id="non_cellph" value="<? echo "$row[non_cellph]"?>" /></td> <td>E-mail: <input name="non_email" type="text" id="non_email" value="<? echo "$row[non_email]"?>" /></td> </tr> <tr> <td colspan="2">Place of Employment: <input name="placeofemployment" type="text" id="placeofemployment" value="<? echo "$row[placeofemployment]"?>" /></td> </tr> <tr> <td colspan="2"> </td> </tr> <tr> <td>Support Start Date: <input name="datestart" type="text" id="datestart" value="<? echo "$row[datestart]"?>" /></td> <td>Support Amount/Month: <input name="supportamount" type="text" id="supportamount" value="<? echo "$row[supportamount]"?>" /></td> </tr> <tr> <td>Judgment Date Entered: <input name="judgmentdate" type="text" id="judgmentdate" value="<? echo "$row[judgmentdate]"?>" /></td> <td>Judge: <input name="judge" type="text" id="judge" value="<? echo "$row[judge]"?>" /></td> </tr> <tr> <td colspan="2" align="left"> <p>Beginning Balance:<input name="beg_bal" type="text" id="beg_bal" value="<? echo "$row[beg_bal]"?>" /> </span></p></td> </tr> <tr> <td colspan="2" align="center"><input type="submit" name="submit" id="submit" value="Edit" /></td> </tr> </table> </form> Edited June 3, 2013 by aarontbarksdale Link to comment Share on other sites More sharing options...
birbal Posted June 3, 2013 Share Posted June 3, 2013 check what does return mysql_query() and even query get successfully get executed or not. You can use mysql_error() to print any error mysql encounters 1 Link to comment Share on other sites More sharing options...
aarontbarksdale Posted June 3, 2013 Author Share Posted June 3, 2013 LOL...thanks for that, I don't know WHY I keep forgetting that little trick...the error reads: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '('userid = 'abark', 'cp_firstname' = 'Tyler', 'cp_lastname' = 'XXXX', 'cp' at line 1 So, perhaps my sql has been completely updated to MySQLi...if so, how do I update my query?? Link to comment Share on other sites More sharing options...
birbal Posted June 3, 2013 Share Posted June 3, 2013 (edited) mysqli has both OOP and modular API. modular API is quite same as mysql API. it have mysqli_query() it has another identical method in OOP. Query itself dont get changed with different API. SQL remains same.http://php.net/Mysqli Edited June 3, 2013 by birbal 1 Link to comment Share on other sites More sharing options...
justsomeguy Posted June 3, 2013 Share Posted June 3, 2013 Don't put quotes around field names. Quotes are for strings, not names. If you use a reserved word for a field or table name then you can use `backquotes` to make sure it sees it as an identifier and not a reserved word, but when you put single quotes around something you are saying that is a text string and not an identifier. The error message indicates that the first field name has an error. 1 Link to comment Share on other sites More sharing options...
aarontbarksdale Posted June 3, 2013 Author Share Posted June 3, 2013 Nothing...I tried it with ` back quotes ` and without any quotes. the error looks like it starts right at the SET portion. Var_dump returns correct information with regards to the first field name.....so, I have NO idea! Link to comment Share on other sites More sharing options...
justsomeguy Posted June 3, 2013 Share Posted June 3, 2013 My mistake, although what I said before was true, the error message actually indicates the open parenthesis as the problem. You shouldn't have the list of fields to update or the where clause inside parentheses. 1 Link to comment Share on other sites More sharing options...
aarontbarksdale Posted June 3, 2013 Author Share Posted June 3, 2013 Holy shnikees! That's the dang problem...Thanks again justsomeguy... Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now