ADLE Posted September 27, 2008 Share Posted September 27, 2008 Hello all, need help...bad. I Know nothing about PHP, so I've been searching tutorials to achieve what I want but no luck. Here is my form on my contact.html. <form name="contactform" action="contactform.php" method="post" window.onload=function() {document.contactform.reset();};> <table border="0" cellpadding="3"> <tr> <td><font size="6"><a href="http://www.somesite.com/" style="text-decoration:none">HOME</a></font></td> <td rowspan="7" width="1020"><center><font size="3">IF YOU HAVE A QUESTION, COMMENT, OR INQUIRY REGARDING RATES PLEASE CONTACT US AT:<br />INFO@SOMEEMAIL.COM<br /><br />YOU MAY ALSO CONTACT US THROUGH OUR FORM:<br /><br /> NAME:<input type="text" size="36" name="name" class="text1" style="font-family: times" /> <br /> EMAIL:<input type="text" size="36" name="email" class="text2" style="font-family: times" /> <br /> <br /> <textarea name="text" rows="5" cols="139" style="font-family: times"> </textarea> <br /> <br /> <a onclick="document.contactform.reset();return false;" href="#"><img alt="Reset" src="reset.gif" border="0" /></a> / <input type="image" src="submit.gif" alt="Submit" /> </font></center></td> </tr> <tr> Here is my contactform.php file. Got info from a site called http://teamtutorials.com/web-development-tutorials/php-tutorials/inserting-data-into-a-mysql-database-using-php it was called inserting data into mysql database using php tutorial. I just mimic. <?php $name = $_post['name']; $email = $_post['email']; $text = $_post['text']; mysql_connect ("localhost"), "projectc_testuse", "password") or die ('Error: ' . mysql_error()); mysql_select_db ("projectc_Test"); $query="INSERT INTO contacttable (ID, name, email, text)VALUES ('NULL','".$name."','.$email."','".$text."')"; mysql_query($query) or die ('error updating database'); ?> What I would like is the data sebmitted from my form, to mysql database using this form. What am I doing wrong? Maybe I am putting host info, database name in wrong area, but I tired several combinations. Help! Thanks, ADLE Link to comment https://forums.phpfreaks.com/topic/126083-need-helpbad/ Share on other sites More sharing options...
peranha Posted September 27, 2008 Share Posted September 27, 2008 mysql_connect ("localhost"), "projectc_testuse", "password") You have an extra ) mysql_connect ("localhost", "projectc_testuse", "password") is projectc_testuse the username, if not that is what goes there. $query="INSERT INTO contacttable (ID, name, email, text)VALUES ('NULL','".$name."','.$email."','".$text."')"; should be $query="INSERT INTO contacttable (ID, name, email, text)VALUES ('NULL','$name','$email','$text')"; if ID is autoincrement, it is not needed at all. $query="INSERT INTO contacttable (name, email, text)VALUES ('$name','$email','$text')"; mysql_query($query) or die ('error updating database); should be mysql_query($query) or die ('error updating database' . mysql_error()); Link to comment https://forums.phpfreaks.com/topic/126083-need-helpbad/#findComment-651975 Share on other sites More sharing options...
ADLE Posted September 27, 2008 Author Share Posted September 27, 2008 Hey Peranha, thanks for the reply. Took all of you suggestions and I got this error: error updating databaseNo Database Selected Link to comment https://forums.phpfreaks.com/topic/126083-need-helpbad/#findComment-651986 Share on other sites More sharing options...
peranha Posted September 27, 2008 Share Posted September 27, 2008 mysql_connect ("localhost", "projectc_testuse", "password") or die ('Error: ' . mysql_error()); mysql_select_db ("projectc_Test"); is projectc_Test the database?? Link to comment https://forums.phpfreaks.com/topic/126083-need-helpbad/#findComment-651988 Share on other sites More sharing options...
DarkWater Posted September 27, 2008 Share Posted September 27, 2008 Also, $_POST not $_post. Link to comment https://forums.phpfreaks.com/topic/126083-need-helpbad/#findComment-651989 Share on other sites More sharing options...
ADLE Posted September 27, 2008 Author Share Posted September 27, 2008 According to the tutorial this is what it says: Now we will make a connection to the database. You will have to replace: “localhost” with the location of your server “projectc_testuse” with your username “password” with your password Then we are selecting the “projectc_Test” database you will change that to whatever you named the database in the first tutorial. I added something to test and got this error: mysql_connect ("localhost"), "projectc_testuse", "databse name", "password") This is the error: Error: Access denied for user: '[email protected]' (Using password: YES) so i changed it back to: mysql_connect ("localhost"), "projectc_testuse", "password") Thanks Piranha, really appreciate this. Link to comment https://forums.phpfreaks.com/topic/126083-need-helpbad/#findComment-651993 Share on other sites More sharing options...
AdRock Posted September 27, 2008 Share Posted September 27, 2008 You could have this in a seperate file and include it on any page that requires a database connection <?php $host="localhost"; $user="username"; $password="password"; $database="databasename"; mysql_connect($host,$user,$password); @mysql_select_db($database) or die( "Unable to select database") ?> Link to comment https://forums.phpfreaks.com/topic/126083-need-helpbad/#findComment-651997 Share on other sites More sharing options...
ADLE Posted September 27, 2008 Author Share Posted September 27, 2008 Changed $_post to $_POST. Thanks Darkwater. Still says: error updating databaseNo Database Selected. Arrg, wish I knew php. Link to comment https://forums.phpfreaks.com/topic/126083-need-helpbad/#findComment-652020 Share on other sites More sharing options...
env-justin Posted September 27, 2008 Share Posted September 27, 2008 Quick question. Did you set up the mysql database? Link to comment https://forums.phpfreaks.com/topic/126083-need-helpbad/#findComment-652027 Share on other sites More sharing options...
ADLE Posted September 27, 2008 Author Share Posted September 27, 2008 To some extent, but it is probably not setup right. Terrible, yes I know. Link to comment https://forums.phpfreaks.com/topic/126083-need-helpbad/#findComment-652033 Share on other sites More sharing options...
dropfaith Posted September 27, 2008 Share Posted September 27, 2008 post the sql from making the db Link to comment https://forums.phpfreaks.com/topic/126083-need-helpbad/#findComment-652034 Share on other sites More sharing options...
env-justin Posted September 27, 2008 Share Posted September 27, 2008 Are you using phpMyAdmin? Link to comment https://forums.phpfreaks.com/topic/126083-need-helpbad/#findComment-652039 Share on other sites More sharing options...
ADLE Posted September 27, 2008 Author Share Posted September 27, 2008 Yes, using php my admin now as a matter of fact, checking it out. mysql4.0 i beleive Link to comment https://forums.phpfreaks.com/topic/126083-need-helpbad/#findComment-652046 Share on other sites More sharing options...
AdRock Posted September 28, 2008 Share Posted September 28, 2008 Did you create a connection file like a suggested? All you have to do is inlcude that on each page where a databse connection is required and it saves duplicating code Link to comment https://forums.phpfreaks.com/topic/126083-need-helpbad/#findComment-652311 Share on other sites More sharing options...
nitation Posted September 28, 2008 Share Posted September 28, 2008 Did you set your database up from your control panel. Also, are you selecting the correct DB names. I think you need to know how PHP/MYSQL works before embarking on the journey. No hard feelings. This link might help www.php.net Link to comment https://forums.phpfreaks.com/topic/126083-need-helpbad/#findComment-652323 Share on other sites More sharing options...
ADLE Posted September 29, 2008 Author Share Posted September 29, 2008 The code was not necessary Adrock, but thank you. I decided to work with my original file and edit it with the suggestions you all gave me; got it just right now. I setup the database too, think it's good to go now. Still experimenting with it though, but I can see the messages peolple send me on m database. Thanks all. Link to comment https://forums.phpfreaks.com/topic/126083-need-helpbad/#findComment-652673 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.