-1

I'm getting parse error in my code.

My code is:

$query="INSERT into tbl_result('result_uname','result_date','result_subject','result_rightans','result_wrongans','result_marks') values ('$uname','$curdate','$subject','10','10','$_SESSION['marks']')";
  if(mysql_query($query))
  {
    header("Location: result.php");
    ?>
    <script>alert("Your Answers Submitted...");</script>
    <?php
  }
  else
  {
    ?>
      <script>alert('Error While Submitting...');</script>
    <?php
  }
Panda
  • 6,955
  • 6
  • 40
  • 55
  • 1
    **WARNING**: If you're just learning PHP, please, do not use the [`mysql_query`](http://php.net/manual/en/function.mysql-query.php) interface. It’s so awful and dangerous that it was removed in PHP 7. A replacement like [PDO is not hard to learn](http://net.tutsplus.com/tutorials/php/why-you-should-be-using-phps-pdo-for-database-access/) and a guide like [PHP The Right Way](http://www.phptherightway.com/) explains best practices. Your user parameters are **not** [properly escaped](http://bobby-tables.com/php) and there are [SQL injection bugs](http://bobby-tables.com/) that can be exploited. – tadman May 01 '16 at 03:19

1 Answers1

0

This bit:

'$_SESSION['marks']'

uses single quotes inside single quotes. That won't work, and the whole thing is inside double quotes already. You'll have to use string concatenation. Or, assign $_SESSION['marks'] to a variable and use that in your query like you already do with $uname, $curdate, etc.

Dave Ross
  • 3,313
  • 1
  • 24
  • 21