Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
03-22-2007, 11:48 PM #1
- Join Date
- Mar 2007
- Thanked 0 Times in 0 Posts
MySQL and GoDaddy - inserting data using PHP problems
I have been having trouble inserting data into my GoDaddy mysql database using a simple php interface (see code below). (I have a more complex php and MySQL that a webmaster friend of mine setup for my website too). The code seems fine, no error comes up when submitting the data, no login error, etc. but when we check the MySQL database it always stays empty. No data is entered.
You can check out the more detailed php my friend made
Any ideas of what might be going on? GoDaddy offered no help whatsever, they said it was beyond theire technical expertise!
Thanks for any help!
$hostname = "h50mysql7.secureserver.net";
$db_user = "atwaterhigh";
$db_password = omitted;
$db_table = "rsvp";
$db = mysql_connect($hostname, $db_user, $db_password);
<title>How To Insert Data Into MySQL db using form in php</title>
How To Insert Data Into MySQL db using form in php<hr>
# THIS CODE TELL MYSQL TO INSERT THE DATA FROM THE FORM INTO YOUR MYSQL TABLE
$sql = "INSERT INTO $db_table(user_name,user_email) values ('$user_name','$user_email')";
$result = mysql_query($sql ,$db);
echo "Thank you, Your information has been entered into our database";
<form method="post" action="">
<input type="text" name="user_name">
<input type="text" name="user_email">
<input type="submit" name="Submit" value="Submit">
03-22-2007, 11:58 PM #2
- Join Date
- Oct 2006
- Denver, Colorado USA
- Thanked 316 Times in 308 Posts
The code has no error checking and reporting to tell you what it might or might not be doing. The following code is taken from an example in the mysql section of the PHP manual, note the or die('Some message' . mysql_error()) that is used with each mysql function call to give information should the function call fail -
// Connecting, selecting database
$link = mysql_connect('mysql_host', 'mysql_user', 'mysql_password') or die('Could not connect: ' . mysql_error());
echo 'Connected successfully';
mysql_select_db('my_database') or die('Could not select database');
// Performing SQL query
$query = 'SELECT * FROM my_table';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.