...

View Full Version : MySQL and GoDaddy - inserting data using PHP problems



CBEP
03-23-2007, 12:48 AM
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

www.ahs1997.com/alumni.php
www.ahs1197.com/submit.php

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!

(www.ahs1997.com/enter-data.com)

<?php
$hostname = "h50mysql7.secureserver.net";
$db_user = "atwaterhigh";
$db_password = omitted;
$db_table = "rsvp";


$db = mysql_connect($hostname, $db_user, $db_password);
mysql_select_db($db_table,$db);
?>
<html>
<head>
<title>How To Insert Data Into MySQL db using form in php</title>
</head>
<body>
How To Insert Data Into MySQL db using form in php<hr>
<?php
if (isset($_REQUEST['Submit']))
{
# 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";
}
else
{
?>
<form method="post" action="">
Name:<br>
<input type="text" name="user_name">
<br>
Email: <br>
<input type="text" name="user_email">
<br><br>
<input type="submit" name="Submit" value="Submit">
</form>
<?php
}
?>
<body>

</body>
</html>

CFMaBiSmAd
03-23-2007, 12:58 AM
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());



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum