codingdreamer Posted August 2, 2013 Share Posted August 2, 2013 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); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/280779-transactions-works-but-query-doesnt/ Share on other sites More sharing options...
mikosiko Posted August 2, 2013 Share Posted August 2, 2013 from the manual " Return Values Returns FALSE on failure. For successful SELECT, SHOW, DESCRIBE or EXPLAIN queries mysqli_query() will return a mysqli_result object. For other successful queriesmysqli_query() will return TRUE." http://php.net/manual/en/mysqli.query.php Quote Link to comment https://forums.phpfreaks.com/topic/280779-transactions-works-but-query-doesnt/#findComment-1443266 Share on other sites More sharing options...
kicken Posted August 2, 2013 Share Posted August 2, 2013 (edited) You're mixing mysqli_* and mysql_* functions, you can't do that. Since your initial connection is mysqli, you will want to change your mysql_real_escape_string and mysql_query functions to the mysqli_ equivalents. Edited August 2, 2013 by kicken Quote Link to comment https://forums.phpfreaks.com/topic/280779-transactions-works-but-query-doesnt/#findComment-1443273 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.