w19sms
05-13-2008, 02:53 PM
I'm new to PHP and MySQL but not to computers. I am currently taking a Web Publishing class at my local Community College and have installed PHP and MySQL as instructed via our textbook. I am running on XP Pro w/ SP2 and using IIS as my server. I installed IIS 1st, then MySQL, and finally PHP. I have set my php.ini up correctly, I borrowed a classmates php.ini file that is working correctly. I have been searching the forums for a while now and have not found anything close to my problem. I apologize if someone else has posted on this or I put this in the wrong forum.
Here is my problem:
I have a PHP script that does work correctly on another classmates server that I typed out of our textbook. Like I said the script works on other machines.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/zhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Register Diver</title>
<link rel="stylesheet" href="php_styles.css" type="text/css" />
</head>
<body>
<h1>Aqua Don's Scuba School Registration</h1>
<?php
if (empty($_GET['first_name']) || empty($_GET['last_name']) ||
empty($_GET['phone']) || empty($_GET['address']) ||
empty($_GET['city']) || empty($_GET['state']) ||
empty($_GET['zip']) || empty($_GET['email']))
exit("<p>You must enter values in all fields of
the New Diver Registration form! Click your browser's Back button
to return to the previous page.</p>");
echo "<p> a pre issue test</p>";
$DBConnect = @mysql_connect("localhost", "w19sms", "password")
Or die("<p>The database server is not available.</p>");
echo "<p>post issue test</p>";
$DBName = "scuba_school";
if (!@mysqli_select_db($DBConnect, $DBName)) {
$SQLstring = "CREATE DATABASE $DBName";
$QueryResult = @mysqli_query($DBConnect, $SQLstring)
Or die("<p>Unable to execute the query.</p>"
. "<p>Error code " . mysqli_errno($DBConnect)
. ": " . mysqli_error($DBConnect)) . "</p>";
echo "<p>Successfully created the database.</p>";
mysqli_select_db($DBConnect, $DBName);
}
$TableName = "divers";
$SQLstring = "SELECT * FROM $TableName";
$QueryResult = @mysqli_query($DBConnect, $SQLstring);
if (!$QueryResult) {
$SQLstring = "CREATE TABLE divers (diverID SMALLINT NOT
NULL AUTO_INCREMENT PRIMARY KEY, first VARCHAR(40),
last VARCHAR(40), phone VARCHAR(40),
address VARCHAR(40), city VARCHAR(40),
state VARCHAR(2), zip VARCHAR(10))";
$QueryResult = @mysqli_query($DBConnect, $SQLstring)
Or die("<p>Unable to create the divers tale.</p>"
. "<p>Error code " . mysqli_errno($DBConnect)
. ": " . mysqli_error($DBConnect)) . "</p>";
echo "<p>Successfully created the divers table.</p>";
}
$First = addslashes($_GET['first_name']);
$Last = addslashes($_GET['last_name']);
$Phone = addslashes($_GET['phone']);
$Address = addslashes($_GET['address']);
$City = addslashes($_GET['city']);
$State = addslashes($_GET['state']);
$Zip = addslashes($_GET['zip']);
$Email = addslashes($_GET['email']);
$SQLstring = "INSERT INTO divers VALUES(NULL, '$First', '$Last',
'$Phone', '$Address', '$City', '$State', '$Zip')";
$QueryResult = @mysqli_query($DBConnect, $SQLstring)
Or die("<p>Unable to execute the query.</p>"
. "<p>Error code " . mysqli_errno($DBConnect)
. ": " . mysqli_error($DBConnect)) . "</p>";
$DiverID = mysqli_insert_id($DBConnect);
mysqli_close($DBConnect);
?>
</body>
</html>
When you run the html form and hit the register diver button it should run this script create the database and table the first time you hit the button and insert the information into the database.
What happens when I run it is I get the 1st echo line printed the "pre issue test" and that is all I get. PHP will not do anything else I do not get the "post issue test" or even the die message "The database server is not available.".
Why can I not get php to execute the following line?
$DBConnect = @mysql_connect("localhost", "w19sms", "password")
Or die("<p>The database server is not available.</p>");
I can access MySQL either by the MySQL Administrator Tool or command line access. All my accounts on MySQL have full access. I can create and modify databases in MySQL, I also can run queries and it will return the correct data.
If someone could point me in a better direction that would be great. I could really use some help, if anyone could please help me I would appreciate it.
Also I have sat with my professor for over an hour and we could not figure out what was going on.
Here is my problem:
I have a PHP script that does work correctly on another classmates server that I typed out of our textbook. Like I said the script works on other machines.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/zhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Register Diver</title>
<link rel="stylesheet" href="php_styles.css" type="text/css" />
</head>
<body>
<h1>Aqua Don's Scuba School Registration</h1>
<?php
if (empty($_GET['first_name']) || empty($_GET['last_name']) ||
empty($_GET['phone']) || empty($_GET['address']) ||
empty($_GET['city']) || empty($_GET['state']) ||
empty($_GET['zip']) || empty($_GET['email']))
exit("<p>You must enter values in all fields of
the New Diver Registration form! Click your browser's Back button
to return to the previous page.</p>");
echo "<p> a pre issue test</p>";
$DBConnect = @mysql_connect("localhost", "w19sms", "password")
Or die("<p>The database server is not available.</p>");
echo "<p>post issue test</p>";
$DBName = "scuba_school";
if (!@mysqli_select_db($DBConnect, $DBName)) {
$SQLstring = "CREATE DATABASE $DBName";
$QueryResult = @mysqli_query($DBConnect, $SQLstring)
Or die("<p>Unable to execute the query.</p>"
. "<p>Error code " . mysqli_errno($DBConnect)
. ": " . mysqli_error($DBConnect)) . "</p>";
echo "<p>Successfully created the database.</p>";
mysqli_select_db($DBConnect, $DBName);
}
$TableName = "divers";
$SQLstring = "SELECT * FROM $TableName";
$QueryResult = @mysqli_query($DBConnect, $SQLstring);
if (!$QueryResult) {
$SQLstring = "CREATE TABLE divers (diverID SMALLINT NOT
NULL AUTO_INCREMENT PRIMARY KEY, first VARCHAR(40),
last VARCHAR(40), phone VARCHAR(40),
address VARCHAR(40), city VARCHAR(40),
state VARCHAR(2), zip VARCHAR(10))";
$QueryResult = @mysqli_query($DBConnect, $SQLstring)
Or die("<p>Unable to create the divers tale.</p>"
. "<p>Error code " . mysqli_errno($DBConnect)
. ": " . mysqli_error($DBConnect)) . "</p>";
echo "<p>Successfully created the divers table.</p>";
}
$First = addslashes($_GET['first_name']);
$Last = addslashes($_GET['last_name']);
$Phone = addslashes($_GET['phone']);
$Address = addslashes($_GET['address']);
$City = addslashes($_GET['city']);
$State = addslashes($_GET['state']);
$Zip = addslashes($_GET['zip']);
$Email = addslashes($_GET['email']);
$SQLstring = "INSERT INTO divers VALUES(NULL, '$First', '$Last',
'$Phone', '$Address', '$City', '$State', '$Zip')";
$QueryResult = @mysqli_query($DBConnect, $SQLstring)
Or die("<p>Unable to execute the query.</p>"
. "<p>Error code " . mysqli_errno($DBConnect)
. ": " . mysqli_error($DBConnect)) . "</p>";
$DiverID = mysqli_insert_id($DBConnect);
mysqli_close($DBConnect);
?>
</body>
</html>
When you run the html form and hit the register diver button it should run this script create the database and table the first time you hit the button and insert the information into the database.
What happens when I run it is I get the 1st echo line printed the "pre issue test" and that is all I get. PHP will not do anything else I do not get the "post issue test" or even the die message "The database server is not available.".
Why can I not get php to execute the following line?
$DBConnect = @mysql_connect("localhost", "w19sms", "password")
Or die("<p>The database server is not available.</p>");
I can access MySQL either by the MySQL Administrator Tool or command line access. All my accounts on MySQL have full access. I can create and modify databases in MySQL, I also can run queries and it will return the correct data.
If someone could point me in a better direction that would be great. I could really use some help, if anyone could please help me I would appreciate it.
Also I have sat with my professor for over an hour and we could not figure out what was going on.