Jump to content

[SOLVED] mysql query help


sax0nNZ

Recommended Posts

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

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?

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

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.