Jump to content

Undefined Variable Help


WilliamNova

Recommended Posts

I know undefined variables are simple to fix, but I can't seem to get this fixed at all.

<?php 
include ("./inc/headerinc.php");

mysql_connect("localhost","root","");
mysql_select_db("mid");

$email = $_GET['email'];
$check_email = mysql_query("SELECT * FROM users WHERE email='$email'");
$count  = mysql_num_rows($check_email);
if ($count == 1) {
while ($row = mysql_fetch_assoc($check_email)) {
      $id = $row['id'];
      $firstname = $row['firstname'];
      $lastname = $row['lastname'];
      $email = $row['email'];
      $password = $row['password'];

      echo "<h2>$firstname's Profile</h2><br />
      Name: $firstname $lastname<br />
      Email: $email
      ";
}
}
?>

In line 7 'email' is undefined.

When I try using isset($_GET ['email']) the error goes away, but none of the information that's suppose to echo is displayed.

Link to comment
https://forums.phpfreaks.com/topic/281142-undefined-variable-help/
Share on other sites

$email = isset($_GET['email']) ? $_GET['email'] : FALSE ;

Then add in a check to make sure $email is not false.

if(empty($email)) {
  // The variable $_GET['email'] doesn't exist.
} else {
  // Other code.
}

You also need to escape the variable before you use it in a query, to make sure it is safe to use.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.