killerofet Posted October 16, 2008 Share Posted October 16, 2008 Hi, I'm quite new to php and have been encountering this problem for quite some time now and haven't figured a way around it. I made this script that take the user number and session id of a user and then check the database for the amount of logins this month and the session id. It thens write to the database the time you logged in, the new amount of logins this month and the session id. The problem I seem to be getting at is that it doesn't seem to be writing to the database. Any help would be appreciated. <?php if (isset($_COOKIE["session_cookie"])){ if (isset($_COOKIE["userno_cookie"])){ $SessionIDNow=$_COOKIE["session_cookie"]; $UserNumber=$_COOKIE["userno_cookie"]; $con = mysql_connect("localhost","username","password"); //stuff that doesn't need database $LSIRIDNow=$SessionIDNow; $ThisMonth=date("m") . "_20" . date("y"); $ThisMonthDate="Date" . $ThisMonth; $result = mysql_query("SELECT * FROM tabeleID WHERE UserNumber=$UserNumber"); mysql_select_db("database_name", $con); if (!$con) { die('Could not connect: ' . mysql_error()); } else { while($row = mysql_fetch_array($result)) //get from database { $TimesThisMonthOld=$row[$ThisMonth]; $DateThisMonthOld=$row[$ThisMonthDate]; $LSIROld=$row['LSIR']; } if ($LSIROld==$LSIRIDNow){ mysql_close($con); }else{ $TimesThisMonthNew=$TimesThisMonthOld + 1; //stuff that needs database $DateThisMonthNew=$DateThisMonthOld . "." . date("dHi"); mysql_select_db("xiao_forum", $con); mysql_query("UPDATE tabeleID SET $ThisMonth=$TimesThisMonthNew WHERE UserNumber=$UserNumber"); mysql_query("UPDATE tabeleID SET LSIR=$LSIRNow WHERE UserNumber=$UserNumber"); mysql_query("UPDATE tabeleID SET $ThisMonthDate=$DateThisMonthNew WHERE UserNumber=$UserNumber"); mysql_close($con); } } } }else{ } ?> Link to comment https://forums.phpfreaks.com/topic/128662-problem-writing-to-mysql-database/ Share on other sites More sharing options...
redarrow Posted October 16, 2008 Share Posted October 16, 2008 or die (mysql_error()): <<<<<<<<<add to querys... Link to comment https://forums.phpfreaks.com/topic/128662-problem-writing-to-mysql-database/#findComment-666827 Share on other sites More sharing options...
redarrow Posted October 16, 2008 Share Posted October 16, 2008 look at ur update ' <<<<<<,, missing single hi='$quotes' Link to comment https://forums.phpfreaks.com/topic/128662-problem-writing-to-mysql-database/#findComment-666828 Share on other sites More sharing options...
redarrow Posted October 16, 2008 Share Posted October 16, 2008 <?php if (isset($_COOKIE["session_cookie"])){ if (isset($_COOKIE["userno_cookie"])){ $SessionIDNow=$_COOKIE["session_cookie"]; $UserNumber=$_COOKIE["userno_cookie"]; $con = mysql_connect("localhost","username","password"); //stuff that doesn't need database $LSIRIDNow=$SessionIDNow; $ThisMonth=date("m") . "_20" . date("y"); $ThisMonthDate="Date" . $ThisMonth; $result = mysql_query("SELECT * FROM tabeleID WHERE UserNumber='$UserNumber'"); mysql_select_db("database_name", $con); if (!$con) { die('Could not connect: ' . mysql_error()); } else { while($row = mysql_fetch_array($result)) //get from database { $TimesThisMonthOld=$row[$ThisMonth]; $DateThisMonthOld=$row[$ThisMonthDate]; $LSIROld=$row['LSIR']; } if ($LSIROld==$LSIRIDNow){ mysql_close($con); }else{ $TimesThisMonthNew=$TimesThisMonthOld + 1; //stuff that needs database $DateThisMonthNew=$DateThisMonthOld . "." . date("dHi"); mysql_select_db("xiao_forum", $con); mysql_query("UPDATE tabeleID SET ThisMonth='$TimesThisMonthNew' WHERE UserNumber='$UserNumber'")or die(mysql_error()); mysql_query("UPDATE tabeleID SET LSIR='$LSIRNow' WHERE UserNumber='$UserNumber'")or die (mysql_eror()); mysql_query("UPDATE tabeleID SET ThisMonthDate='$DateThisMonthNew' WHERE UserNumber='$UserNumber'")or die(mysql_error()); mysql_close($con); } } } }else{ } ?> Link to comment https://forums.phpfreaks.com/topic/128662-problem-writing-to-mysql-database/#findComment-666829 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.