Variable Problem (More Questions...)

PichuSecretBase

Web Site Critique
  • 2,775
    Posts
    21
    Years
    Well me and my friend could not seem to figure it out. I am using the fwrite commands so I need to put some variables into a table and make that a variable. But I cant get the other variables to show up in one.

    PHP:
    $variable = "<?php echo "$var";?> <br/> <?php echo "$var"; <br/>";

    Help Kip-Kip or other smart people lol!
     
    Code:
     $variable = "<?php echo "$var";?> <br/> <?php echo "$var";?> <br/>";
    you forgot thr second ?>
     
    ...shouldn't you be defining the variable in php anyways?

    PHP:
    <? $variable = "echo $var <br /> $var"; ?>


    Not sure if that'd work, I'm not a PHP guru.

    But I know this:
    ~ Variables should be done in the <? code - therefore, you really shouldn't need the ones in the middle
    ~ For " in ", you need to make them ' (otherwise it reads the second " as the ending - that was confusing X_x)
     
    PHP:
    $variable = 'echo $var; <br /> echo $var;<br />';
    Try that.
    What you did wrong is that you used " to open and close $variable. Then you used " to echo the variable. That would close $variable and give you an unexpected something error. You don't need to use " to echo a variable, but you need to with text. Also, you don't use the <?php and ?> tags for the echo function since they're already in php tags.
     
    PHP:
    <?php 
    $user = $_POST["user"];
    $place = $_POST["place"];
    $money = $_POST["money"];
    $avatar = $_POST["avatar"];
    $action = $_POST["action"]; ?>
    <?
    $html = 'Test';
    ?>

    when I Fwrite it it shows up as echo $user; >.>;;
     
    PHP:
    $variable = "$var\n$var";
    /or/
    PHP:
    $variable = "$var"."\n"."$var";

    Some people find the alternate way easier to read.

    I'm not sure of the context of your code. It looks like everyone is presenting <br /> tags instead of the preprocessed \n escape character. You woudn't use single quotes, either, our you'll get the literal value of the text between them rather than the variable values. If you posted the whole code -- and least the pertinent parts -- I could see how you want it to behave. Otherwise, it's hit and miss helping you.
     
    PHP:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <?php include "config.php" ?>
    <html>
    <head>
    <title><?php echo "$title" ?>-Powered by H-91cms</title>
    <link rel="stylesheet" type="text/css" href="style.css" />
    </head>
    <body>
    <div align="Center">
    <?php include "head.php" ?>
    <?php 
    $user = $_POST["user"];
    $place = $_POST["place"];
    $money = $_POST["money"];
    $avatar = $_POST["avatar"];
    $action = $_POST["action"]; ?>
    <?
     $html = "<table class="table"><td><td class="nav" colspan="2">"."$user"."</td></tr><tr><td class="nav" width="100">"."$avatar"."\n"."$place"."\n"."$money"."\n"."</td><td width="250">"."$user"."\n".
    "$action"."</td></tr></table>"; 
    ?>
    
    <?php
    
    $contents = $html;
    
    $filename = "rpg.txt";
    
    
    
    $file = file_get_contents($filename);
    
    
    $fs = fopen($filename, "w+");
    
    fwrite($fs, $contents.$file);
    
    fclose($fs);
    
    
    
    echo "Thank for posting ";
    echo " $user <br/> ";
    echo "$contents";
    
    
    ?>
    <?php include "foot.php" ?>
    </div>
    </body>
    </html>

    It's STILL not wokring ><!!
     
    Hmm... Try this:
    PHP:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <?php include "config.php"; ?>
    <title><?php echo "$title" ?>-Powered by H-91cms</title>
    <link rel="stylesheet" type="text/css" href="style.css" />
    </head>
    <body>
    <div align="Center">
    <?php include "head.php";
    $user = $_POST["user"];
    $place = $_POST["place"];
    $money = $_POST["money"];
    $avatar = $_POST["avatar"];
    $action = $_POST["action"];
    $html = '<table class="table"><td><td class="nav" colspan="2">'."$user".'</td></tr><tr><td class="nav" width="100">'."$avatar"."\n"."$place"."\n"."$money"."\n".'</td><td width="250">'."$user"."\n"."$action".'</td></tr></table>';
    
    $contents = $html;
    
    $filename = "rpg.txt"; 
    ?>
    It should work. I came up with no errors when I tried it. Of course, I didn't have the config.php or head.php, but I don't think you're having problems with that.
     
    Back
    Top