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
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]
Link to comment
Share on other sites

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]
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.