soycharliente Posted December 14, 2009 Share Posted December 14, 2009 Possibly a MySQL issue, but the function that is not behaving in the anticipated way is a PHP function. Seems as though mysql_affected_rows() is not returning the desired number so I can move into my if statement. This is just a snippet. Let me know if more code might be needed to diagnose. <?php dbconnect(); $sql = "INSERT INTO `registration` (`id`, `the_date`, `first_name`, `last_name`, `email`, `phone`, `street_address`, `city`, `state`, `zip`, `emergency_contact`, `emergency_phone`, `high_school`, `test_score`, `major_interest`, `gpa`, `activity1`, `activity2`, `activity3`, `activity4`, `recruitment`, `recruitment_explain`, `travel`, `language`, `language_years`, `rotc`, `interests`, `accommodations`, `pay`) VALUES (NULL, '{$the_date}', '{$first_name}', '{$last_name}', '{$email}', '{$phone}', '{$street_address}', '{$city}', '{$state}', '{$zip}', '{$emergency_contact}', '{$emergency_phone}', '{$high_school}', '{$test_score}', '{$major_interest}', '{$gpa}', '{$activity1}', '{$activity2}', '{$activity3}', '{$activity4}', '{$recruitment}', '{$recruitment_explain}', '{$travel}', '{$language}', '{$language_years}', '{$rotc}', '{$interests}', '{$accommodations}', 'N')"; $result = mysql_query($sql) OR DIE ('//INSERT error<br />Please report this to the site admin <a href="/contact/index.php">here</a>.<br /><br />'.mysql_error()); if (mysql_affected_rows($result)==1) { //send email ?> Quote Link to comment https://forums.phpfreaks.com/topic/185054-mysql_affected_rows-usage/ Share on other sites More sharing options...
Buddski Posted December 14, 2009 Share Posted December 14, 2009 I personally dont use mysql_affected_rows for single line INSERT queries.. I use: if (mysql_query(...)) { // success } else { //failure } or in your case if ($result) { //success } else { //failure } Quote Link to comment https://forums.phpfreaks.com/topic/185054-mysql_affected_rows-usage/#findComment-976822 Share on other sites More sharing options...
soycharliente Posted December 14, 2009 Author Share Posted December 14, 2009 Works just how I wanted it to. Thanks. What could be causing the function to not return the number of rows affected with a single line query? Quote Link to comment https://forums.phpfreaks.com/topic/185054-mysql_affected_rows-usage/#findComment-976823 Share on other sites More sharing options...
PFMaBiSmAd Posted December 14, 2009 Share Posted December 14, 2009 The parameter that mysql_affected_rows() takes is a link identifier, not the value that mysql_query() returns. The value returned by a INSERT/UPDATE/DELETE query is just a TRUE (the query executed without any errors) or FALSE (the query failed to execute because of an error, like a syntax error or a problem with the database) value anyway. You can have a case (depends on the mysql server configuration or the use of the IGNORE keyword) where an INSERT query executes without error but the row will not be inserted. Quote Link to comment https://forums.phpfreaks.com/topic/185054-mysql_affected_rows-usage/#findComment-976825 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.