Jump to content

What's wrong with this code?


ValkR

Recommended Posts

I had this code working, then I became curious and tried something else and it failed. I then I went to use the original code that worked but forgot it.

 

Whats wrong with this code?

<?php

        $A=(echo '2);

        if ($_POST['number'] == '1') {include $A;}

?>

Link to comment
Share on other sites

that code makes very little sense. what exactly are you trying to do? (in plain english)

 

Get basic acknowledgement that the code works.

 

And secondly, if you are using an include, you should be including a filename.

 

I see, what would I have to use?

Link to comment
Share on other sites

But the syntax is wrong and you can't include a, variable... but you can echo it.. Im guessing you want somthing more like this:

 

  <?php
    $a = '2';
    if($_POST['number']==1){echo $a;}
  ?>

 

Or if you are actualy trying to include a file, do what Kira said.

Link to comment
Share on other sites

Just out of curiosity,

 

How does

<?php
$file = 'filename.php';
if (isset($_POST['number']) && $_POST['number'] == '1')
{    
include($file);
}
?>

 

And

<?php    
$a = '2';    
if($_POST['number']==1){echo $a;}  
?>

 

do what you want?  They perform completely different actions?

 

Link to comment
Share on other sites

Our if statements are basically the same.  All I did was check that it's set, and that it equals the value you want.

 

The variables are just strings, except mine has ".php" on the end of it which usually means you're pointing it to a file.  What you name the variable really don't matter.

 

Inside the if statements are what actually makes the difference.  His echoes the variable, which prints it out, and mine includes the variable, which pulls the data from the file in the variable to the file it's included in.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.