s1yman Posted August 10, 2008 Share Posted August 10, 2008 Hi everyone, I seem to be having trouble with my script to delete entries on my database. The script should work by using the URL, i.e. URL visited will be http://domain.com/delete.php?id=2 and that should delete entry 2 on the table. the script is below; <?php mysql_connect("server","uid,"password") or die('Could not connect to server: ' . mysql_error()); mysql_select_db("database") or die('Could not connect to database: ' . mysql_error()); $query = 'DELETE FROM 'ajc' WHERE 'ajc'.'#'=$id LIMIT 1;' or die('Error querying table: ' . mysql_error()); $delete = MYSQL_QUERY($query); if (!mysql_query($delete)) { die('Error deleting: ' . mysql_error()); } print "Entry has been removed from the database"; ?> However, the error I get is; Parse error: syntax error, unexpected T_STRING in E:\location\delete.php on line 4 Any ideas? Thanks in advance. -Sly Quote Link to comment https://forums.phpfreaks.com/topic/119024-solved-php-script-problem-help-please/ Share on other sites More sharing options...
budimir Posted August 10, 2008 Share Posted August 10, 2008 You have a problem here: $query = 'DELETE FROM 'ajc' WHERE 'ajc'.'#'=$id LIMIT 1;' or die('Error querying table: ' . mysql_error()); Do it like this: $query = "DELETE FROM 'ajc' WHERE '#'='$id' LIMIT 1"; $result = mysql_query($query) or die('Error querying table: ' . mysql_error()); Also, where are you getting $id from??? Quote Link to comment https://forums.phpfreaks.com/topic/119024-solved-php-script-problem-help-please/#findComment-612881 Share on other sites More sharing options...
s1yman Posted August 10, 2008 Author Share Posted August 10, 2008 $id is the typed URL. That should be something like http://domain.com/delete.php?id=2 Quote Link to comment https://forums.phpfreaks.com/topic/119024-solved-php-script-problem-help-please/#findComment-612890 Share on other sites More sharing options...
wildteen88 Posted August 10, 2008 Share Posted August 10, 2008 You should use $_GET['id'] rather than $id. Quote Link to comment https://forums.phpfreaks.com/topic/119024-solved-php-script-problem-help-please/#findComment-612891 Share on other sites More sharing options...
s1yman Posted August 10, 2008 Author Share Posted August 10, 2008 Sorry guys - I'm a complete retard with these sort of scripts. I appreciate your help! The script I got now is <?php mysql_connect("server","UID","password") or die('Could not connect to server: ' . mysql_error()); mysql_select_db("DB") or die('Could not connect to database: ' . mysql_error()); $query = 'DELETE FROM 'ajc' WHERE '#'=$_GET['id'] LIMIT 1'; $result = mysql($query) or die('Error querying table: ' . mysql_error()); if (!mysql_query($result)) { die('Error deleting: ' . mysql_error()); } print "Entry has been removed from the database"; ?> Still getting the same error - I tried $_GET['id'] and $id but neither seem to change make a difference Quote Link to comment https://forums.phpfreaks.com/topic/119024-solved-php-script-problem-help-please/#findComment-612896 Share on other sites More sharing options...
budimir Posted August 10, 2008 Share Posted August 10, 2008 Your query is not getting parsed properly, use double quotes. $id = $_GET["id"]; $query = "DELETE FROM ajc WHERE # = '$id' LIMIT 1"; Is # a field in your databse or what??? Quote Link to comment https://forums.phpfreaks.com/topic/119024-solved-php-script-problem-help-please/#findComment-612899 Share on other sites More sharing options...
s1yman Posted August 10, 2008 Author Share Posted August 10, 2008 that's right, # is the unique field in the table "ajc". $id = $_GET["id"] $query = "DELETE FROM ajc WHERE #=$id"; $result = mysql_query($query) or die('Error querying table: ' . mysql_error()); makes sense to me but now error's You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 ??? Quote Link to comment https://forums.phpfreaks.com/topic/119024-solved-php-script-problem-help-please/#findComment-612919 Share on other sites More sharing options...
s1yman Posted August 10, 2008 Author Share Posted August 10, 2008 Can anyone help please? I can't make any sense of dev.mysql.com -----EDIT----- I'm on Server version: 5.0.22 Quote Link to comment https://forums.phpfreaks.com/topic/119024-solved-php-script-problem-help-please/#findComment-612975 Share on other sites More sharing options...
budimir Posted August 10, 2008 Share Posted August 10, 2008 I'm not quite sure, but I think you can't use # as a name in your MySQL DB, because it's a reserved sign. Try to change to 'number' or something like that... Quote Link to comment https://forums.phpfreaks.com/topic/119024-solved-php-script-problem-help-please/#findComment-613003 Share on other sites More sharing options...
s1yman Posted August 10, 2008 Author Share Posted August 10, 2008 works on all my other scripts, but I'll give it a try now Quote Link to comment https://forums.phpfreaks.com/topic/119024-solved-php-script-problem-help-please/#findComment-613004 Share on other sites More sharing options...
s1yman Posted August 10, 2008 Author Share Posted August 10, 2008 It changed the error to right syntax to use near '1' at line 1 (just added '1') but that still doesn't make sense to me ... r u as confused as I am? Does the code about getting "id" from the URL make sense?, maybe that's the problem Quote Link to comment https://forums.phpfreaks.com/topic/119024-solved-php-script-problem-help-please/#findComment-613006 Share on other sites More sharing options...
MidOhioIT Posted August 10, 2008 Share Posted August 10, 2008 What does the code look like where you declare the id? For example this is a link that you have to click on located on a website that controls my id: <td><b><a href='menu.php?param=id'>Invoice number</a></b></td> which then goes and runs this: $result = mysql_query("SELECT * FROM invoices ORDER BY $param",$db); Quote Link to comment https://forums.phpfreaks.com/topic/119024-solved-php-script-problem-help-please/#findComment-613017 Share on other sites More sharing options...
s1yman Posted August 10, 2008 Author Share Posted August 10, 2008 it's generated by php, but it's just a normal link in the browser - <a href="delete.php?id=1"><font color="#FFFFFF"><img src="del.png" alt="Delete" align="left" /></font></a> Quote Link to comment https://forums.phpfreaks.com/topic/119024-solved-php-script-problem-help-please/#findComment-613028 Share on other sites More sharing options...
budimir Posted August 10, 2008 Share Posted August 10, 2008 Can you echo your query so we can see what is beeing put inside it??? Quote Link to comment https://forums.phpfreaks.com/topic/119024-solved-php-script-problem-help-please/#findComment-613037 Share on other sites More sharing options...
s1yman Posted August 10, 2008 Author Share Posted August 10, 2008 Actually, changing it to "num" instead of "#" has made the script work!! I thought it was erroring because I had my if else statement the wrong way round lol - serves me right for following about.com!! Budimir, you're a legend for the help! cheers man Quote Link to comment https://forums.phpfreaks.com/topic/119024-solved-php-script-problem-help-please/#findComment-613042 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.