Question

My 2nd Try asking the same "PHP Programming with MySQL question. When I run my code,...

My 2nd Try asking the same "PHP Programming with MySQL question.

When I run my code, I get the following messages:

Notice: Undefined index: email in /Applications/XAMPP/xamppfiles/htdocs/Week9/VerifyLogin.php on line 71
Notice: Undefined index: password in /Applications/XAMPP/xamppfiles/htdocs/Week9/VerifyLogin.php on line 71
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, null given in /Applications/XAMPP/xamppfiles/htdocs/Week9/VerifyLogin.php on line 75

The e-mail address/password combination entered is not valid.

Please use your browser's BACK button to return to the form and fix the errors indicated.

Please use your browser's BACK button to return to the form and fix the errors indicated.

- Please help me fix my code and provide screenshot and revised code. Thank you :)

------

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">

<html xmlns="https://www.w3.org/1999/xhtml">

<head>

<title>Verify Intern Login</title>

</head>

<body>

<h1>College Internship</h1>

<h2>Verify Intern Login</h2>

<?php

{

$errors = 0;

$DBConnect = @mysqli_connect("localhost", "root", "");

if ($DBConnect === FALSE) {

echo "

<p>

Unable to connect to the database

server. " . "Error code " . mysqli_errno() . ": " . mysqli_error() . "

</p>\n";

++$errors;

} else {

$DBName = "internships";

$result = @mysqli_select_db($DBName, $DBConnect);

if ($result === FALSE) {

echo "

<p>

Unable to select the database. " . "Error code " . mysqli_errno($DBConnect) . ": " . mysqli_error($DBConnect) . "

</p>\n";

++$errors;

}

}

}

{

$TableName = "interns";

if ($errors == 0) {

$SQLstring = "SELECT internID, first, last FROM

$TableName" . " where email='" . stripslashes($_POST['email']) . "' and password_md5='" . md5(stripslashes($_POST['password'])) . "'";

$QueryResult = @mysqli_query($SQLstring, $DBConnect);

if (mysqli_num_rows($QueryResult) == 0) {

echo "

<p>

The e-mail address/password " . " combination entered is not valid.

</p>\n";

++$errors;

} else {

$Row = mysqli_fetch_assoc($QueryResult);

$InternID = $Row['internID'];

$InternName = $Row['first'] . " " . $Row['last'];

echo "

<p>

Welcome back, $InternName!

</p>\n";

}

}

}

{

if ($errors > 0) {

echo "

<p>

Please use your browser's BACK button

to return " . " to the form and fix the errors

indicated.

</p>\n";

if ($errors > 0) {

echo "

<p>

Please use your browser's BACK button

to return " . " to the form and fix the errors

indicated.

</p>\n";

}

}

}

?>

</body>

</html>

0 0
Add a comment Improve this question Transcribed image text
Answer #1

I think the problem is that you haven't checked if the POST variable is set, which you can check by

'if(isset($_POST['email']) && isset($_POST['email']))'

so code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">

<html xmlns="https://www.w3.org/1999/xhtml">

<head>

<title>Verify Intern Login</title>

</head>

<body>

<h1>College Internship</h1>

<h2>Verify Intern Login</h2>

<?php

if(isset($_POST['email']) && isset($_POST['email']))

{

$errors = 0;

$DBConnect = @mysqli_connect("localhost", "root", "");

if ($DBConnect === FALSE) {

echo "

<p>

Unable to connect to the database server. " . "Error code " . mysqli_errno() . ": " . mysqli_error() . "

</p>\n";

++$errors;

} else {

$DBName = "internships";

$result = @mysqli_select_db($DBName, $DBConnect);

if ($result === FALSE) {

echo "

<p>

Unable to select the database. " . "Error code " . mysqli_errno($DBConnect) . ": " . mysqli_error($DBConnect) . "

</p>\n";

++$errors;

}

}

$TableName = "interns";

if ($errors == 0) {

$SQLstring = "SELECT internID, first, last FROM

$TableName" . " where email='" . stripslashes($_POST['email']) . "' and password_md5='" . md5(stripslashes($_POST['password'])) . "'";

$QueryResult = @mysqli_query($SQLstring, $DBConnect);

if (mysqli_num_rows($QueryResult) == 0) {

echo "

<p>

The e-mail address/password " . " combination entered is not valid.

</p>\n";

++$errors;

} else {

$Row = mysqli_fetch_assoc($QueryResult);

$InternID = $Row['internID'];

$InternName = $Row['first'] . " " . $Row['last'];

echo "

<p>

Welcome back,".$InternName."!

</p>\n";

}

}

if ($errors > 0) {

echo "

<p>

Please use your browser's BACK button to return " . " to the form and fix the errors indicated.</p>\n";

if ($errors > 0) {

echo "

<p>

Please use your browser's BACK button to return " . " to the form and fix the errors indicated.

</p>\n";

}

}

}

