| | |
Help! my script couldn't submit form data to mysql database
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jul 2008
Posts: 39
Reputation:
Solved Threads: 1
Despite the fact that my script runs perfectly well on the server, it fails to submit form data into mysql database. Kindly look into this for me. see code below:
Is the issue really with the script or with my mysql database table structure?
php Syntax (Toggle Plain Text)
<?php> $dbcnx = mysql_connect("localhost","user_name","password"); if (!$dbcnx){ exit('<p>Unable to connect to the database</p>'); } If (isset($_POST['submit'])) { $SchoolName = $_POST['SchoolName']; $SchoolEmail = $_POST['SchoolEmail']; $UserName = $_POST['UserName']; $pscode = $_POST['pscode']; $sql = mysql_query("INSERT INTO accesscarduse (SchoolName, SchoolEmail, UserName, pscode) VALUES ('$SchoolName', '$SchoolEmail', '$UserName', '$pscode')"); } echo "Values successfully submitted to database. Thank you" ; ?>
O God! He that teaches man what he knows not, please grant us the solution.
Nothing wrong with the script. Umm.. Check if it enters the loop,
Try mysql_error to know what exactly is the error message. ie.,
Also check if error reporting is turned on on your server.
If (isset($_POST['submit'])) { . Try mysql_error to know what exactly is the error message. ie.,
php Syntax (Toggle Plain Text)
$sql = mysql_query("INSERT INTO accesscarduse (SchoolName, SchoolEmail, UserName, pscode) VALUES ('$SchoolName', '$SchoolEmail', '$UserName', '$pscode')") or die (mysql_error());
Ignorance is definitely not bliss!
*PM asking for help will be ignored*
*PM asking for help will be ignored*
In addition you have an extra closing bracket on the first line and your mysql query's need escaping. Try making your code the following:
Just a note, it has also been suggested on another topic that using single quotes wherever possible will speed up execution time.
php Syntax (Toggle Plain Text)
<?php $dbcnx = mysql_connect("localhost","user_name","password"); if (!$dbcnx){ exit('<p>Unable to connect to the database</p>'); } if (isset($_POST['submit'])) { $SchoolName = mysql_real_escape_string($_POST['SchoolName']); $SchoolEmail = mysql_real_escape_string($_POST['SchoolEmail']); $UserName = mysql_real_escape_string($_POST['UserName']); $pscode = mysql_real_escape_string($_POST['pscode']); $sql = mysql_query('INSERT INTO accesscarduse (SchoolName, SchoolEmail, UserName, pscode) VALUES ("'.$SchoolName.'", "'.$SchoolEmail.'", "'.$UserName.'", "'.$pscode.'")') or die(mysql_error()); } echo 'Values successfully submitted to database. Thank you'; ?>
Try not to bump 10 year old threads as it can be really annoying.
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
•
•
Join Date: Jul 2008
Posts: 39
Reputation:
Solved Threads: 1
Thanks for the help fellas. After going through your suggestions, I restructure the script using the recommendations you gave me. I also noticed that I didn't select my database in the mysql query. So I rewrote the code as below and got the message sorry database not connectedNo database selected
nav33, will you look into this as you are immediately online now.
php Syntax (Toggle Plain Text)
<?php> $dbcnx = mysql_connect("localhost","lsschnln_emiolab","bembestica"); if (!$dbcnx){ exit('<p>Unable to connect to the database</p>'); } $dbselector = mysql_select_db('lsschnln01'); if (!$dbselector){ echo('sorry database not connected'); } If (isset($_POST['validate'])) { $SchoolName = mysql_real_escape_string($_POST['SchoolName']); $SchoolEmail = mysql_real_escape_string($_POST['SchoolEmail']); $UserName = mysql_real_escape_string($_POST['UserName']); $pscode = mysql_real_escape_string($_POST['pscode']); $sql = mysql_query("INSERT INTO accesscarduse (SchoolName, SchoolEmail, UserName, pscode) VALUES ('$SchoolName', '$SchoolEmail', '$UserName', '$pscode')")or die (mysql_error()); } echo "Values successfully submitted to database. Thank you" ; ?>
O God! He that teaches man what he knows not, please grant us the solution.
Ah! How could we miss that in your first post
Even after specifying the database, it said "sorry database not connected No database selected" ? Hmm.. Strange..
Try this.. The 2nd parameter is optional, but, lets see if this can do the trick.
you better check if the database really exist.
P.S. Never give out your database username/password in a forum.
Even after specifying the database, it said "sorry database not connected No database selected" ? Hmm.. Strange..
Try this.. The 2nd parameter is optional, but, lets see if this can do the trick.
$dbselector = mysql_select_db('lsschnln01',$dbcnx); If it still says no database selected, then P.S. Never give out your database username/password in a forum.
Ignorance is definitely not bliss!
*PM asking for help will be ignored*
*PM asking for help will be ignored*
•
•
Join Date: Jul 2008
Posts: 39
Reputation:
Solved Threads: 1
Thanks for your advice nav33. I had posted before realizing my folly. Immediately after posting, I visited w3schools and noticed what you too sugessted and addede the parameter but I still got the same response. Take a look please
I've gone into my database to check things up. lsschnln01 is available for sure. Should I drop the database and recreate it? Please advise.
Also, I have no idea about how to script a site search engine for my website without the option of google search. Please if you have any code guide, bless me with it.
Thanks.
php Syntax (Toggle Plain Text)
$dbcnx
php Syntax (Toggle Plain Text)
<?php> $dbcnx = mysql_connect("localhost","username","password"); if (!$dbcnx){ exit('<p>Unable to connect to the database</p>'); } $dbselector = mysql_select_db('lsschnln01', $dbcnx); if (!$dbselector){ echo('sorry database not connected'); } If (isset($_POST['validate'])) { $SchoolName = mysql_real_escape_string($_POST['SchoolName']); $SchoolEmail = mysql_real_escape_string($_POST['SchoolEmail']); $UserName = mysql_real_escape_string($_POST['UserName']); $pscode = mysql_real_escape_string($_POST['pscode']); $sql = mysql_query("INSERT INTO accesscarduse (SchoolName, SchoolEmail, UserName, pscode) VALUES ('$SchoolName', '$SchoolEmail', '$UserName', '$pscode')")or die (mysql_error()); } echo "Values successfully submitted to database. Thank you" ; ?>
Also, I have no idea about how to script a site search engine for my website without the option of google search. Please if you have any code guide, bless me with it.
Thanks.
O God! He that teaches man what he knows not, please grant us the solution.
Darn! I typed a long paragraph and just before I clicked 'Post' I lost my internet connection.
Does it still say No database selected ? You only get "No database selected" if you don't have mysql_select_db or if you have specified wrong database name.
Anyways, Try using another database to see if that works. If it doesn't work, then you have to contact your system admin
Sorry. I don't have any guide w.r.t site search engine. Well, maybe someone else from this forum can help you with it.
Does it still say No database selected ? You only get "No database selected" if you don't have mysql_select_db or if you have specified wrong database name.

Anyways, Try using another database to see if that works. If it doesn't work, then you have to contact your system admin
Sorry. I don't have any guide w.r.t site search engine. Well, maybe someone else from this forum can help you with it.
Last edited by nav33n; Mar 4th, 2009 at 5:15 pm.
Ignorance is definitely not bliss!
*PM asking for help will be ignored*
*PM asking for help will be ignored*
![]() |
Similar Threads
- Populating form with existing MySQL data (PHP)
- Parsing html form. (PHP)
- Image upload from, Form into Folder and MySQL (PHP)
- Sending form data in an email (PHP)
- need help finding a script or tool to use for a news update program. (PHP)
- send data from while loop to mysql database (PHP)
- submiting info into a database for retrieval! (PHP)
- bringing data from mysql using select box (PHP)
- question about connecting odbc to sql through php script (PHP)
- Mysql num rows(): Invalid argument (PHP)
Other Threads in the PHP Forum
- Previous Thread: PHP MYSQL split results?
- Next Thread: mysql_fetch_array failure?
| Thread Tools | Search this Thread |
ajax apache api array arrays beginner binary broken cache cakephp checkbox class cms code confirm cron curl customizableitems database date display dynamic echo email error external file files folder form forms forum function functions google header headmethod howtowriteathesis href htaccess html iframe image include insert integration ip java javascript joomla limit link login loop mail malfunction menu method mlm multiple mysql neutrality oop paypal pdf php phpmysql play problem query question radio random recursion regex remote root script search select server sessions sms soap source space sql syntax system table tutorial update upload url validator variable video web xml youtube






