Hi, the below is my latest tutorial script from Sam's Learn PHP4 in 24 Hours. Hour 12. But I think that because my web host is running PHP Version 4.3.4 that there are significant compatibility issues that are now starting to keep every script I try from the book from running. but i'm not experienced enough yet to know right away what the are...I didn't realize the compatiblity issues would be that huge from 4 to 4.3.4 (but won't I have the same problem if I use the book "PHP5 for Dummies" since my web hosting is on 4.3.4?)
this particular script is supposed to generate a form which allows users to add a row of info to table "tut_domains" in my database.
instead of doing this it just generates the form, lets them fill in info and submit, and nothing gets added to the database.
I'm trying to walk it through logically, just the way the parser would, but I can't figure out why either "Error..." or "Thank you very much" don't get printed out.
<?php
if (isset($name)&&isset($domain)&&isset($sex)&&isset($domain))
{
// check user input here!
$dberror="";
$ret=add_to_database($name,$domain,$sex,$mail,$dberror);
if ($ret)
print "Error: $dberror<br>";
else
print "Thank you very much";
}
else
{
write_form();
}
function add_to_database($name,$domain,$sex,$mail,&$dberror)
{
$user="user";
$pass="password";
$db="database";
$link=mysql_connect("localhost",$user,$pass);
if (!link)
{
$dberror="Couldn't connect to MySQL server";
return false;
}
if (!mysql_select_db($db,$link))
{
$dberror=mysql_error();
return false;
}
$query="INSERT INTO tuts_domains (name, domain, sex, mail)
values('$name','$domain','$sex','$mail')";
if (!mysql_query($query,$link))
{
$dberror=mysql_error();
return false;
}
return true;
}
function write_form()
{
global $PHP_SELF;
print "<form action=\"$PHP_SELF\" method=\"POST\">\n";
print "Please enter your name: ";
print "<input type=\"text\" name=\"name\"><p>";
print "The domain you would like:";
print "<input type=\"text\" name=\"domain\"><p>";
print "Your mail address: ";
print "<input TYPE=\"text\" name=\"mail\"><p>";
print "<select name=\"sex\">\n";
print "\t<option value=\"F\"> Female\n";
print "\t<option value=\"F\"> Male\n";
print "</select>\n<p>";
print "<input type=\"submit\" value=\"Submit!\">\n</form>\n";
}
?>
I would very appreciate your help, and suggestions for how I can continue this tutorial experience without SO many compatibility related glitches along the way.