Jump to content


Photo

Help with very simple form


  • Please log in to reply
3 replies to this topic

#1 crzyman

crzyman
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 14 September 2006 - 10:04 PM

I can't get this to work. What am I over looking? I have an html form that looks like this:
<html>
<head>
</head>
<center>
<form method="post" action="test.php">
<input type="hidden" name="id" value="null">
<table>

<tr><td align="left">Comments</td>
<td><input type="text" name="comments" size="40"></td>
</tr>

</table>
</form>
</center>
</html>
and the php script for test.php looks like this:

<?php
$firstname = "name";

mysql_connect(localhost,name,pass) or die("Unable to connect to database");
@mysql_select_db("database") or die("Unable to select database ims_search");

$result = mysql_query("SELECT name FROM table WHERE name like '$firstname'");

$sqlquery = "INSERT INTO table(row) VALUES('$comments') WHERE name like '$firstname'";


$results = mysql_query($sqlquery);
mysql_close();
print "<html><body><center>";
print "<p>You have just entered this record<p>";
print "Comments: $comments";
print "</body></html>";
?>
The data is not being entered into the database. Any help would be appreciated. Thanks.

#2 Gruzin

Gruzin
  • Members
  • PipPipPip
  • Advanced Member
  • 448 posts
  • LocationGeorgia

Posted 15 September 2006 - 12:09 AM

First thing I can see:
mysql_connect(localhost,name,pass) or die("Unable to connect to database");
Think you can't connect to db like that...
mysql_connect("localhost","name","pass") or die("Unable to connect to database");

Second: Can you please tell me, why are you trying to run two querys? one is :
$result = mysql_query("SELECT name FROM table WHERE name like '$firstname'");
and the second one is:
$sqlquery = "INSERT INTO table(row) VALUES('$comments') WHERE name like '$firstname'";

I don't need your script, I'll try to write it myself

#3 Wintergreen

Wintergreen
  • Members
  • PipPipPip
  • Advanced Member
  • 107 posts

Posted 15 September 2006 - 12:13 AM

Also, when you're accessing an element's value that was passed from a form, you have to use $_POST['comments'] to access it.  Normally you'd make a new variable in the php page for it, so you'd do
$comments = $_POST['comments'];


#4 crzyman

crzyman
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 15 September 2006 - 12:18 AM

Thank you for your replies. This is my code now. But still no luck getting the information into the database. Any ideas?
<?php
$comments = $_POST['comments'];
$firstname = "Seconds To Impact";

mysql_connect("localhost","name","pass") or die("Unable to connect to database");
@mysql_select_db("ims_search") or die("Unable to select database ims_search");

$sqlquery = "INSERT INTO artist(comments) VALUES('$comments') WHERE artist_name like '$firstname'";


$results = mysql_query($sqlquery);
mysql_close();
print "<html><body><center>";
print "<p>You have just entered this record<p>";
print "Comments: $comments";
print "</body></html>";
?>






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users