Jump to content

Problem with comment system


alexguz79

Recommended Posts

Hey everybody...

 

i have this problem:

 

i have my comment system working in terms of adding and displaying the data... but there's this thing that everytime the page loads insert a new blank field in the database... here's the code... thank in advance

 

<form action="<?=$PHP_SELF?>" method="post">
          Nombre:<br /> 
          <input type="text" name="name" id="name" />
          <br />
          Commentario:<br /> 
          <input type="text" name="comment" id="comment" />
          <br />
          <input type="submit" value="Enviar" /></form>
	  
	  <?php

	  mysql_connect("localhost", "root", "root") or die(mysql_error());
	  mysql_select_db("gallery") or die(mysql_error());
	  $id    = $_GET['id'];
	  

	  $result2 = mysql_query("SELECT * FROM images_comments WHERE image_id = '$id' ORDER BY ID DESC");
	  $sql="INSERT INTO images_comments (id, image_id, name, comment)
	  VALUES ('','$id','$_POST[name]','$_POST[comment]')";
	  
	  !mysql_query($sql);
	   
	  ?>
	   

Link to comment
Share on other sites

you should never put primary key into query! mysql handles primary keys without php's help remove id from query completely

 


  $sql="INSERT INTO images_comments (id, image_id, name, comment)
	  VALUES ('','$id','$_POST[name]','$_POST[comment]')";

 

to


  $sql="INSERT INTO images_comments (image_id, name, comment)
	  VALUES ('$id','$_POST[name]','$_POST[comment]')";

why do people always do the blank thing in primary keys??

 

 

not to mention your

!mysql_query($sql); has a Exclamation mark

 

you also have to check for

if(isset($_POST['submit']))  //before you run it all code with mysql

Link to comment
Share on other sites

Your code is currently inputting blank lines into your database because it has no variables to deal with.  You are calling up variables such as $_POST[name] before the form is submitted, which is making $_POST[name] equal to nothing, hence why the entries are being made blank. 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.