Jump to content

Problem writing to mysql database


killerofet

Recommended Posts

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

<?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{
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.