crzyman Posted September 14, 2006 Share Posted September 14, 2006 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. Quote Link to comment Share on other sites More sharing options...
Gruzin Posted September 15, 2006 Share Posted September 15, 2006 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] Quote Link to comment Share on other sites More sharing options...
Wintergreen Posted September 15, 2006 Share Posted September 15, 2006 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']; Quote Link to comment Share on other sites More sharing options...
crzyman Posted September 15, 2006 Author Share Posted September 15, 2006 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] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.