Some help please
Posted: Mon Jan 18, 2010 3:23 am
I have this code here that echo's out from mysql all rows with id. Now i haave to add delete button what takes mysql row code and uses it to delete certain row in mysql. code looks like this:
well it seems to work but it wont delete the row.
It echos out the "Row deleted" but in mysql the row still exist's. Where am i wrong here?
PS! I'm quite newbie in mySQL part. This is my first script to add/remove row's in MySQL.
Code: Select all
<?php
mysql_connect ("localhost", "myuser", "mypass") or die ('Error: ' . mysql_error());
mysql_select_db ("foral");
if(!isset($cmd))
{
//query
$query = mysql_query("SELECT * FROM tellimus order by id");
//display row
while ($row = mysql_fetch_array($query)) {
echo
'<td border="1" size="3"><input name="id" type="text" size="1" value='.$row['id'].'>'."".'<td border="1" size="3"><input name="id" type="text" size="16" value='.$row['kood'].'>'."".'<td border="1" size="3"><input name="id" type="text" size="19" value='.$row['nimetus'].'>'."".'<td border="1" size="3"><input name="id" type="text" size="11" value='.$row['kogus'].'>'."".'<td border="1" size="3"><input name="id" type="text" size="13" value='.$row['number'].'>'."".'<td border="1" size="3"><input name="id" type="text" size="11" value='.$row['kes'].'>'."".'<td border="1" size="3"><a href=\'index.php?cmd=delete&id='.$row['id'].'\'>'.$row['id'].' - Delete</a>'.
"<br />";}
}
if($_GET["cmd"]=="delete")
{
$sql = 'DELETE * FROM tellimus WHERE id='.$row['id'].'';
$query = mysql_query($sql);
echo "Row deleted!";
}
?>
It echos out the "Row deleted" but in mysql the row still exist's. Where am i wrong here?
PS! I'm quite newbie in mySQL part. This is my first script to add/remove row's in MySQL.