Jump to content

Recommended Posts

Hi all

 

I am quite new to php and am having a little problem with sessions. when a user logs in there username becomes a session and every page checks this session this all works fine, which is great but I would like it to search the database for this username this is part of the code that i have.

 

mysql_query("UPDATE userinformation SET credits = $c

WHERE username = ". $_SESSION['username']; mysql_close($con);

 

this is the error I am getting

Parse error: syntax error, unexpected ';' in

 

sorry if i have not been clear, I hope you can help, thanks in advanced

 

yogi

Link to comment
https://forums.phpfreaks.com/topic/51554-solved-session-mysql/
Share on other sites

Hi thanks for your fast reply, ;D I thought everything was working when I got no error but then I noticed that it has stopped the calculation from working. This is all my work in progress code

 

<?
// You may copy this PHP section to the top of file which needs to access after login.
session_start(); // Use session variable on this page. This function must put on the top of page.
if(!session_is_registered("username")){ // if session variable "username" does not exist.
header("location:index.php"); // Re-direct to index.php
}

$con = mysql_connect('localhost','***','***');
if (!$con)
  {
  die('Could not connect: ' . mysql_error());

  }mysql_select_db("***", $con);

$result = mysql_query("SELECT * FROM userinformation
WHERE username='yogibear'");

while($row = mysql_fetch_array($result))

$a = $row['credits'];

$b = 5000;
$c = $a + $b;

mysql_query("UPDATE userinformation SET credits = $c WHERE username = ". $_SESSION['username']");
mysql_close($con);

?>
[code]

The code is meant to take credits and add 5000 to it and then replace the original amount of credits with the total, but it doesn’t, it does when ". $_SESSION['username']"); is replaced with 'yogibear'");

Any ideas

Thanks

[/code]

Link to comment
https://forums.phpfreaks.com/topic/51554-solved-session-mysql/#findComment-254423
Share on other sites

if this is your exact code you are missing a period after the $_session variable

 

mysql_query("UPDATE userinformation SET credits = $c WHERE username = '". $_SESSION['username']."');


 

you have ".$_SESSION['username']")

 

if that doesn't work, make sure you have your sessions set.

 

EDIT:

Also you need single quotes around the session variable before the double quotes.

Link to comment
https://forums.phpfreaks.com/topic/51554-solved-session-mysql/#findComment-254453
Share on other sites

Hi now im getting an error

Parse error: syntax error, unexpected $end in /home/sites/bf2c.co.uk/public_html/orderexhaust.php on line 27

This is all the code

 

<?
// You may copy this PHP section to the top of file which needs to access after login.
session_start(); // Use session variable on this page. This function must put on the top of page.
if(!session_is_registered("username")){ // if session variable "username" does not exist.
header("location:index.php"); // Re-direct to index.php
}

$con = mysql_connect('localhost','***','***');
if (!$con)
  {
  die('Could not connect: ' . mysql_error());

  }mysql_select_db("***", $con);

$result = mysql_query("SELECT * FROM userinformation
WHERE username='yogibear'");

while($row = mysql_fetch_array($result))

$a = $row['credits'];

$b = 5000;
$c = $a + $b;

mysql_query("UPDATE userinformation SET credits = $c WHERE username = '". $_SESSION['username']."');
mysql_close($con);
?>

 

Thanks for your help

Link to comment
https://forums.phpfreaks.com/topic/51554-solved-session-mysql/#findComment-254520
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.