Implementing (If) statement to generate code?

Discussion in 'PHP' started by scottlpool2003, Apr 29, 2007.

  1. #1
    Hi, i'm new to the IF statement and I can't find help anywhere. I've tried posting in here for some help but I can't seem to post in the right category. I would like to use the IF statement to only show generated code when a user clicks submit.

    The form I use is <form action="#"> so it reloads in the same page but at present the code is already there, so after doing some research I found out that I need to implement the IF statement.

    Please somebody help me?

    Scott.
     
    scottlpool2003, Apr 29, 2007 IP
  2. gamerfreak

    gamerfreak Well-Known Member

    Messages:
    250
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    110
    #2
    What language?
     
    gamerfreak, Apr 29, 2007 IP
  3. scottlpool2003

    scottlpool2003 Well-Known Member

    Messages:
    1,708
    Likes Received:
    49
    Best Answers:
    9
    Trophy Points:
    150
    #3
    I'm going to sound like a NOOB now. English?
     
    scottlpool2003, Apr 29, 2007 IP
  4. commandos

    commandos Notable Member

    Messages:
    3,648
    Likes Received:
    329
    Best Answers:
    0
    Trophy Points:
    280
    #4
    :D

    He meant what programming language ?

    JAVASCRIPT , php , asp , c# ,c++ , c , ruby , jsp , etc ...
     
    commandos, Apr 29, 2007 IP
  5. scottlpool2003

    scottlpool2003 Well-Known Member

    Messages:
    1,708
    Likes Received:
    49
    Best Answers:
    9
    Trophy Points:
    150
    #5
    Thought so! I have better knowledge of php then the rest but javascript or php would work better I think. I hope you all understand what I mean because I don't think I explained it properly.

    Take a look at:
    http://www.myspace4yourpage.com/Generators/whore-me.html

    You see the way the code is already there?

    I want to have it so the code only displays when there is actually code to generate.

    The pages are all in php but I use a rewrite rule to change them. :) I really hope someone can help because it's been bugging me for a while.

    Thanks guys!
     
    scottlpool2003, Apr 29, 2007 IP
  6. manilodisan

    manilodisan Peon

    Messages:
    224
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Change your form to:
    <form action="<?=$_SERVER["php_self"]?>" method="post">

    <?php
    
    if($_POST['name']!='')
    {
           $code = '<table border="0" class="content" align="center" width="70%" style="border:2px solid black"><tr>
    
    </tr>
    <tr>
    <td bgcolor="beige" align="center">
    <table border="0" class="content">
    <td><a href="http://www.myspace4yourpage.com/add_"><img src="" height="100" width="150"></a></td><tr>
    <td>Name:<font color="beige">'.$_POST['name'].'</font></td><tr>
    <font size="5"></font>
    </table>
    <table>
    <td><a href="http://www.myspace4yourpage.com/add_"><img src="http://www.myspace4yourpage.com/images/addicon.gif" border="0"></a></td><td><a href="http://messaging.myspace.com/index.cfm?fuseaction=mail.message&friendID="> <img src="http://www.myspace4yourpage.com/images/messageicon.gif" border="0"></a></td>
    </table>
    <br><br><br>
    <a href="http://www.myspace4yourpage.com/add_39723601">Add This Too!</a>
    <br><br>
    
    </form><br><a href="http://www.myspace4yourpage.com">Myspace Content</a></center></form></style>
    
    
    </table></table>
    ';//etc etc
    }
    ?>
    PHP:
    <textarea><?=$code;?></textarea>



    It's a spartan code but I hope you get the idea...
     
    manilodisan, Apr 29, 2007 IP
  7. scottlpool2003

    scottlpool2003 Well-Known Member

    Messages:
    1,708
    Likes Received:
    49
    Best Answers:
    9
    Trophy Points:
    150
    #7
    Hi, thanks a lot for the help... Still having a slight glitch. Here is how I have laid the code out:

    
    <form action="<?=$_SERVER["php_self"]?>" method="post">
    <?php
    
    if($_POST['name']!='')
    {
           $code = '<table border="0" class="content" align="center" width="70%" style="border:2px solid black"><tr>
    
    </tr>
    <tr>
    <td bgcolor="beige" align="center">
    <table border="0" class="content">
    <td><a href="http://www.myspace4yourpage.com/add_"><img src="" height="100" width="150"></a></td><tr>
    <td>Name:<font color="beige">'.$_POST['name'].'</font></td><tr>
    <font size="5"></font>
    </table>
    <table>
    <td><a href="http://www.myspace4yourpage.com/add_"><img src="http://www.myspace4yourpage.com/images/addicon.gif" border="0"></a></td><td><a href="http://messaging.myspace.com/index.cfm?fuseaction=mail.message&friendID="> <img src="http://www.myspace4yourpage.com/images/messageicon.gif" border="0"></a></td>
    </table>
    <br><br><br>
    <a href="http://www.myspace4yourpage.com/add_39723601">Add This Too!</a>
    <br><br>
    
    </form><br><a href="http://www.myspace4yourpage.com">Myspace Content</a></center></form></style>
    
    
    </table></table>
    ';//etc etc
    }
    ?>
    <table border="0" class="content" align="center" width="70%" style="border:2px solid black"><tr>
    <td bgcolor="3399FF" align="center"><b>The Work Area</b></td>
    </tr>
    <tr>
    <td bgcolor="beige" align="center">
    
    <table border="0" class="content">
    
    <tr><td>Your Name:<br>
    <input type="text" name="name" class="form"></td>
    <td>
    Text:<br>
    <input type="text" name="subtext" class="form" value="Add Me!"></td></tr>
    <tr><td>
    Picture URL:<br>
    <input type="text" name="pictureurl" class="form"></td>
    
    <td>FriendID:<br>
    <input type="text" name="friendid" class="form"></td></tr>
    <tr><td>
    
    <br /><input type="submit" value="Generate" class="form"><br /><br /><br><br><tr><tr>	
    <table border="0" class="content" align="center" width="50%" style="border:2px solid black"><tr>
    <td bgcolor="#3399FF" align="center" style="border:1px solid lightblue"><b>Your Code</b></td>
    </tr>
    <tr>
    <td bgcolor="beige" align="center">
    
    <table border="0" class="content"><tr>
    <td>
    <center><textarea><?=$code;?></textarea></table></table>
    
    Code (markup):
    If you have a look:

    http://www.myspace4yourpage.com/Generators/whore-me.html

    The generated code doesn't change from:

    
    
    <?php
    
    if($_POST['name']!='')
    {
           $code = '<table border="0" class="content" align="center" width="70%" style="border:2px solid black"><tr>
    
    </tr>
    <tr>
    <td bgcolor="beige" align="center">
    <table border="0" class="content">
    <td><a href="http://www.myspace4yourpage.com/add_"><img src="" height="100" width="150"></a></td><tr>
    <td>Name:<font color="beige">'.$_POST['name'].'</font></td><tr>
    <font size="5"></font>
    </table>
    <table>
    <td><a href="http://www.myspace4yourpage.com/add_"><img src="http://www.myspace4yourpage.com/images/addicon.gif" border="0"></a></td><td><a href="http://messaging.myspace.com/index.cfm?fuseaction=mail.message&friendID="> <img src="http://www.myspace4yourpage.com/images/messageicon.gif" border="0"></a></td>
    </table>
    <br><br><br>
    <a href="http://www.myspace4yourpage.com/add_39723601">Add This Too!</a>
    <br><br>
    
    </form><br><a href="http://www.myspace4yourpage.com">Myspace Content</a></center></form></style>
    
    
    </table></table>
    ';//etc etc
    }
    ?>
    
    Code (markup):
    Thanks,
    Scott.
     
    scottlpool2003, Apr 30, 2007 IP
  8. scottlpool2003

    scottlpool2003 Well-Known Member

    Messages:
    1,708
    Likes Received:
    49
    Best Answers:
    9
    Trophy Points:
    150
    #8
    Problem solved everyone. Thanks Manilodason I really appreciate it!
     
    scottlpool2003, Apr 30, 2007 IP
  9. dp-user-1

    dp-user-1 Well-Known Member

    Messages:
    794
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    110
    #9
    On my site (on the weblog), I made a setting that if trun=1, to trim the blog at 5 posts. Then I used GET to have PHP look at the URL and decide what to do.
     
    dp-user-1, Apr 30, 2007 IP
  10. scottlpool2003

    scottlpool2003 Well-Known Member

    Messages:
    1,708
    Likes Received:
    49
    Best Answers:
    9
    Trophy Points:
    150
    #10
    NinjaNoodles, that sounds good! All i wanted it to do was just display the html code after a user clicks generate. The code that Manilodason gave me worked just enough for me to work out what to do. Take a look here:
    http://myspace4yourpage.com/Generators/whore-me.html

    Then take a look:

    http://myspace4yourpage.com/Generators/makebg.html

    I just didn't want any users getting confused thinking the code is already there when it isn't. It works fine now and i'm about to add the if statement to all my generators. Thanks again everyone this was an issue that fiddled me for ages.

    I love learning! :)
     
    scottlpool2003, Apr 30, 2007 IP
  11. manilodisan

    manilodisan Peon

    Messages:
    224
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Glad you made it workin'
     
    manilodisan, Apr 30, 2007 IP