I'm trying to add some info to my database via a form. I've done this int he past with no issues, but for some reason I'm having a major brain fart and it stinks.
Here's my PHP:
PHP Code:
//Connect to Database
$con = mysql_connect("localhost:8888","root","root");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("toronto_****burns", $con);
Looks like you want to use mysql_affected_rows() instead of the 2nd instance of mysql_query().
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Either way. Or you could assign the results to a variable, in case you want to see if for some unexplained reason it inserts more than one row. However, note that if the result is 0, mysql_error() won't say anything, as that is not a DB error. If there were an error, it would show up by the mysql_query() failing.
PHP Code:
$sql = " INSERT INTO family ( first_name, second_name, last_name, birth_date, death_date) VALUES ( '$firstName', '$secondName', '$lastName', '$birthDate', '$deathDate' "; $addMember = mysql_query($sql, $con) or die(mysql_error()."<br />\n$sql"); if (($rows = mysql_affected_rows($addMember, $con)) == 0) { die('Error: Unknown DB error, no row added'); } else { echo "$rows record added"; }
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Crud... I have a DB error. Looks like I need to review my DB connection. I know the connectiong to my DB is ok, becasue I can display the information to my page. But for some reason I can't add info to my DB..
The information uploaded to my DB, but it still gave me an error code. I'm assuming it's something to do with how many rows are being affected, I'll have to test it out..
I'm sorry, I should have added that I...added the parenthesis at the and of the query. Even then, the info is added to my DB, but the error message is still relayed. I'm thinking I'll get rid of the error message and replace it with a congrats message, Lol.
Bookmarks