ValkR Posted August 23, 2011 Share Posted August 23, 2011 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;} ?> Quote Link to comment Share on other sites More sharing options...
WebStyles Posted August 23, 2011 Share Posted August 23, 2011 that code makes very little sense. what exactly are you trying to do? (in plain english) Quote Link to comment Share on other sites More sharing options...
Nodral Posted August 23, 2011 Share Posted August 23, 2011 At first glance you have a missing single quote when you define $A And secondly, if you are using an include, you should be including a filename. include('foo.php'); Quote Link to comment Share on other sites More sharing options...
ValkR Posted August 23, 2011 Author Share Posted August 23, 2011 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? Quote Link to comment Share on other sites More sharing options...
codefossa Posted August 23, 2011 Share Posted August 23, 2011 Here's an example: <?php $file = 'filename.php'; if (isset($_POST['number']) && $_POST['number'] == '1') { include($file); } ?> Quote Link to comment Share on other sites More sharing options...
Nodral Posted August 23, 2011 Share Posted August 23, 2011 http://php.net/manual/en/function.include.php Quote Link to comment Share on other sites More sharing options...
Zephni Posted August 23, 2011 Share Posted August 23, 2011 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. Quote Link to comment Share on other sites More sharing options...
ValkR Posted August 23, 2011 Author Share Posted August 23, 2011 Thank you all very much for your help. I tried all codes provided and they all do the thing I need. I'm very new to PHP so thanks for your support! Quote Link to comment Share on other sites More sharing options...
Nodral Posted August 23, 2011 Share Posted August 23, 2011 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? Quote Link to comment Share on other sites More sharing options...
codefossa Posted August 23, 2011 Share Posted August 23, 2011 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. Quote Link to comment Share on other sites More sharing options...
WebStyles Posted August 23, 2011 Share Posted August 23, 2011 going back to my original question: (sheer curiosity now that it's 'solved' in many different ways) what exactly were you trying to do ? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.