Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Unexpected T VARIABLE?

getting an unexpected t_variable message in a script of mine

5:19 pm on Nov 15, 2006 (gmt 0)

5+ Year Member

Here it is, i am a novice just started programming php and mysql, i have got it to take submissions from a form and add them to the database now i want to be able to delete these submissions from the page that displays them using a http link.

I have included in my where the items from the db are displayed the following code.

echo "<a href='delete.php?id=".$row{'id'}."'>";
echo "DELETE";
echo "</a></span></td>";

This works great and infact I can see each URL is correct and it displays the id at the end sort of like this. delete.php?id=5

now I created a script that will delete the items based on their ID i have included the code for the script below:

include 'dbconnect.php';

$id = $_GET['id']

$sqlquery = "DELETE * FROM tnews WHERE id='".$id."')";

header("Location: display.php");

//print $sqlquery;
$results = mysql_query($sqlquery);


Now the error I am getting is as follows:

Parse error: parse error, unexpected T_VARIABLE in H:\wwwdir\Apache2\htdocs\delete.php on line 6

line 6 being, now line 6 is:

$sqlquery = "DELETE * FROM tnews WHERE id='".$id."')";

can anyone here help me to get this to work correctly? I would appreciate it an awful lot.

[edited by: bysonary at 5:22 pm (utc) on Nov. 15, 2006]

5:22 pm on Nov 15, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

I am also learning PHP.

$sqlquery = "DELETE * FROM tnews WHERE id='".$id."')";

Take out the ) and the let us know what happens?

5:25 pm on Nov 15, 2006 (gmt 0)

5+ Year Member

Hello i took out the ) so it looks like this

$sqlquery = "DELETE * FROM tnews WHERE id='".$id."'";

Still getting unexpected T_VARIABLE in line 6

I even tried

$sqlquery = "DELETE * FROM tnews WHERE id='$id'";

but the same error occurs.

5:43 pm on Nov 15, 2006 (gmt 0)

WebmasterWorld Senior Member dreamcatcher is a WebmasterWorld Top Contributor of All Time 10+ Year Member

$id = $_GET['id']

You are missing a semi colon after this line. Should be:

$id = $_GET['id'];


5:52 pm on Nov 15, 2006 (gmt 0)

5+ Year Member

thanks it seems to redirect to the header location however it isnt actually deleting anything from the database, i dont suppose anyone would know why?

here is the full code including the dbconnect.php include

$username = "root";
$password = "password";
$server = "localhost";
$dbname = "cb2cwh";

$dbc = mysql_connect($server, $username, $password) or die ("ERROR");
$select = mysql_select_db($dbname, $dbc) or die("couldn't connect");

$id = $_GET['id'];

$sqlquery = "DELETE * FROM tnews WHERE id='$id'";

header("Location: display.php");

//print $sqlquery;
$results = mysql_query($sqlquery);


this should delete an item from the table tnews with the id in the url for instance if the url is delete.php?id=5 it would delete the item from the database with the id of 5?

it isnt deleting anything?

6:10 pm on Nov 15, 2006 (gmt 0)

5+ Year Member

please ignore my above post i fixed it, incase anyone would like to know how i changed the query to:

$sqlquery = "DELETE FROM tnews WHERE id='$id'";

Thanks for all your help.

6:53 am on Nov 16, 2006 (gmt 0)

10+ Year Member

Not sure how fast you need to develop, but it might be a good idea to check and see if "rows_affected" was successful or not, then redirect accordingly. But what you have might be just fine for your situation :-)
4:27 pm on Nov 16, 2006 (gmt 0)

5+ Year Member

you need to add how many rows that you want to delete, so if you want to delete one row the code will look like this.

$sqlquery = "DELETE FROM tnews WHERE id='$id' limit 1";

please ignore my above post


[edited by: Mohamed at 4:32 pm (utc) on Nov. 16, 2006]


Featured Threads

Hot Threads This Week

Hot Threads This Month