talimore1
12-05-2010, 09:04 PM
Hello everyone, for this class assignment I have to just copy and paste out of the book but its not working!!! How is that even possible. I sharing the simple code here but Ill also share what Im getting from it:
You must enter your first and last name! Click your browser's Back button to return to the Guest Book form."; else { $DBConnect = @mysql_connect("localhost", "mgs314", "password"); if ($DBconnect === FALSE) echo "
Ubable to connect to the database server.
" . "
Error Code " . mysql_errno() . ": " . mysql_error() . "
"; else { $DBName = "guestbook"; if (!@mysql_select_db($DBName, $DBConnect)) { $SQLstring = "CREATE DATABASE $DBName"; $QueryResult = @mysql_query($SQLstring, $DBConnect); if ($QueryResult ===FALSE) echo "
Unable to execute the query.
" . "
Error code " . mysql_errno($DBConnect) . ": " . mysql_error($DBConnect) . "
"; else echo "
You are the first visitor!
"; } mysql_select_db($DBName, $DBConnect); $TableName = "visitors"; $SQLstring = "SHOW TABLES LIKE '$TableName'"; $QueryResult = @mysql_query($SQLstring, $DBConnect); if (mysql_num_rows($QueryResult) == 0) { $SQLstring = "CREATE TABLE $TableName (countID SMALLINT NOT NULL AUTO_INCREMENT PRIMARY KEY, last_name VARCHAR(40), first_name VARCHAR(40))"; $QueryResult = @myswl_query($SQLstring, $DBConnect); if ($QueryResult === FALSE) echo "
Unable to create the table.
" . "
Error code " . mysql_errno($DBConnect) . ": " . mysql_error($DBConnect) . "
"; $LastName = stripslashes($_POST['last_name']); $FirstName = stripslashes($_POST['first_name']); $SQLstring = "INSERT INTO $TableName VALUES(NULL, '$LastName', '$FirstName')"; $QueryResult = @mysql_query($SQLstring, $DBConnect); if ($QueryResult === FALSE) echo "
Unable to execute the query.
" . "
Error code " . mysql_errno($DBConnect) . ": " . mysql_error($DBConnect) . "
"; else echo "
Thank you for signing our guest book!
"; } mysql_close($DBConnect); } } ?>
And here are the two pages code:
<form method="POST" action="signguestbook.php">
<p>First Name <input type="text" name="first_name" /></p>
<p>Last Name <input type="text" name="last_name" /></p>
<p><input type="submit" value="Submit"></p>
</form>
and the php page that it sends to:
<?php
if (empty($_POST['first_name']) OR empty($_POST['last_name']))
echo "<p>You must enter your first and last name! Click your browser's Back button to return to the Guest Book form.</p>";
else {
$DBConnect = @mysql_connect("localhost", "mgs314", "password");
if ($DBconnect === FALSE)
echo "<p>Ubable to connect to the database server.</p>" . "<p>Error Code " . mysql_errno() . ": " . mysql_error() . "</p>";
else {
$DBName = "guestbook";
if (!@mysql_select_db($DBName, $DBConnect)) {
$SQLstring = "CREATE DATABASE $DBName";
$QueryResult = @mysql_query($SQLstring, $DBConnect);
if ($QueryResult ===FALSE)
echo "<p>Unable to execute the query.</p>" . "<p>Error code " . mysql_errno($DBConnect) . ": " . mysql_error($DBConnect) . "</p>";
else
echo "<p> You are the first visitor!<p>";
}
mysql_select_db($DBName, $DBConnect);
$TableName = "visitors";
$SQLstring = "SHOW TABLES LIKE '$TableName'";
$QueryResult = @mysql_query($SQLstring, $DBConnect);
if (mysql_num_rows($QueryResult) == 0) {
$SQLstring = "CREATE TABLE $TableName (countID SMALLINT NOT NULL AUTO_INCREMENT PRIMARY KEY, last_name VARCHAR(40), first_name VARCHAR(40))";
$QueryResult = @myswl_query($SQLstring, $DBConnect);
if ($QueryResult === FALSE)
echo "<p> Unable to create the table.</p>" . "<p>Error code " . mysql_errno($DBConnect) . ": " . mysql_error($DBConnect) . "</p>";
$LastName = stripslashes($_POST['last_name']);
$FirstName = stripslashes($_POST['first_name']);
$SQLstring = "INSERT INTO $TableName VALUES(NULL, '$LastName', '$FirstName')";
$QueryResult = @mysql_query($SQLstring, $DBConnect);
if ($QueryResult === FALSE)
echo "<p>Unable to execute the query.</p>" . "<p>Error code " . mysql_errno($DBConnect) . ": " . mysql_error($DBConnect) . "</p>";
else
echo "<h1>Thank you for signing our guest book!</h1>";
}
mysql_close($DBConnect);
}
}
?>
Both are using Strict DTD.
Thanks in Advance for the help!
You must enter your first and last name! Click your browser's Back button to return to the Guest Book form."; else { $DBConnect = @mysql_connect("localhost", "mgs314", "password"); if ($DBconnect === FALSE) echo "
Ubable to connect to the database server.
" . "
Error Code " . mysql_errno() . ": " . mysql_error() . "
"; else { $DBName = "guestbook"; if (!@mysql_select_db($DBName, $DBConnect)) { $SQLstring = "CREATE DATABASE $DBName"; $QueryResult = @mysql_query($SQLstring, $DBConnect); if ($QueryResult ===FALSE) echo "
Unable to execute the query.
" . "
Error code " . mysql_errno($DBConnect) . ": " . mysql_error($DBConnect) . "
"; else echo "
You are the first visitor!
"; } mysql_select_db($DBName, $DBConnect); $TableName = "visitors"; $SQLstring = "SHOW TABLES LIKE '$TableName'"; $QueryResult = @mysql_query($SQLstring, $DBConnect); if (mysql_num_rows($QueryResult) == 0) { $SQLstring = "CREATE TABLE $TableName (countID SMALLINT NOT NULL AUTO_INCREMENT PRIMARY KEY, last_name VARCHAR(40), first_name VARCHAR(40))"; $QueryResult = @myswl_query($SQLstring, $DBConnect); if ($QueryResult === FALSE) echo "
Unable to create the table.
" . "
Error code " . mysql_errno($DBConnect) . ": " . mysql_error($DBConnect) . "
"; $LastName = stripslashes($_POST['last_name']); $FirstName = stripslashes($_POST['first_name']); $SQLstring = "INSERT INTO $TableName VALUES(NULL, '$LastName', '$FirstName')"; $QueryResult = @mysql_query($SQLstring, $DBConnect); if ($QueryResult === FALSE) echo "
Unable to execute the query.
" . "
Error code " . mysql_errno($DBConnect) . ": " . mysql_error($DBConnect) . "
"; else echo "
Thank you for signing our guest book!
"; } mysql_close($DBConnect); } } ?>
And here are the two pages code:
<form method="POST" action="signguestbook.php">
<p>First Name <input type="text" name="first_name" /></p>
<p>Last Name <input type="text" name="last_name" /></p>
<p><input type="submit" value="Submit"></p>
</form>
and the php page that it sends to:
<?php
if (empty($_POST['first_name']) OR empty($_POST['last_name']))
echo "<p>You must enter your first and last name! Click your browser's Back button to return to the Guest Book form.</p>";
else {
$DBConnect = @mysql_connect("localhost", "mgs314", "password");
if ($DBconnect === FALSE)
echo "<p>Ubable to connect to the database server.</p>" . "<p>Error Code " . mysql_errno() . ": " . mysql_error() . "</p>";
else {
$DBName = "guestbook";
if (!@mysql_select_db($DBName, $DBConnect)) {
$SQLstring = "CREATE DATABASE $DBName";
$QueryResult = @mysql_query($SQLstring, $DBConnect);
if ($QueryResult ===FALSE)
echo "<p>Unable to execute the query.</p>" . "<p>Error code " . mysql_errno($DBConnect) . ": " . mysql_error($DBConnect) . "</p>";
else
echo "<p> You are the first visitor!<p>";
}
mysql_select_db($DBName, $DBConnect);
$TableName = "visitors";
$SQLstring = "SHOW TABLES LIKE '$TableName'";
$QueryResult = @mysql_query($SQLstring, $DBConnect);
if (mysql_num_rows($QueryResult) == 0) {
$SQLstring = "CREATE TABLE $TableName (countID SMALLINT NOT NULL AUTO_INCREMENT PRIMARY KEY, last_name VARCHAR(40), first_name VARCHAR(40))";
$QueryResult = @myswl_query($SQLstring, $DBConnect);
if ($QueryResult === FALSE)
echo "<p> Unable to create the table.</p>" . "<p>Error code " . mysql_errno($DBConnect) . ": " . mysql_error($DBConnect) . "</p>";
$LastName = stripslashes($_POST['last_name']);
$FirstName = stripslashes($_POST['first_name']);
$SQLstring = "INSERT INTO $TableName VALUES(NULL, '$LastName', '$FirstName')";
$QueryResult = @mysql_query($SQLstring, $DBConnect);
if ($QueryResult === FALSE)
echo "<p>Unable to execute the query.</p>" . "<p>Error code " . mysql_errno($DBConnect) . ": " . mysql_error($DBConnect) . "</p>";
else
echo "<h1>Thank you for signing our guest book!</h1>";
}
mysql_close($DBConnect);
}
}
?>
Both are using Strict DTD.
Thanks in Advance for the help!