0

Can someone tell me why I am unable to update a table in mysql using php with session data.

First of all, I have done some reading around daniweb and Im not sure if i should be using UPDATE or INSERT to update the table.

I have session_start(); at the top of my page and I have echo'd out the session data as below, so I know the data is correct.

<?php echo $_SESSION['SESS_IMG1'];?><br>	
<?php echo $_SESSION['SESS_COUNTRY'];?><br>
<?php echo $_SESSION['SESS_CITY'];?><br>

Im trying to update a mysql table every time a page loads with the session data.

at first I tried the following using the session data

$sql = "INSERT INTO viewed id='', uid='$urlid', usecurecode='".$_SESSION['SESS_SECURE_CODE']."', ulogin='".$_SESSION['SESS_LOGIN']."', uimg='".$_SESSION['SESS_IMG1']."', ucountry='".$_SESSION['SESS_COUNTRY']."', ucity='".$_SESSION['SESS_CITY']."', uage='".$_SESSION['SESS_AGE']."', vdate='now()'";       
$result = mysql_query($sql) or die(mysql_error());      

echo "Thank you! Information updated.";

I then tried using the session variables

mysql_query("INSERT INTO viewed (uid,usecurecode,ulogin,uimg,ucountry,ucity,uage,vdate)
VALUES ('$urlid','$_SESSION[$securecode]', '$_SESSION[$login]', '$_SESSION[$img1]', '$_SESSION[$country]', '$_SESSION[$city]', '$_SESSION[$age], 'now()')")

	or die("couldn't add new user");

and I have also tried

$sql = "UPDATE viewed SET uid='$urlid', usecurecode='".$_SESSION['SESS_SECURE_CODE']."', ulogin='".$_SESSION['SESS_LOGIN']."', uimg='".$_SESSION['SESS_IMG1']."', ucountry='".$_SESSION['SESS_COUNTRY']."', ucity='".$_SESSION['SESS_CITY']."', uage='".$_SESSION['SESS_AGE']."', vdate='now()'";
       
$result = mysql_query($sql) or die(mysql_error());      

echo "Thank you! Information updated.";

With trying the above three, I am still unable to update the table viewed with the session data, and im a bit stuck now as how i update

1
Contributor
1
Reply
7
Views
7 Years
Discussion Span
Last Post by LloydFarrell
0

Ahhaaaaaa..... I now have this working, after some more digging around on daniweb, and mixing some examples i found with what I wanted to do,

Here is the working version of the above three failed attempts

<?php
	require_once('../config.php');
	require_once('../auth.php');
	
$urlid = $_GET['id'];

mysql_query("INSERT INTO viewed (uid,usecurecode,ulogin,uimg,ucountry,ucity,uage,vdate) VALUES ('$urlid','".$_SESSION['SESS_SECURE_CODE']."','".$_SESSION['SESS_LOGIN']."','".$_SESSION['SESS_IMG1']."', '".$_SESSION['SESS_COUNTRY']."', '".$_SESSION['SESS_CITY']."', '".$_SESSION['SESS_AGE']."', now())") 

	OR die("Could not update: <br>".mysql_error());
mysql_close();
?>

The database is now updating with session data,
Many thanks to those who have posted,

SEEK & HE SHALL FIND

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.