josephman1988 Posted August 17, 2008 Share Posted August 17, 2008 Ok guys, so I have a form where i want to edit and change the data within that field. Here's the code I have so far: <h1>Edit Operation</h1> <hr /> Editing Operation: <span class="subhead"><?php print $operation['name']; ?></span> </div> <!-- ADMIN BOX 1 --> <div id="adminbox1"> <?php $doid = $_GET['oid']; $sql = @mysql_query("SELECT * FROM operation_data"); while ($odata = mysql_fetch_array($sql)) { ?> <form action='<?php $_SERVER['PHP_SELF']; ?>' method='post'> Case Name:<br /> <input type='text' name='name' value='<?php print $odata['name']; ?>' /> Case Briefing:<br /> <textarea cols='50' rows='10' name='briefing'><?php print $odata['briefing']; ?></textarea> <input type="submit" value="Edit Operation" /> </form> <?php } $upnamenew = $_POST['name']; $upbriefingnew = $_POST['briefing']; print $upnamenew; print $upbriefingnew; Up to this point, I 'believe' I have succeeded as printing the results give me the newly entered fields. HOWEVER, the update query just doesn't update. $sql2 = @mysql_query("UPDATE FROM operation_data SET name = $upnamenew, briefing = $upbriefingnew WHERE oid = $doid"); I get a syntax error about this paticular query, with the new data added: UPDATE FROM operation_data SET name = bla, briefing = $blahmore WHERE oid = 1" And the data in the operation table: ----------------------- | oid | name | briefing | ----------------------- Doesn't update. Any help would be great. Thanks. Link to comment https://forums.phpfreaks.com/topic/120077-updating-mysql-data-via-a-form/ Share on other sites More sharing options...
cooldude832 Posted August 17, 2008 Share Posted August 17, 2008 if u are asking mysql related questions you must do 2 things before anyone can help you 1) Do not suppress the error on the function via the @ symbol (This holds true for any function you think is failing) 2) Use the or die clause on a query ($q = "Select * from `table`"; $r = mysql_query($q) or die(mysql_error()."<Br /><br />\n\n".$q);) 3) Display the error if there is one. Do this then post back Link to comment https://forums.phpfreaks.com/topic/120077-updating-mysql-data-via-a-form/#findComment-618565 Share on other sites More sharing options...
josephman1988 Posted August 17, 2008 Author Share Posted August 17, 2008 Thankyou for the quick reply. After editing the lines you suggested to change, and adding it into an if statement: if (isset($upnamenew, $upbriefingnew)) { $sql2 = mysql_query("UPDATE FROM operation_data SET name = $upnamenew, briefing = $upbriefingnew WHERE 'oid' = $doid") or die(mysql_error() . $sql2); } Displays the following after submitting the form: 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 'FROM operation_data SET name = change title, briefing = change briefing WHERE 'o' at line 1 Link to comment https://forums.phpfreaks.com/topic/120077-updating-mysql-data-via-a-form/#findComment-618570 Share on other sites More sharing options...
cooldude832 Posted August 17, 2008 Share Posted August 17, 2008 well that isn't the query that is error because I don't see the word "from" in it. Link to comment https://forums.phpfreaks.com/topic/120077-updating-mysql-data-via-a-form/#findComment-618573 Share on other sites More sharing options...
Mchl Posted August 17, 2008 Share Posted August 17, 2008 Change UPDATE FROM operation_data SET name = $upnamenew, briefing = $upbriefingnew WHERE oid = $doid to UPDATE operation_data SET name = $upnamenew, briefing = $upbriefingnew WHERE oid = $doid Always check mysql statement syntax section in mySQL docs (section 12) http://dev.mysql.com/doc/refman/5.0/en/sql-syntax.html Link to comment https://forums.phpfreaks.com/topic/120077-updating-mysql-data-via-a-form/#findComment-618575 Share on other sites More sharing options...
josephman1988 Posted August 17, 2008 Author Share Posted August 17, 2008 Thank you both for your replies. When I changed the query, and submitted the form, the value from the 'name' field is perceived as a column in the db? Unknown column 'Test Title' in 'field list' Thanks again guys. Link to comment https://forums.phpfreaks.com/topic/120077-updating-mysql-data-via-a-form/#findComment-618581 Share on other sites More sharing options...
Mchl Posted August 17, 2008 Share Posted August 17, 2008 Add quotes when storing strings: UPDATE operation_data SET name = '$upnamenew', briefing = '$upbriefingnew' WHERE oid = $doid Better yet, read about prepared statements in php mysql manual Link to comment https://forums.phpfreaks.com/topic/120077-updating-mysql-data-via-a-form/#findComment-618585 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.