Hi all,
Here's my coding issue: I have a transaction script that is supposed to insert into a sold_items and then update the products table--this works perfectly. However, I want to introduce a third query that will execute the transaction ONLY if there is an existing employee number. The problem is I keep getting the else statement: "Employee ID is invalid". For some reason, the query doesn't allow the other blocks of code to be excuted. Any insight ya'll could provide would be greatly appreciated.
<?php require ('connect.php'); //connect $connection =mysqli_connect($db_host, $db_user, $db_pass); if(!$connection){ die ("Could not connect to database: <br />".mysql_error()); } //select database $db_select = mysqli_select_db($connection, $db_database); if (!$db_select){ die ("Could not select to database: <br />". mysql_error()); } if ( isset($_POST['sellbtn']) ) { // Get values from form $emp_id =mysql_real_escape_string(htmlentities($_POST['emp_id'])); $item_id =mysql_real_escape_string(htmlentities($_POST['item_id'])); $qnty =mysql_real_escape_string(htmlentities($_POST['qnty'])); //Cancel auto commit option in the database mysqli_autocommit($connection, FALSE); //check to see if there is an existing employee $query = mysql_query("SELECT * FROM employees WHERE emp_id='$emp_id' AND comp_id='$comp_id'"); if (mysql_query($query) == TRUE) { //query to update products table--this part works when I take out the first query //query to add sold_table--this part works when I take out the first query $success = true; foreach( $results as $result) { if(!$result) { $success = false; } } if(!$success) { echo "Error. Please make sure all fields have been entered correctly."; mysqli_rollback($connection); } else { echo "Sold!"; mysqli_commit($connection); } } else echo "<center><p><font color ='red'>Employee ID is invalid.</font></p></center>"; mysqli_close($connection); } ?>