Jump to content

[SOLVED] mysql query help


sax0nNZ

Recommended Posts

So I am trying to use a session variable as one of the values in my mysql query but it has spaces in it and I'm pretty sure that's what's causing the problem. So how do I get it to treat the spaces as extra characters in the value.

 

All help greatly apreciated!!!  :)

Link to comment
Share on other sites

If this code looks really stupid then I'm sorry, I'm still learning...

 

 <?php session_start(); ?>
<html>
<head><title> test </title> <link rel="stylesheet" type="text/css" href="style1.css" /> </head>
<body>
<?php 
require ('mysql_connect.php');
include('header.php');
?>
<div class='testbody'>
<?php
echo $_GET['gig'];
if (isset($_SESSION['currentgig']))
echo "You are already at a gig! <br> <a href='/battle.php'> Continue... </a>";
else
{
$_SESSION['currentgig']=$_GET['gig'];
echo $_SESSION['currentgig'];
$result = mysql_query("SELECT '$_SESSION[`currentgig`]' FROM $gigstable ") or die(mysql_error());
$_SESSION['battlegig'] = mysql_fetch_array($result);

$result2 = mysql_query("SELECT '$_SESSION[`username`]' FROM userdata");
$_SESSION['playerstats'] = mysql_fetch_array($result2);
echo "Get ready to rock out!!! <br> <a href='/battle.php'> Continue... </a>";
}
?>
</body> 
</html> 

 

The error I get is:

 

Parse error: syntax error, unexpected '`', expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/vol1/byethost32.com/b32_3527373/htdocs/gigbattle.php on line 18

Link to comment
Share on other sites

The problem is with:

 

'$_SESSION[`currentgig`]'

 

Indexes must have single or double quotes around them, not the 'grave accent'. There's a few variations you could change this to, for example:

 

'".$_SESSION['currentgig']."'

 

There's another occurrence of this a few lines down by the way.

 

Edit: Deansatch beat me too it!

 

Edited again: Didn't realise at first the value was for a table name, should be:

 

`".$_SESSION['currentgig']."`

 

I may be wrong but I don't think you can create tables with spaces?

Link to comment
Share on other sites

<?php session_start(); ?>
<html>
<head><title> test </title> <link rel="stylesheet" type="text/css" href="style1.css" /> </head>
<body>
<?php 
require ('mysql_connect.php');
include('header.php');
?>
<div class='testbody'>
<?php
echo $_GET['gig'];
if (isset($_SESSION['currentgig']))
echo "You are already at a gig! <br> <a href='/battle.php'> Continue... </a>";
else
{
$_SESSION['currentgig']=$_GET['gig'];
echo $_SESSION['currentgig'];
$result = mysql_query("SELECT `".$_SESSION['currentgig']."` FROM $gigstable ") or die(mysql_error());
$_SESSION['battlegig'] = mysql_fetch_array($result);

$result2 = mysql_query("SELECT `".$_SESSION['username']."` FROM userdata");
$_SESSION['playerstats'] = mysql_fetch_array($result2);
echo "Get ready to rock out!!! <br> <a href='/battle.php'> Continue... </a>";
}
?>
</body> 
</html> 

Link to comment
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.