Jump to content

mysql_affected_rows() usage


soycharliente

Recommended Posts

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
?>

Link to comment
https://forums.phpfreaks.com/topic/185054-mysql_affected_rows-usage/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.