PHP/MySQL UPDATE not working for second table


Joined
Jan 3, 2020
Messages
1
Reaction score
0
Hello.

I have 2 tables that store the same information for different groups. When I run this for the "pilots", the query executes successfully and the record is changed. However, when the "data" variable is mentors, the query executes and throws no errors, but does not change the cells information.

In the query if, you can see all the debugging I have attempted. Both data values outpout correctly, all the values are matching what they should, but the mentor table does not update.

Any ideas are much appreciated.

Thank you!
(This is on a local server, not too worried about db details, etc. Its all different on the production side, haha)
PHP:
<?php
  $id = $_GET['id'];
  $status = $_GET['status'];
  $database = $_GET['data'];

  switch ($database) {
    case 'ip':
      $database = "pilots";
      break;
    case 'im':
      $database = "mentors";
      break;
    default:
      echo "Invalid";
      exit();
  }
  switch ($status)
  {
    case 's1':
      $status = "Email Sent";
      break;
    case 's2':
      $status = "Account Created";
      break;
    case 's3':
      $status = "Contacted";
      break;
    case 's4':
      $status = "Ready to Pair";
      break;
    case 's5':
      $status = "Active-Paired";
      break;
    case 's6':
      $status = "Inactive";
      break;
    default:
      $status = "FALSE";
      echo 'Invalid';
      exit();
  }

  if (isset($status) && $status != "FALSE")
  {
    // Create connection
    $conn = mysqli_connect("localhost", "root", "", "interestedpilots");
    // Check connection
    if (!$conn) {
        die("Connection failed: " . mysqli_connect_error());
    }

    $sql = "UPDATE $database SET status='$status' WHERE id='$id'";

    if (mysqli_query($conn, $sql)) {
      $result = mysqli_query($conn, $sql);
        /*header("Location: interestedPilots.php");*/
        echo $result ? 'good' : 'failed with ' . mysqli_error($connection);
        echo '<br>';
        echo $sql;
        echo '<br>';
        echo $database;
        echo '<br>';
        echo $status;
        echo '<br>';
        echo $id;
    } else {
        echo "Error updating record: " . mysqli_error($conn);
    }

    mysqli_close($conn);
  }
?>
(Page output)
good
UPDATE mentors SET status='Account Created' WHERE id='6'
mentors
Account Created
6
 
Ad

Advertisements

Joined
Nov 27, 2019
Messages
127
Reaction score
19
Just a thought
If status='Account Created means your ARE creating an account UPDATE is the wrong command.

Your output means nothing if we can't see all the variables. Please show these after the GET[]s, the switch ($database) and switch ($status)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top