?>

</body>

</html>

Add a comment
Know the answer?
Add Answer to:
My 2nd Try asking the same "PHP Programming with MySQL question. When I run my code,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • PHP Programming with MySQL - Why do I get the following error and how do I...

    PHP Programming with MySQL - Why do I get the following error and how do I connect to my database. Looks like I might need to use mysqli instead of mysql but I dont know how to do that or what to change. I appreciate it is you fixed anything that needs to be re-written. Fatal error: Uncaught Error: Call to undefined function mysql_connect() in /Applications/XAMPP/xamppfiles/htdocs/Week9/VerifyLogin.php:12 Stack trace: #0 {main} thrown in /Applications/XAMPP/xamppfiles/htdocs/Week9/VerifyLogin.php on line 12 Line 12: $DBConnect =...

  • I am having an issue. When i press submit to test the code, it goes to...

    I am having an issue. When i press submit to test the code, it goes to a blank screen. Please, will some one assist me? Thanks! <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Sign Guest Book</title> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> </head> <body> <?php if (empty($_POST['?rst_name']) || empty($_POST['last_name']))     echo "<p>You must enter your ?rst and last name! Click your browser's Back button to return to the Guest Book form.</p>"; else {     $DBConnect = @mysql_connect("localhost", "root", "");    ...

  • PHP Programming In this project, you will create a Web page that allows visitors to your...

    PHP Programming In this project, you will create a Web page that allows visitors to your site to sign a guest book that is saved to a database. Create a new document in your text editor and type the <!DOCTYPE> declaration, <html> element, document head, and <body> element. Use the strict DTD and “Guest Book” as the content of the <title> element. Add the following text and elements to the document body: <h2>Enter your name to sign our guest book</h2>...

  • PHP code that is given : <?php // Here is where your preprocessing code goes //...

    PHP code that is given : <?php // Here is where your preprocessing code goes // An example is already given to you for the First Name $fname = $_GET['fname']; ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Exercise 2 - GET Echo</title> <style> body { margin:0; padding:0; font-family: Arial; } form { margin:20px; } input[type="text"], input[type="password"] { width:150px; padding:3px; font-size:1em; } input[type="submit"] { padding:3px; font-size:1em; } label { display:inline-block; width:150px; } .input-container { padding:5px; } </style> </head> <body> <form...

  • How can I convert $num_rows to PDO? See errors below code ** (PHP, MySQL, HTML) $sql...

    How can I convert $num_rows to PDO? See errors below code ** (PHP, MySQL, HTML) $sql = "SELECT testN, testG from testTab";    $res = $db -> query($sql);    ** if ($res-> $num_rows >0)    {        while($row = $result-> fetch_assoc())        {            echo "". $row["testN"] ."". $row["testG"]. "";            if($row['testG'] < 60)            {            echo "". "F" ."";            }            elseif($row['testG'] >= 60 and $row['testG']<=69)            {                echo "". "D" ."";            }        }        echo "";     } else    {        echo("0 Result");           } ** Notice: Undefined variable: result...

  • For this code below, I need to add the form information to mysql when I click...

    For this code below, I need to add the form information to mysql when I click on submit, at the same time when I click on submit I need to move to another page like Welcome.php WITH NOTE THAT THE ENTERED INFORMATION NOW ALREADY IN DATABASE how can I male that with my code below? THANKS ................................................................................................................................................   <form method="POST"> <div class="container">    <label for="fname"><b>First Name</b></label> <input type="text" placeholder="Enter First Name" name="fname" required> <label for="lname"><b>Last Name</b></label> <input type="text" placeholder="Enter Last Name"...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT