Deleting from data base using value from form.

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
PHP:
$statement = "DELETE FROM commentTable WHERE ID='$ID'";  
// OR   
$statement = "DELETE FROM commentTable WHERE ID='".$ID."'";
As I said before, (and as the comment says)
You only need one of them
Both lines won't hurt, but they do the same thing. Use whichever is more readable or try PDO's prepared queries, which is the superior route. There are plenty of PDO tutorials, though some have bugs and others are just low quality.

PHP:
mysql_connect('localhost', 'martynba_martynb', 'test123'') or die('Error: ' . mysql_error()); 
...
    die('Error:  .mysql_error());
The first line has an extra single quote, and the last has an unterminated string ("Error: "). Notice how the coloration is all funny? Notice how "Error" is the same color as "mysql_error()"? Read over the PHP manual section on strings. It'd also be a good idea to get a good book or find a good introductory tutorial online. O'Reilly publishes quality books ("Learning PHP 5" and "Programming PHP, Second Edition"), but (like most books) they were written before PDO. Instead, they use PEAR DB, which was also good but has been supplanted.

And don't use "die" for web scripts. You'll get malformed HTML.
 
Last edited:

martynball

New Member
Messages
60
Reaction score
0
Points
0
What should I use instead of "die"?

I will try and get some books on php, javascript ect... i plan on learning many coding languages, just not yet. And thanks for pointing out the errors.
 
Top