Jump to content

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.

Edited by PaulRyan
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.