Jump to content

I Need Help With Delete...


rubdoo

Recommended Posts

Hey, I made a database and every time I refresh the page, it adds a blank row to my database. I was wondering how i could make it not add those blank rows. I was trying:

DELETE FROM 'tableName' WHERE fieldName = ""

It didn't work; it was just a guess. lol :SAnyways, if anyone could help me out, it'd be appreciated.Thanks!

Link to comment
Share on other sites

Okay:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>ChatGalore</title></head><body><form action="index.php" method="post">Name: <input style="position:relative;left:22px;" type="text" name="name" /><br />Comment: <input style="width:200px;" type="text" name="comment" /><br /><input type="submit" value="Post Comment" /></form><?php$name = $_POST["name"];$comment = $_POST["comment"];$con = mysql_connect("localhost:3306","root","");if (!$con)  {  die('Could not connect: ' . mysql_error());  }mysql_select_db("chatgalore", $con);$sql="INSERT INTO comments (name, comment) VALUES ('$name', '$comment')";if (!mysql_query($sql,$con))  {  die('Error: ' . mysql_error());  }echo "";$query="SELECT * FROM comments";$result=mysql_query($query);$num=mysql_numrows($result);$i=0;while ($i < $num) {$name=mysql_result($result,$i,"name");$comment=mysql_result($result,$i,"comment");echo "<b>$name:</b> $comment<br />";$i++;}mysql_query(DELETE FROM comments WHERE name = "");mysql_close($con)?></body></html>

Link to comment
Share on other sites

Two problems php and SQL:

.........if (isset( $_POST["name"])){  $sql="INSERT INTO comments (name, comment) VALUES ('$name', '$comment')";    if (!mysql_query($sql,$con))	{	   die('Error: ' . mysql_error());	 } }.......mysql_query(DELETE FROM comments WHERE name = ""); is supposed to be mysql_query(DELETE FROM comments WHERE name is null);note: "" != null

If you fix PHP you can omit the delete statment, and in any case such a statement should be an "after insert" trigger on DBMS side.hope it helps

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...