rubdoo Posted March 28, 2009 Share Posted March 28, 2009 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 More sharing options...
jlhaslip Posted March 28, 2009 Share Posted March 28, 2009 Can you post the full page of code, please.Delete should be removing a page, not adding one. There must be something else going on. Link to comment Share on other sites More sharing options...
rubdoo Posted March 28, 2009 Author Share Posted March 28, 2009 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 More sharing options...
Stefano Posted March 29, 2009 Share Posted March 29, 2009 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 More sharing options...
rubdoo Posted March 29, 2009 Author Share Posted March 29, 2009 Thanks you so much. It fixed the problem Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.