if statement - PHP Script not executing second command -


i have script inserts 2 notifications database table it's adding first note , not second. i've tried swapping them around , still posts first of 2. here code:

<?php $type = "---"; $title = "---"; $note1 = "note 1"; $note2 = "note 2"; ?> <?php if($business1 !== ""){     $insert_note1_sql = "insert notes (id, recipient, type, title, post, message, date) values('$id', 'business 1', '$type', '$title', '$event', '$note1', '$time')";     $insert_note1_res = mysqli_query($con, $insert_note1_sql); }; ?> <?php if($business2 !== ""){     $insert_note2_sql = "insert notes (id, recipient, type, title, post, message, date) values('$id', 'business 2', '$type', '$title', '$event', '$note2', '$time')";     $insert_note2_res = mysqli_query($con, $insert_note2_sql); }; ?> 

can see why second not not posted (they both !=="")?

probably id field primary key field, , since you're using same $id in both queries insertion, you're getting duplicate key violation.

you should check return values failure, e.g.

$insert_note1_res = mysqli_query(...); if ($insert_note1_res === false) {    die(mysqli_error()); } 

Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -