1

The INSERT INTO does not run, and I get no error, except a notice that $re is undefined. It had previously worked, but no longer works.

 $servername = "localhost";
 $username = "id728908_njaohnt";
 $password = "pass";
 $dbname = "id728908_sub";

 // Create connection
 $conn = new mysqli($servername, $username, $password, $dbname);
 // Check connection
 if ($conn->connect_error) {
      die("Connection failed: " . $conn->connect_error);
 } 
 if (!$resu=$conn->query("SELECT confirmed FROM subscribers WHERE 
 email='".$email."'"))
 {echo $conn->error;}

 while ($row = $resu->fetch_assoc()) {
 $resul=$row['confirmed'];}
 $sql = "INSERT INTO subscribers (email) VALUES ('".$email."')";

    if ($resul==null || $resul==0)
    {
  if ($resul!=0)
{
    if ($conn->query($sql) === TRUE)
     {
 $res=$conn->query("SELECT A_I FROM subscribers WHERE email='".$email."'");
 while ($row = $res->fetch_assoc()) {
 $re=$row['A_I'];
...

$email is $email = @trim(stripslashes($_GET['email']));

njaohnt
  • 29
  • 4

1 Answers1

1

Where is $email defined? If that is user inputted then make sure it is sanitized before putting it into an SQL string.

Refactor this:

 if ($resul==null || $resul==0)
 {
     if ($resul!=0)
     {

to this:

 if ($resul==null) {

The other conditions are useless.

Is the message "$re is undefined" happening on the line "$re=$row['A_I'];"?

Matt
  • 718
  • 6
  • 20
  • re is undefined is happening on a line where $re is put into a string. "text".$re."more text" – njaohnt May 30 '17 at 23:32
  • It ended up being that if ($resul!=0) stopped going through... I'm not sure why, as it used to work, but I will definitely simplify my code before trying other things next time! – njaohnt May 30 '17 at 23:49