Jump to content

Help with delete from mysql drop down list please


jp15

Recommended Posts

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.

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.