1

I have an if statement. If a condition is true the query is an INSERT query, else it is an UPDATE query. If i am updating the row, it works fine. But the insert part doesn't. And it is being submitted and not returning errors so I have no clue what the error is. I have looked over it a thousand times.

The insert query

$query = "INSERT INTO exhibitions (code, name, description,
                                    notes, status, image, slug, start_date, end_date)
      VALUES (?,?,?,?,?,?,?,?,?)";
      $stmt = $connection->prepare($query);
      $stmt->bind_param('sssssssss', $code, $new_name, $new_description, $new_notes, $new_status,
                                       $new_image, $new_slug, $new_startDate, $new_endDate);

Where the statement is executed

if($stmt->execute()) {
      $stmt->close();
      updateActivityWithDetails($_SESSION['userCode'], $activityId, $code, $name, $connection);
      //header("Location:/view-exhibitions/");
      $_SESSION['form-alert'] = '
        <div class="alert alert-success">
          <i class="fa fa-check-circle"></i> '.$activityDesc.'
        </div>';

      if($_POST['action'] == 'edit' || $_POST['action'] == 'save'){
        //header('Location: /'.$productfolder.'/view-exhibitions/'.$code);
      }else{

      }
    }
    else {
      $_SESSION['form-alert'] = '
        <div class="alert alert-danger">
          <i class="fa fa-check-circle"></i><strong> System Warning </strong>
          There was a serious error with the system. You request could not be processed. If the problem persists, please contact the '.$systemName.' Support Team
        </div>
      ';
    }
TiernO
  • 427
  • 6
  • 20
  • Does this answer your question? [mysqli\_fetch\_assoc() expects parameter / Call to a member function bind\_param() errors. How to get the actual mysql error and fix it?](https://stackoverflow.com/questions/22662488/mysqli-fetch-assoc-expects-parameter-call-to-a-member-function-bind-param) – Dharman Aug 10 '20 at 10:42
  • @Dharman Unfortunately not, I have strict error reporting on. – TiernO Aug 10 '20 at 11:11
  • What is the error you are facing then? When you say it doesn't work we can't guess what might be wrong. What debugging have you done? Which line of code is executed and which isn't? – Dharman Aug 10 '20 at 11:13
  • When I press a button to submit an insert form. It gets submitted and redirects me as it should. No error. Everything seems like it worked fine. But the data hasn't gone into the database. I have tried checking table names, column names, variable names. I have even commented out the lines that redirect after submitting, but it still refreshes the page after i press submit – TiernO Aug 10 '20 at 11:18
  • Does it reach as far as `prepare`? Does it reach `bind_param`? Does it reach `execute`? – Dharman Aug 10 '20 at 11:20
  • How can I tell? It must do so if the page refreshes – TiernO Aug 10 '20 at 11:27
  • @TiernO add different `echo`s to the parts of the code you want to check they are actually reached (and comment the redirection so you can see the result) – Kaddath Aug 10 '20 at 12:34

0 Answers0