1

I found this code that does exactly what i need

http://www.daveismyname.com/tutorials/php-tutorials/delete-rows-from-a-mysql-database-with-a-confirmation/

When i copy the code into a new dreamweaver php file, it states that there is a syntax error in this part:

<?php
$result = mysql_query("SELECT * FROM news")or die(mysql_error());
while($row = mysql_fetch_object($result))
{
echo "<ul>n";
echo "<li>$row->newsTitle <a href="javascript:delnews('$row->newsID','$row->newsTitle')">Delete</a></li>n";
echo "</ul>n";
}
?>

more specifically in the echo <li>$row line.

if I try to upload it anyways it says:

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/asbj1076/public_html/testdel/admin.php on line 39

i can save it as a html5 file without that syntax error, but the code still aint working properly.

Any suggestions?

I know there has been a lot of similar questions already, sorry for that. I'm just a noob who's in over my head, so i need really specific help.

Thanks. Asbjørn

2
  • 1
    Escape " in middle of the second echo using \" instead. Commented Jul 18, 2013 at 19:25
  • 1
    try echo "<li>$row->newsTitle <a href=\"javascript:delnews('$row->newsID','$row->newsTitle')\">Delete</a></li>n"; Commented Jul 18, 2013 at 19:25

2 Answers 2

2

Because of the double quotes " in your second echo statement PHP is throwing an error because it is trying to evaluate the HTML that is inside of those quotes.

echo "<li>$row->newsTitle <a href="javascript:delnews('$row->newsID','$row->newsTitle')">Delete</a></li>n";
                                   ^                                                  ^

Everything between those marks is trying to be evaulated as php and errors. Escape your quotes like this instead.

echo "<li>$row->newsTitle <a href=\"javascript:delnews('$row->newsID','$row->newsTitle')\">Delete</a></li>n";
Sign up to request clarification or add additional context in comments.

3 Comments

will try that out in a minute, its time for hotdogs now. thanks so much for the fast reply.
The answer is good but maybe you could seperate each part instead of writing php,html and js on the same line. Writing like this make the code really difficult to debug. After that he should remove mysql_* statement because it is deprecated now.
i can see what you say. fortunately it seems like fred already did that for me. thanks.
1

You may try (keep the ul out of loop)

echo "<ul>";
while($row = mysql_fetch_object($result))
{
    echo "<li>" . $row->newsTitle . " <a href='javascript:delnews(\'" . $row->newsID ."\', \'" . $row->newsTitle . "\')>Delete</a></li>";
}
echo "</ul>";

Output will be :

  • Hello Delete

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.