943,569 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 7465
  • PHP RSS
Jun 14th, 2004
0

php wont submit data into the database

Expand Post »
[php]<?
$DBhost = "localhost";//location of mySQL on server/site
$DBuser = "michael";//User name for logging onto mySQL
$DBpass = "";//Password for logging onto mySQL
$DBName = "user_login_info";//Name of the databse for logging into
$table = "login_info";//Name of the Table to be used steps to create are included
$name = "$_POST[name]";//Name that the person gave on the form
$email = "$_POST[email]";//Email that person gave on the form
$con_email = "$_POST[confirm_email]";//confirm their email is correct
$sex = "$_POST[sex]";//sex of the person
$month = "$_POST[month]";//month person was born
$day = "$_POST[day]";//day person was born
$year = "$_POST[year]";//year person was born


if ($email != $con_email)
{
echo "sorry the emails you provided do not match!<br />";
echo "Please use the back button to correct this error and resubmit<br />";
}
else
{
mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database"); //connecting to the database using the variable set
@mysql_select_db("$DBName") or die("Unable to select database $DBName"); //at connection to the databse select DBNAME (phpforms) or tell that it couldnt connect
$sqlquery = "INSERT INTO $table VALUES('$id','$name','$email','$email','$con_email','$sex','$month','$day','$year')"; //Telling the mySQL to insert the values from the form into the databse coresponding with the form

$results = mysql_query($sqlquery); //Query the results

mysql_close();

echo "
<html>
<head>
<title> Registerd Data </title>
</head>
<body>
<center>
<table border='0' width='500'>
<tr>";

echo " <td>
<font face='verdana' size='+0'>
<center>
<p>You Just Entered This Information Into the Database</p>
</center>";
//display the information that user submitted in the previous form
echo " <blockquote>
<center>
<p>
Name : $name
</p>
<p>
E-Mail : $email
</p>
<p>
Sex : $sex
</p>
<p>
Birthdate: $month / $day / $year
</p>
</center>
</blockquote>
</td>
</tr>
</table>
</center>
</body>
</html>";
}
?>[/php]

for some reason i cant get this to submit any data into to my database, ive been trying to create a sort of registration form, so i modified the tutorial that i had been working on, but now it wont send the data to my database, but it will display the information that i have entered at the bottom of the screen (the info is displayed in the 'echo' areas.

heres the code for the form if you need to see that too

PHP Syntax (Toggle Plain Text)
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "<a rel="nofollow" href="http://www.w3.org/TR/html4/loose.dtd" target="_blank">http://www.w3.org/TR/html4/loose.dtd</a>">
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  5. <title>Handling forms with PHP</title>
  6. </head>
  7. <body>
  8. <center>
  9. <form method="post" action="confirm_reg.php">
  10. <table border="1">
  11. <tr>
  12. <td colspan="2">
  13. Please Register to continue!
  14. </td>
  15. </tr>
  16. <tr>
  17. <td>
  18. </td>
  19. </tr>
  20. <tr>
  21. <td align="left">
  22. <p><b> Your Name:</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="name" id="name"></p>
  23. <p><b> E-Mail Address:</b>&nbsp;&nbsp;&nbsp;<input type="text" name="email" id="email"></p>
  24. <p><b> E-Mail Again:</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="confirm_email" id="confirm_email"></p>
  25. <p><b> Sex:</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  26. <select name="sex" id="sex">
  27. <option value="unknown">
  28. Unknown
  29. </option>
  30. <option value="male">
  31. Male
  32. </option>
  33. <option value="female">
  34. Female
  35. </option>
  36. </select></p>
  37. <p><b> Birthdate:</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  38. <input type="text" size="2" maxlength="2" name="month" id="month">/
  39. <input type="text" size="2" maxlength="2" name="day" id="day">/
  40. <input type="text" size="4" maxlength="4" name="year" id="year"></p>
  41. </td>
  42. </tr>
  43. <tr>
  44. <td colspan="2">
  45. <input type="submit" value="Tell us!">
  46. </td>
  47. </tr>
  48. </table>
  49. </form>
  50. </center>
  51. </body>
  52. </html>
Similar Threads
Reputation Points: 152
Solved Threads: 39
Master Poster
Killer_Typo is offline Offline
778 posts
since Apr 2004
Jun 14th, 2004
0

Re: php wont submit data into the database

$results = mysql_query($sqlquer y); //Query the results

if(!$results){
echo(mysql_error());
}
Reputation Points: 16
Solved Threads: 2
Junior Poster
Arizona Web is offline Offline
118 posts
since Jun 2004
Jun 14th, 2004
0

Re: php wont submit data into the database

Quote originally posted by Arizona Web ...
$results = mysql_query($sqlquer y); //Query the results

if(!$results){
echo(mysql_error());
}
thank you thank you thank you.

here are the results.

Column count doesn't match value count at row 1

(heres a screenshot of what the database looks like)




Quote originally posted by Killer_Typo ...
thank you thank you thank you.

here are the results.

Column count doesn't match value count at row 1

(heres a screenshot of what the database looks like)
srry for the double post, but i figured it out, i had accidently included $email twice, once removing the second $email it all worked out. thanks arizona web for the help, i wouldnt have thought to double check that if i hadnt seen the error that i got.
Attached Thumbnails
Click image for larger version

Name:	database picture.JPG
Views:	50
Size:	71.4 KB
ID:	461  
Last edited by samaru; Jun 15th, 2004 at 1:57 am.
Reputation Points: 152
Solved Threads: 39
Master Poster
Killer_Typo is offline Offline
778 posts
since Apr 2004
Jun 14th, 2004
0

Re: php wont submit data into the database

NP bud. While I am developing I always echo errors after every SQL statement in PHP and keep debug on in other languages. Makes it easier to know off the bat where the problems are.
Reputation Points: 16
Solved Threads: 2
Junior Poster
Arizona Web is offline Offline
118 posts
since Jun 2004
Jun 15th, 2004
0

Re: php wont submit data into the database

Quote originally posted by Killer_Typo ...
srry for the double post, but i figured it out, i had accidently included $email twice, once removing the second $email it all worked out. thanks arizona web for the help, i wouldnt have thought to double check that if i hadnt seen the error that i got.
Glad you were able to figure it out, but please use the "edit" button to modify your post. It doesn't take very long. It's the second time, that I know of, that you double post. I don't want to be a bit**, but obey the rules.
Team Colleague
Reputation Points: 262
Solved Threads: 18
a.k.a inscissor
samaru is offline Offline
1,227 posts
since Feb 2002

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: PHP Sessions on IIS
Next Thread in PHP Forum Timeline: phpbb2.X news?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC