Jump to content

Need help...bad


ADLE

Recommended Posts

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&#64;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
Share on other sites

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
Share on other sites

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: 'sometihng@72.13.16.211' (Using password: YES)

 

so i changed it back to: mysql_connect ("localhost"), "projectc_testuse", "password")

 

Thanks Piranha, really appreciate this.

Link to comment
Share on other sites

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
Share on other sites

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