Jason Pruim schreef: > Hi Everyone, > > Happy New Year a week late! :) > > I am trying to get more serious with my programming, I feel fairly > confident in my basic abilities except for one... Error checking. That's > what I'm trying to get figured out :) > > I have a script, that I am using to connect to my database, read, > insert, delete or edit the records in there. > > most of the time the script works perfectly, but on the occassion it > doesn't like when jupiters third moon aligns with uranus, I want the > user to be notified to take their head out of their ass... :) > > What I have tried is this: > > $querytest = "INSERT INTO current VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; > if ($stmt = mysqli_prepare($link, $querytest)) { > > > mysqli_stmt_bind_param($stmt, 'ssssssssss', $FName, $LName, $Add1, > $Add2, $City, $State, $Zip, $XCode, $Record, $Reason); it's possible that the binding fails. check the return value of mysqli_stmt_bind_param() and if an error status is returned log the error and don't try to execute. > //Add the record > mysqli_stmt_execute($stmt); again check the return value of the function you called (you beginning to see a pattern here with regard to error checking? ;-) you only need to print out (or log) an error if one actually occurred. additionally if mysqli_stmt_execute() returns an error code you can output a nice userfriendly message log the cryptic mysql error message, etc somewhere. e.g. if (!mysqli_stmt_execute($stmt)) { echo "SOMETHING BAD HAPPENED!"; error_log(mysqli_stmt_errno($stmt)); } hope you get the idea. > printf("Error: %d.\n", mysqli_stmt_errno($stmt)); > printf("%d Row Inserted.\n", mysqli_stmt_affected_rows($stmt)); you might want to output the actual error message (often more useful than a number) and also output the values you we're trying to submit to the DB. lastly consider logging to a file (e.g. error_log()) and log enough so that you build up a store of error data that you can use to help you track problems that are apparently cropping up occasionally > > > } > > //Close the statement > mysqli_stmt_close($stmt); you should only close the statement if it was actually prepared okay in the first place at it's most simple: if ($stmt) mysqli_stmt_close($stmt); > > > that was pulled off of the php.net site (For the most part) and adapted > slightly to meet my needs, and obviously I edited too much of it :) > > If anyone has any ideas I would appreciate it. Even RTFM as long as $M > is defined :) > > > > -- > > Jason Pruim > Raoset Inc. > Technology Manager > MQC Specialist > 3251 132nd ave > Holland, MI, 49424 > www.raoset.com > japruim@xxxxxxxxxx > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php