Jump to content

[SOLVED] PHP script problem - Help please??


s1yman

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/119024-solved-php-script-problem-help-please/
Share on other sites

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???

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

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

 

???

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);

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.