howdy!
i am having tons of problems getting this PHP stuff to work right. i have set up my database (csigs) and my table (admin_profile) from with phpMyAdmin. i ran this to make sure that i could connect to it:
<?php
$user = "****";
$pass = "****";
$db = "csigs";
$link = mysql_connect ("localhost", $user, $pass);
if (!link)
die ("Couldnt Connect to MySQL");
print "Successfully connected to the server.<br>";
mysql_select_db ($db)
or die ("Couldnt open the $db: " .mysql_error());
print "Successfully connected to the database.";
?>
Everything works fine with that. I got both 'print' messages which means i can connect.
first thing i am trying to do, which is giving me problems, is add information to the database from a form the user fills out. :. i am reading a book "PHP in 24" so i just copied everything from there to my file and uploaded it. here is what i have:
<?php
if (isset ($call_sign) && isset($password) && isset ($first_name) && isset ($last_name) && isset ($age) && isset ($state)
&& isset ($email) && isset ($aim) && isset ($icq) && isset ($quote)) {
//check user input
$dberror = "";
$ret = add_to_database ($call_sign, $password, $first_name, $last_name, $age, $state, $email, $aim, $icq, $quote, $dberror);
if (!$ret)
print "Error: $dberror<br>";
else
print "Thank you for your information...";
} else {
write_form();
//print "Your form should be here...";
}
function add_to_database ($call_sign, $password, $first_name, $last_name, $age, $state, $email, $aim, $icq, $quote, &$dberror) {
$user = "****";
$pass = "****";
$db = "csigs";
$link = mysql_connect ("localhost", $user, $pass);
if (!$link) {
$dberror = "Couldnt connect to MySQL Server";
return false;
}
if (!mysql_select_db ($db, $link)) {
$dberror = mysql_error();
return false;
}
$query = " INSERT INTO admin_profile (call_sign, password, first_name, last_name, age, state, email, aim, icq, quote)
values ('$call_sign', '$password', '$first_name', '$last_name', '$age', '$state', '$email', '$aim', '$icq', '$quote')";
if (!mysql_query ($query, $link)) {
$dberror = mysql_error();
//print "Thank you for your information...";
return false;
}
return true;
}
function write_form() {
global $PHP_SELF;
print "<form method=\"POST\"> \n";
print "<input type=\"text\" name=\"call_sign\">";
print " :your call sign<br> \n";
print "<input type=\"password\" name=\"pass\">";
print " :your password<br> \n";
print "<input type=\"text\" name=\"first_name\">";
print " :your first name<br> \n";
print "<input type=\"text\" name=\"last_name\">";
print " :your last name<br> \n";
print "<input type=\"text\" name=\"age\">";
print " :your age<br> \n";
print "<input type=\"text\" name=\"state\">";
print " :your state<br> \n";
print "<input type=\"text\" name=\"email\">";
print " :your email<br> \n";
print "<input type=\"text\" name=\"aim\">";
print " :your aim no.<br> \n";
print "<input type=\"text\" name=\"icq\">";
print " :your icq no.<br> \n";
print "<input type=\"text\" name=\"quote\">";
print " :quote<br> \n";
print "<input type=\"submit\" value=\"submit!\"> \n </form> \n";
}
?>
when and if the info is inserted into the db, on line 9, i should recieve a 'print' message. i never get this message. i ran another script to check the db and nothing is in there. :. i have check and recheck over and over again but i cant seem to find any mistakes that would be keeping this from inserting.
any help would be greatly appreciated.
thanks kindly!