Page 1 of 1

Delete all from a table - resolved

Posted: Mon Oct 12, 2009 11:44 am
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';
?>
 

Re: Delete all from a table

Posted: Mon Oct 12, 2009 11:48 am
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.

Re: Delete all from a table

Posted: Mon Oct 12, 2009 12:19 pm
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

Re: Delete all from a table

Posted: Mon Oct 12, 2009 12:34 pm
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.

Re: Delete all from a table

Posted: Mon Oct 12, 2009 12:58 pm
by lmhart

Code: Select all

<?php
include 'dbc.php'
 
 
mysql_query("TRUNCATE TABLE categories");
 
echo(mysql_error());
 
include 'redirect_category.php';
?>

Re: Delete all from a table

Posted: Mon Oct 12, 2009 1:00 pm
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.

Re: Delete all from a table

Posted: Tue Oct 13, 2009 2:31 pm
by lmhart
Thanks all for the help. Found the issue --> missing a ; when calling the db connection.