jp15 Posted March 1, 2010 Share Posted March 1, 2010 Hi please help, trying to delete a value from a drop down list populated by a table in my database. this is the code: <? $conn = mysql_connect('localhost','**','**'); $db = mysql_select_db(**'); if(isset($_POST['id']) && !empty($_POST['id'])){ $id = mysql_real_escape_string($_POST['id']); $sql = "DELETE FROM `upload2` WHERE `id` = $id"; $result = mysql_query($sql); $num = mysql_affected_rows(); if($num == 1){ echo "<p>Record $id deleted successfully.</p>\n"; }else{ echo "<p>Unable to delete record $id.</p>\n"; } } ?> <form action="$PHP_SELF" method="post"> Name to delete:<br /> <select name="id"> <? $sql = "SELECT `id`,`name`, FROM `upload2` ORDER BY `name`; $result = mysql_query($sql); while($row = mysql_fetch_assoc($result)){ echo '<option value="' . $row['id'] . '">' . $row['name'] . '</option>' . "\n"; } ?> </select> <input type="submit" value="Delete" /> </form> and this is the error: Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /.automount/barra4/ug/home/jp15v07/public_html/discard.php on line 29 Line 29 : echo '<option value="' . $row['id'] . '">' . $row['name'] . '</option>' . "\n"; Ive looked up the error but am fairly new to php so cant seem to solve it, appreciate any help thanks. Quote Link to comment https://forums.phpfreaks.com/topic/193778-help-with-delete-from-mysql-drop-down-list-please/ Share on other sites More sharing options...
PFMaBiSmAd Posted March 1, 2010 Share Posted March 1, 2010 The problem is because there is no closing double-quote in the following line - $sql = "SELECT `id`,`name`, FROM `upload2` ORDER BY `name`; The quotes encountered in the line where the error is reported at signaled the language parser that something was amiss with the code (it cannot tell that you did not intend everything after the missing closing quote to be part of that statement.) Parse errors often are due to something wrong before the line where the error is reported at because php cannot know what the programmer intended when he left out an element of the syntax. Quote Link to comment https://forums.phpfreaks.com/topic/193778-help-with-delete-from-mysql-drop-down-list-please/#findComment-1019907 Share on other sites More sharing options...
jp15 Posted March 2, 2010 Author Share Posted March 2, 2010 Thanks! problem solved, Quote Link to comment https://forums.phpfreaks.com/topic/193778-help-with-delete-from-mysql-drop-down-list-please/#findComment-1020525 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.