Delete all from a table - resolved

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lmhart
Forum Newbie
Posts: 15
Joined: Tue Apr 14, 2009 1:05 pm

Delete all from a table - resolved

Post by lmhart »

I can not get the following code to work. I keep getting an error stating that the statement is wrong. However when I run in directly on the db it will delete everything without issues. Will someone please look and see what I am missing.
Thanks,

Code: Select all

 
<?php
include 'dbc.php'
 
 
mysql_query("delete from categories");
 
include 'redirect_category.php';
?>
 
Last edited by lmhart on Tue Oct 13, 2009 2:32 pm, edited 1 time in total.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: Delete all from a table

Post by onion2k »

Does your MySQL user have the DELETE privilege?

Also, use TRUNCATE if you don't need to maintain any autoincrement values. It's much, much faster.
lmhart
Forum Newbie
Posts: 15
Joined: Tue Apr 14, 2009 1:05 pm

Re: Delete all from a table

Post by lmhart »

double checked--> the user has the proper credentials to allow for deletes.
Also changed to truncate table but still getting the same error

Parse error: syntax error, unexpected T_STRING in /home/themarkh/public_html/budget/delete_all_categories.php on line 5
User avatar
Mirge
Forum Contributor
Posts: 298
Joined: Thu Sep 03, 2009 11:39 pm

Re: Delete all from a table

Post by Mirge »

lmhart wrote:double checked--> the user has the proper credentials to allow for deletes.
Also changed to truncate table but still getting the same error

Parse error: syntax error, unexpected T_STRING in /home/themarkh/public_html/budget/delete_all_categories.php on line 5
Don't see anything that'd cause that error. Though that's a PHP error, not a MySQL error. Post new code that you have.
lmhart
Forum Newbie
Posts: 15
Joined: Tue Apr 14, 2009 1:05 pm

Re: Delete all from a table

Post by lmhart »

Code: Select all

<?php
include 'dbc.php'
 
 
mysql_query("TRUNCATE TABLE categories");
 
echo(mysql_error());
 
include 'redirect_category.php';
?>
User avatar
Mirge
Forum Contributor
Posts: 298
Joined: Thu Sep 03, 2009 11:39 pm

Re: Delete all from a table

Post by Mirge »

lmhart wrote:

Code: Select all

<?php
include 'dbc.php'
 
 
mysql_query("TRUNCATE TABLE categories");
 
echo(mysql_error());
 
include 'redirect_category.php';
?>
This is all of the code for delete_all_categories.php? Verbatim? If so, I'm at a loss... I don't see anything in that that'd cause that parse error.
lmhart
Forum Newbie
Posts: 15
Joined: Tue Apr 14, 2009 1:05 pm

Re: Delete all from a table

Post by lmhart »

Thanks all for the help. Found the issue --> missing a ; when calling the db connection.
Post Reply