4 replies
I wanted to fetch result from mysql database with the table name set to a session variable but it not working, here is the error message."You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '
' at line 1"


<?php
session_start();
$subject1=$_SESSION['subject1']='mathematics';

function getsubject1(){ global $subject1;

$questions=mysql_query("select * from $subject1 ") or die(mysql_error());
while($quest=mysql_fetch_array($question)){
echo $quest['question']; } }


?>
#php #variable
  • Profile picture of the author christogonus
    See the correction I found out in your code:
    In the function you declaied, I see that you created a variable $questions
    but what you assigned to the variable $quest is $question (you did not add the ending "s" in subjects)

    Then ensure that there is a column is the database known as "question"

    <?php
    session_start();
    $subject1=$_SESSION['subject1']='mathematics';

    function getsubject1(){ global $subject1;

    $questions=mysql_query("select * from $subject1 ") or die(mysql_error());
    while($quest=mysql_fetch_array($questions)){
    echo $quest['question']; } }


    ?>



    et me know if it works this time.
    Signature
    I am a developer and can support on WHMCS, Cpanel, VPS, SSL and more. Add Me On Skype: christogonus2

    >> I offer WHMCS Setup, Updates & Technical Support <<
    {{ DiscussionBoard.errors[8992367].message }}
  • Profile picture of the author KirkMcD
    At what point are you calling the function getsubject1?
    {{ DiscussionBoard.errors[8994104].message }}
    • Profile picture of the author heroecitadel
      Thanks guys, i have fixed the bug. I didn't pass the SESSION variable from the previous page, that was the problem. Thanks
      {{ DiscussionBoard.errors[8995035].message }}
  • Profile picture of the author christogonus
    Good you found the solution.
    Signature
    I am a developer and can support on WHMCS, Cpanel, VPS, SSL and more. Add Me On Skype: christogonus2

    >> I offer WHMCS Setup, Updates & Technical Support <<
    {{ DiscussionBoard.errors[9007667].message }}

Trending Topics