code generating error

please help this code generating error

<?php error_reporting(0); $username=$_SESSION['username']; $date = date("y-m-d"); $connect = mysql_connect("localhost","root",""); mysql_select_db("ttlogin",$connect); $result=mysql_query("SELECT username FROM users WHERE username ='".$_SESSION['username']."'"); $row = mysql_fetch_array($result); $queryreg = mysql_query("INSERT INTO initiative VALUES('$row['username']','go green','$date'"); die("you have been registered! Return"); ?>

showing error
( ! ) Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\wamp\www\html\confirm.php on line 15

Hi, you shouldn’t have double quotes for your variable just single quotes, it should look like this:

[php]
$result=mysql_query(“SELECT username FROM users WHERE username =’.$_SESSION[username]’”);
[/php]

actually sorry, there shouldn’t be a period there either:

[php]$result=mysql_query(“SELECT username FROM users WHERE username =’$_SESSION[username]’”);[/php]

hello imnaina11,
your select query is looking fine. but in you insert query you are missing “)” small closing brackets.
so replace below line
$queryreg = mysql_query(“INSERT INTO initiative VALUES(’$row[‘username’]’,‘go green’,’$date’”);
with below code

$insetsql = “INSERT INTO initiative VALUES (’$row[‘username’]’, ‘go green’, ‘$date’)”;
$queryreg = mysql_query($insetsql);

i hope this will helpful for you
SR

@ sarthak agn its showng error …
( ! ) Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\wamp\www\html\confirm.php on line 21

code:::::

confirm

<?php error_reporting(0);
     session_start();
      

     if ($_SESSION['username'])
    echo "<h1>Welcome, ".$_SESSION['username']." !</h1>";


      $username = $_SESSION['username'];
      $date = date("y-m-d");

     $connect=mysql_connect("localhost","root","");
   mysql_select_db("ttlogin", $connect);

$result=mysql_query("SELECT * FROM users WHERE username ='.$_SESSION['username'].'");

    $row=mysql_fetch_array($result)

    
    

    $queryreg = mysql_query("INSERT INTO initiative VALUES('$row['username']','go green','$date')");
     $insetsql = "INSERT INTO initiative VALUES ('$row['username']', 'go green', '$date')";
      $queryreg = mysql_query($insetsql);
      die("you have been registered! <a href='member.php'>Return</a>");

?>

hello imnaina11,
remove below line from your code.
$queryreg = mysql_query(“INSERT INTO initiative VALUES(’$row[‘username’]’,‘go green’,’$date’)”);
Actually you have did not remove your old code. so please remove that.

SR

( ! ) Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\wamp\www\html\confirm.php on line 21
This error is showing agn…

confirm

<?php error_reporting(0);
     session_start();
      

     if ($_SESSION['username'])
    echo "<h1>Welcome, ".$_SESSION['username']." !</h1>";


      $username = $_SESSION['username'];
      $date = date("y-m-d");

     $connect=mysql_connect("localhost","root","");
   mysql_select_db("ttlogin", $connect);

  $result=mysql_query("SELECT * FROM users WHERE username ='.$_SESSION['username'].'");

      $row=mysql_fetch_array($result)

    
    

   
     $insetsql = "INSERT INTO initiative VALUES('$row['username']', 'go green', '$date')";
      $queryreg = mysql_query($insetsql);
      die("you have been registered! <a href='member.php'>Return</a>");

?>

Did you try removing the single quotes from the table id (username) in your query?

exactly like so:
[php]
$result=mysql_query(“SELECT * FROM users WHERE username =’$_SESSION[username]’”);
[/php]

yup i tried agn shwng error…

) Parse error: syntax error, unexpected T_VARIABLE in C:\wamp\www\html\confirm.php on line 25

hello imnaina11,

remove below line
$result=mysql_query(“SELECT * FROM users WHERE username =’.$_SESSION[‘username’].’”);
and use below line instead of above line
$result=mysql_query(“SELECT * FROM users WHERE username =’”.$_SESSION[‘username’]."’");

SR

( ! ) Parse error: syntax error, unexpected T_VARIABLE in C:\wamp\www\html\confirm.php on line 25
still shwng error please try to help it out

confirm

<?php error_reporting(0);
     session_start();
      

     if ($_SESSION['username'])
      echo "<h1>Welcome, ".$_SESSION['username']." !</h1>";


      $username = $_SESSION['username'];
      $date = date("y-m-d");

     $connect=mysql_connect("localhost","root","");
   mysql_select_db("ttlogin", $connect);

  $result=mysql_query("SELECT * FROM users WHERE username ='".$_SESSION[username]."'");

      $row=mysql_fetch_array($result)

     $insetsql = "INSERT INTO initiative VALUES('$row[username]','','')";
      $queryreg = mysql_query($insetsql);

      die("you have been registered! <a href='member.php'>Return</a>");

?>

hello imnaina11,

remove below code
$insetsql = “INSERT INTO initiative VALUES(’$row[username]’,’’,’’)”;
$queryreg = mysql_query($insetsql);

and use below code instead of above code
$insetsql = “INSERT INTO initiative VALUES(’”.$row[username]."’,’’,’’)";
$queryreg = mysql_query($insetsql);

SR

@ sarthak
its still showing parse error

if you cn help me out please try ,

hello imnaina11,
do this
echo $insetsql = “INSERT INTO initiative VALUES(’”.$row[username]."’,’’,’’)"; exit;
show me the echo query and also directly execute this query in database.

SR

its still shwng error…

Please repost your current code. And, indicate the line you are getting the error at. Thanks…

Sponsor our Newsletter | Privacy Policy | Terms of Service