Killermud
03-01-2009, 05:53 PM
What im trying to do is delete data from my SQL database from a SQL query list. Then select from that list what you would like to delete, i am able to generate the list but i cant manage to delete what i select.
I have 2 files, the list and the delete file.
List file ->
<?php
/**
* @author Killermud
* @copyright 2009
*/
require './connect.php';
if(!$con){
die('Could not connect: ' . mysql_error());
}
$tbl_name="forum_question";
mysql_select_db("$dbname")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name";
$result = mysql_query($sql);
?>
<table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td><table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td width="10%" bgcolor="#F8F7F1"><strong>Select</strong></td>
<td width="15%" bgcolor="#F8F7F1"><strong>Topic</strong></td>
<?php
while($rows = mysql_fetch_array($result)){ ?>
<tr>
<td width="10%" bgcolor="#F8F7F1"><form action="delete.php">
<input type=checkbox name="<?php $rows['id']; ?>">
</td>
<td width="15%" bgcolor="#F8F7F1"><?php echo $rows['topic']; ?></td>
</tr>
<?php
}
?>
</tr>
</tr>
</table>
</table>
<input type="submit" name="submit" value="Delete">
</form>
Then this is where it goes wrong when i hit submit. Here is my delete file.
<?php
/**
* @author Killermud
* @copyright 2009
*/
require './connect.php';
if(!$con){
die('Could not connect: ' . mysql_error());
}
mysql_select_db("$dbname")or die("cannot select DB");
$sql="SELECT id FROM users where id={$rows['id']}";
$result = mysql_query($sql) or die('Delete album failed. ' . mysql_error());
if (mysql_num_rows($result) == 1) {
$row = mysql_fetch_assoc($result);
$sql = "DELETE FROM $tbl_name WHERE id ={$rows['id']}";
mysql_query($sql) or die('Delete album failed. ' . mysql_error());
}
if(mysql_num_rows($results)){?>
<html>
<head>
<title>Go Back to previous Page</title>
<script language="javascript">
<!--
function function1() {
history.back(1);
}
//-->
</script>
</head>
<body>
<a href="javascript:function1()">Back</a><br>
</body>
</html>
<?php
}else
{
$msg = mysql_error();
echo $msg;
}
?>
The error i get is :
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in c:\domains\opjeplaats.nl\wwwroot\darkness\webtemp\delete.php
Help please.
I have 2 files, the list and the delete file.
List file ->
<?php
/**
* @author Killermud
* @copyright 2009
*/
require './connect.php';
if(!$con){
die('Could not connect: ' . mysql_error());
}
$tbl_name="forum_question";
mysql_select_db("$dbname")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name";
$result = mysql_query($sql);
?>
<table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td><table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td width="10%" bgcolor="#F8F7F1"><strong>Select</strong></td>
<td width="15%" bgcolor="#F8F7F1"><strong>Topic</strong></td>
<?php
while($rows = mysql_fetch_array($result)){ ?>
<tr>
<td width="10%" bgcolor="#F8F7F1"><form action="delete.php">
<input type=checkbox name="<?php $rows['id']; ?>">
</td>
<td width="15%" bgcolor="#F8F7F1"><?php echo $rows['topic']; ?></td>
</tr>
<?php
}
?>
</tr>
</tr>
</table>
</table>
<input type="submit" name="submit" value="Delete">
</form>
Then this is where it goes wrong when i hit submit. Here is my delete file.
<?php
/**
* @author Killermud
* @copyright 2009
*/
require './connect.php';
if(!$con){
die('Could not connect: ' . mysql_error());
}
mysql_select_db("$dbname")or die("cannot select DB");
$sql="SELECT id FROM users where id={$rows['id']}";
$result = mysql_query($sql) or die('Delete album failed. ' . mysql_error());
if (mysql_num_rows($result) == 1) {
$row = mysql_fetch_assoc($result);
$sql = "DELETE FROM $tbl_name WHERE id ={$rows['id']}";
mysql_query($sql) or die('Delete album failed. ' . mysql_error());
}
if(mysql_num_rows($results)){?>
<html>
<head>
<title>Go Back to previous Page</title>
<script language="javascript">
<!--
function function1() {
history.back(1);
}
//-->
</script>
</head>
<body>
<a href="javascript:function1()">Back</a><br>
</body>
</html>
<?php
}else
{
$msg = mysql_error();
echo $msg;
}
?>
The error i get is :
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in c:\domains\opjeplaats.nl\wwwroot\darkness\webtemp\delete.php
Help please.