homepage Welcome to WebmasterWorld Guest from 54.226.191.80
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Unexpected T VARIABLE?
getting an unexpected t_variable message in a script of mine
bysonary




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

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:

<?php
include 'dbconnect.php';

$id = $_GET['id']

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

header("Location: display.php");

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

mysql_close($dbc);
?>

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]

 

rj87uk




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

I am also learning PHP.

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

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

bysonary




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

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.

dreamcatcher




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

$id = $_GET['id']

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

$id = $_GET['id'];

dc

bysonary




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

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

mysql_close($dbc);
?>

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?

bysonary




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

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.

ramoneguru




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

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 :-)
--Nick

Mohamed




msg:3158695
 4:27 pm on Nov 16, 2006 (gmt 0)

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

[added]Oops![/added]

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved