in the following code, i would like to get the row result for column “id” as a result for $selectedmovieid. The ‘commenid’ is the primary key attribute. Sorry for not knowing how to use mysql_fetch_assoc properly.
<?php
require ("connect-comment.php");
$deleteid=$_GET['commentid'];
$query1=mysql_query("SELECT id FROM comment WHERE commentid='$deleteid'");
$selectedmovieid= mysql_fetch_assoc($query1);
$query2=mysql_query("DELETE FROM comment WHERE commentid='$deleteid'");
header("Location: reload.php?id=$selectedmovieid");
?>
EDIT 1: I will do up the security injection much later, just need to get the syntax right and get the right result. So this is what i have done so far:
<?php
require ("connect-comment.php");
$deleteid=$_GET['commentid'];
$query1=mysql_query("SELECT id FROM comment WHERE commentid='$deleteid'");
while ($selectedmovieid= mysql_fetch_assoc($query1))
{echo $selectedmovieid['id'];};
$query2=mysql_query("DELETE FROM comment WHERE commentid='$deleteid'");
header("Location: reload.php?id=$selectedmovieid");
?>
Now this doesn’t make much sense to me cos i am not parsing the correct $selectedmovieid value into the reload.php?id=
Try changing
to
Also, as Pekka rightly suggests, try reading the manual page for
mysql_fetch_assoc()and reading up on SQL injection.As a side note, you should not use relative paths for
Location:header redirects. RFC’s specify that this field should contain a full URL and, while many browsers will correctly interpret relative paths, this behaviour should not be relied upon. In other words,Location: reload.php?id=...should beLocation: http://mysite.tld/reload.php?id=EDIT Try this complete version of your sample code: