Jump to content

Recommended Posts

I am trying to post comments to the database. This is the code for the form:

 

<!--DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"-->
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>
Comments
</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<meta name="description" content="description goes here" />
<meta name="keywords" content="keywords,goes,here" />
<link rel="stylesheet" href="style1.css" type="text/css" />
<!--[if IE 6]>
<link rel="stylesheet" href="fix.css" type="text/css" />
<![endif]-->
</head>


<body>
<form name="myForm" action="testin.php" method="post">
<br />
<br />
<b>Comment</b>
<br/>
<br />
<textarea name="comment" cols="40" rows="10" />
</textarea>
<br /><br />
<input type="reset" value="Reset" />
<input type="submit" value="Send" />

</form>
</body>
</html>

 

This is the code for the testin.php:

<html>
<head>
</head>
<body>

<?php
mysql_connect("host", "username", "pass") or die(mysql_error());
//connects to the blacknight server
mysql_select_db("database");
//selects the database called 4grads

$comment=$_POST['comment'];

mysql_query("INSERT INTO comments (comment) values ('$comment')");


echo "comment added successfully. well done.";


?>


</body>
</html>

 

The text echoes but it doesn't enter the database. I can't see why! Any suggestions?

Link to comment
https://forums.phpfreaks.com/topic/123280-solved-values-into-database/
Share on other sites

i was going to say pretty much what they said...

 

try:

 

$comment = $_POST['comment'];

$query = mysql_query("INSERT INTO comments (comment) VALUES ('{$comment}')");

if (!$query) {
   print 'MySQL Error: ' . mysql_error();
} else {
   print 'Comment: <strong>"' .$comment. '"</strong> entered successfully...';
}

$comment =  $_POST['comment'];

$result = mysql_query("INSERT INTO comments (comment) values '$comment'  ");


echo "comment added successfully. well done.";


?>

 

that should work.... no need to do error checking for such a simple question. you dont need the () around the variable

Say what?  What do you mean no need to do error checking?  Show the guy how to do it right the first time.  Teaching bad habbits is just wrong.

 

 

that should work.... no need to do error checking for such a simple question. you dont need the () around the variable

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.