Inserting values into a MySQL table

Hello,

With the code below, I am trying to insert some values into a MySQL table called “comment.”

Here are the values:

NULL, ‘$uid’, ‘$subid’, ‘$comment’, NULL, NULL

Here is the structure of the MySQL table:

commentid, loginid, submissionid, comment, datecommented, level

I have had a hard time getting this to work. I am looking for what code would work on the file comments2.php to accomplish what I mentioned above. Any suggestions?

Thanks in advance,

John

echo '<form action="http://www...com/sandbox/comments/comments2.php" method="post"> 
    <input type="hidden" value="'.$_SESSION['loginid'].'" name="uid">
	<input type="hidden" value="'.$submissionid.'" name="submissionid">  
    
	<label class="addacomment" for="title">Add a comment:</label>
    <input class="commentsubfield" name="comment" type="comment" id="comment" maxlength="1000">  
	  
    <div class="commentsubbutton"><input name="submit" type="submit" value="Submit"></div> 
</form>
';

Your code sample doesn’t seem to have anything to do with inserting data into a MySQL table so I’m not a hundred percent sure I understand your question. It looks like you just have the form, so I’m assuming your asking what the script that processes the form should look like…

The code in comments2.php should get the data from the $_POST array and validate it to prevent SQL injection and make sure the data makes sense. Then get a connection to MySQL and Insert that data with something like…


$result = $conn->query("INSERT INTO comment (loginid, submissionid, comment) VALUES('$loginid', '$submissionid', '$comment')"

The code aboves assumes you first…

  1. Created a connection to MySQL and stored a reference in $conn

  2. You validated and then copied the values out of $_POST and into $loginid, $submissionid, and $commentid