Jump to content

Help with very simple form


crzyman

Recommended Posts

I can't get this to work. What am I over looking? I have an html form that looks like this:
[code]
<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>
[/code]
and the php script for test.php looks like this:
[code]

<?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>";
?>
[/code]
The data is not being entered into the database. Any help would be appreciated. Thanks.
Link to comment
https://forums.phpfreaks.com/topic/20793-help-with-very-simple-form/
Share on other sites

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

Second: Can you please tell me, why are you trying to run two querys? one is :
[code]$result = mysql_query("SELECT name FROM table WHERE name like '$firstname'");[/code]
and the second one is:
[code]$sqlquery = "INSERT INTO table(row) VALUES('$comments') WHERE name like '$firstname'";[/code]
Thank you for your replies. This is my code now. But still no luck getting the information into the database. Any ideas?
[code]
<?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>";
?>

[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.