Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can you explane me this assignment? It gave me error. <!DOCTYPE html> <html> <he

ID: 3704581 • Letter: C

Question

Can you explane me this assignment? It gave me error.

<!DOCTYPE html>
<html>
<head>
<title>Guest Book Post</title>
</head>
<body>

<?php
$DBConnect = @mysql_connect("host", "user", "password");
if ($DBCONNECT === FALSE)
echo "<p>Unable to connect to the database server.</p>"
."<p>Error code" . mysql_errno()
.":" . mysql_error() . "</p>";

else{
$DBName = "guestbook";
if (!@mysql_select_db($DBName, $DBConnect))
echo "<p>There are no entries in the guest book!</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_INCEMENT PRIMARY KEY,
last_name VARCHAR(40), first_name VARCHAR(40))";
$QueryReult = @mysql_query($SLstring,
$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')";
$SQLstring = @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 signing our guest book!</h1>";
}
mysql_close($DBConnect)

}
}

else{
$TableName = "visitors";
$SQLstring = "SELECT * FROM $TableName";
$QueryResult = @mysql_query($SQLstring,$DBConnect);
if (mysql_num_rows($QueryResult) == 0)
echo "<p>There are no entries in the quest book!</p>";
  
else{
echo "<p>The following visitors have signed our quest book:</p>";
echo "<table width='100%' border='1'>";
echo "<tr><th>First Name</th><th>Last Name</th></tr>";
while ((@Row = mysql_fetch_assoc($QueryResult)) !== FALSE){
echo "<td>{$Row['first_name']}</td>";
echo "<tr><td>{$Row['last_name']}</td></tr>";

}
}
mysql_free_result($QueryResult);
}
mysql_close($DBConnect);
}
?>
</body>
</html>

Explanation / Answer

This is an PHP + MYSQL code. An connection with database is established named as guest book. you have to create a database in phpmyadmin with name "guestbook".

use hostname:"localhost"

username:"root"

password:""

there is a table named as visitor

so create a table visitor.

Also create a form like,

<form method="post">

Enter First name<input type="text" name="first_name" />

Enter Last name<input type="text" name="last_name" />

<input type="submit" name="submit"/>

</form>

<!DOCTYPE html>

<html>

<head>

<title>Guest Book Post</title>

</head>

<body>

<?php

$DBConnect = mysql_connect("localhost", "root", "");

if ($DBConnect === FALSE){

echo "<p>Unable to connect to the database server.</p>"

."<p>Error code" . mysql_errno()

.":" . mysql_error() . "</p>";

}

else{

$DBName = "guestbook";

if (!mysql_select_db($DBName, $DBConnect))

echo "<p>There are no entries in the guest book!</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_INCEMENT PRIMARY KEY,

last_name VARCHAR(40), first_name VARCHAR(40))";

$QueryReult = mysql_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')";

$SQLstring = 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 signing our guest book!</h1>";

mysql_close($DBConnect);

}

}

else{

$TableName = "visitors";

$SQLstring = "SELECT * FROM $TableName";

$QueryResult = mysql_query($SQLstring,$DBConnect);

if (mysql_num_rows($QueryResult) == 0)

echo "<p>There are no entries in the quest book!</p>";

  

else{

echo "<p>The following visitors have signed our quest book:</p>";

echo "<table width='100%' border='1'>";

echo "<tr><th>First Name</th><th>Last Name</th></tr>";

while (($row = mysql_fetch_assoc($QueryResult)) !== FALSE){

echo "<td>{$row['first_name']}</td>";

echo "<tr><td>{$row['last_name']}</td></tr>";

}

}

mysql_free_result($QueryResult);

}

mysql_close($DBConnect);

?>

</body>

</html>

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote