> I have this function that updates a page log. To my eyes, its just like
> another function I have that creates user accounts. I have added the "if
> ( $status" because its returning yes but the db is unaffected.
>
> I have four fields, date being a time stamp. So its returning $acc_state
> = 4yes every time but the db isnt showing a thing.
>
> function fn_updateAccessLog($userid, $appid, $page) {
> include ('db.php');
>
> $sql = "INSERT INTO accesslog (userid,appid,page) VALUES (";
> $sql.="'".$userid."'";
> $sql.="'".$appid."'";
> $sql.="'".$page."')";
> mysql_query($sql, $connection);
>
> $status = mysql_affected_rows($connection);
>
> mysql_close($connection);
>
> if ($status == 3) {
> $acc_state = "3yes";
> return $acc_state;
> }
> else if ($status = 4) {
> $acc_state = "4yes";
> return $acc_state;
> }
> else {
> $acc_state = "no";
> return $acc_state;
> }
> }
>From a diagnostic standpoint, you should first print the query to see if it
looks OK before letting the program write to the database. An alternative is
to change your mysql_query() statement to:
mysql_query($sql, $connection) or
die("<fieldset>$sql<br>" . mysql_error() . "</fieldset>");
If there is a problem with your SQL syntax the program will stop and display
the query and any error message from MySQL.
In this case the problem concerns the structure of your INSERT statement. The
format should be:
INSERT INTO tablename (field1, field2, field3) VALUES ('val1', 'val2', 'val3');
However, if you print your variable, I think you will find that you are missing
the commas between the values.
> $sql = "INSERT INTO accesslog (userid,appid,page) VALUES (";
> $sql.="'".$userid."'";
> $sql.="'".$appid."'";
> $sql.="'".$page."')";
James
_____
James D. Keeline
http://www.Keeline.com http://www.Keeline.com/articles
http://Stratemeyer.org http://www.Keeline.com/TSCollection
http://www.ITeachPHP.com -- Free Computer Classes: Linux, PHP, etc.
Spring Semester Begins Jan 31 -- New Classes Start Every Few Weeks.
Community email addresses:
Post message: [email protected]
Subscribe: [EMAIL PROTECTED]
Unsubscribe: [EMAIL PROTECTED]
List owner: [EMAIL PROTECTED]
Shortcut URL to this page:
http://groups.yahoo.com/group/php-list
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/php-list/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/