954,580 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

syntax error in my code in line 9

plz somebody help with this code . i m fed up now

<?php
$x=5;
echo $x;
session_start();
$_SESSION['y']=$x;

$string = '<?php 
session_start(); 
$x=$_SESSION['y'];
 echo $x;?> ';

$fp = fopen("6.php", "w");

fwrite($fp, $string);

fclose($fp);
?>
aaloo
Junior Poster in Training
76 posts since Oct 2011
Reputation Points: 22
Solved Threads: 0
 

Try the following:

<?php
$x=5;
session_start();
echo $x;
$_SESSION['y']=$x;

$string = '<?php 
session_start(); 
$x=$_SESSION[\'y\'];
echo $x;?> ';
$fp = fopen("6.php", "w");
fwrite($fp, $string);
fclose($fp);
?>
cwarn23
Occupation: Genius
Team Colleague
3,033 posts since Sep 2007
Reputation Points: 413
Solved Threads: 259
 

thanx man :)

aaloo
Junior Poster in Training
76 posts since Oct 2011
Reputation Points: 22
Solved Threads: 0
 

i have one more problem
this is my code

<?php
    
    session_start();
    
     
for($i=5;$i<=6;$i++)
{
$_SESSION['y']=$i;
 $string = '<?php
    session_start();
    $x=$_SESSION[\'y\'];
    echo $x;?> ';
    $fp = fopen("$i.php", "w");
    fwrite($fp, $string);
    fclose($fp);
}
    ?>

it is generating the output 6 in both newly created pages. but i want to print 5 on 5.php and 6 on 6.php .. how to do it ??

aaloo
Junior Poster in Training
76 posts since Oct 2011
Reputation Points: 22
Solved Threads: 0
 

Do you mean like the following?

<?php
session_start();
for($i=5;$i<=6;$i++)
{
$_SESSION['y']=$i;
$string = '<?php
$x='.$_SESSION['y'].';
echo $x;?> ';
$fp = fopen("$i.php", "w");
fwrite($fp, $string);
fclose($fp);
}
?>
cwarn23
Occupation: Genius
Team Colleague
3,033 posts since Sep 2007
Reputation Points: 413
Solved Threads: 259
 

thanx man .. i really appreciate u

aaloo
Junior Poster in Training
76 posts since Oct 2011
Reputation Points: 22
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: