Is this mysqli code correct & complete-has everything needed
Posted: Tue Oct 07, 2008 11:49 am
Is the following mysqli code correct? and complete? Am I missing something? I ask because my hosting admins tell me that MySQL is good to go and therefore the code must be at fault. They tell me to talk with my developer. But I am the developer (who is rusty in PHP/MySQL since I develop at work using asp.net/MsSQL). The mysqli_affected_rows($link) reference contains the value of 1 after the update BUT the table never gets updated (in that subsequent SELECTS from either code or from PHPadmin using the same userid/password continues to show old values instead of the supposedly updated values). Below is the connection and update code:
Connection code:
UPDATE code where $fndChatStream is a string known to contain value as are the other variables known to contain values. And the record containing ID=1 does exist.
Note again that mysqli_affected_rows($link) as shown below reports 1 record updated.
The connection seems good since the following query returns results. And the userid/password again is the same as the userid/password used from PHPadmin to originally create the database and to check for changed values (such changed values never being shown but instead the old values continuing to show).
Connection code:
Code: Select all
$link = mysqli_connect('localhost', 'userid','password','Uno8s');
if (mysqli_connect_errno()) {
echo "Connect failed: " . mysqli_connect_errno() . " " . mysqli_connect_error() . "<br />";
exit();
}
Code: Select all
$MySQL = "UPDATE chatTbl set chatStream = '" . $fndChatStream . "\n" . $handle . " " . $inDate . " " . $inTime . "\n" . $inMessage . "' WHERE ID = 1";
if ($result = mysqli_query($link, $query)) {
if (mysqli_affected_rows($link) > 0) {
$numInserted_rows = 1;
}
else if (mysqli_affected_rows($link) == 0)
$numInserted_rows = 0;
else $numInserted_rows = -1;
}
else $numInserted_rows = 0;
Code: Select all
$numInserted_rows = mysqli_affected_rows($link);
Code: Select all
$query = "SELECT c.gameID, c.date, c.time, c.chatStream from chatTbl c WHERE c.gameID = " . $inGameID ;
if ($result = mysqli_query($link, $query)) {
$numChat_rows = mysqli_num_rows($result);
}
else $numChat_rows = 0;
if ($numChat_rows > 0) {
$row = mysqli_fetch_assoc($result);
$fndID = $row["ID"];
$fndGameID = $row["gameID"];
}