Author Topic: Help with delete from mysql drop down list please  (Read 1070 times)

0 Members and 1 Guest are viewing this topic.

Offline jp15Topic starter

  • Irregular
  • Posts: 10
    • View Profile
Help with delete from mysql drop down list please
« on: March 01, 2010, 11:26:31 AM »
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.

Offline PFMaBiSmAd

  • Guru
  • 'Insane!'
  • *
  • Posts: 14,588
  • In Coding, Automatic means you write code to do it
    • View Profile
Re: Help with delete from mysql drop down list please
« Reply #1 on: March 01, 2010, 11:36:02 AM »
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.
Signature: (not a comment about anything you posted unless specifically indicated)
Debugging step #1: To get past the garbage-out equals garbage-in stage in your code, you must check that the inputs to your code are what you expect.

Programming is just problem solving, but it is done in another language. You must learn enough of the programming language you are using to be able to read and write code.

Offline jp15Topic starter

  • Irregular
  • Posts: 10
    • View Profile
Re: Help with delete from mysql drop down list please
« Reply #2 on: March 02, 2010, 12:50:51 PM »
Thanks! problem solved,