SitePoint Sponsor

User Tag List

Results 1 to 25 of 25

Thread: if and echo

  1. #1
    SitePoint Addict caddyfixr's Avatar
    Join Date
    Aug 2004
    Location
    Albuquerque, NM
    Posts
    249
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    if and echo

    Hello,

    I am trying to install an upgrade and I can't seem to get this bit of code to write to the data base.
    PHP Code:
    <?php if ($premium == "yes") echo ("<textarea  name='games' cols='50' rows='10'><?=$games?></textarea>");?>
    if I remove the qualifier, it writes just fine.
    PHP Code:
    <textarea  name='games' cols='50' rows='10'><?=$games?></textarea>
    What am I doing wrong?
    Thanks
    Steve
    Last edited by caddyfixr; Jan 24, 2005 at 22:01.

  2. #2
    Non-Member coo_t2's Avatar
    Join Date
    Feb 2003
    Location
    Dog Street
    Posts
    1,819
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Where is $premium coming from? Does it actually equal "yes"?

    Try doing this and see what it says:

    PHP Code:
     <pre>
     <?php var_dump('var_dump($premium) = '$premium); ?>
     </pre>
    --ed

  3. #3
    SitePoint Addict caddyfixr's Avatar
    Join Date
    Aug 2004
    Location
    Albuquerque, NM
    Posts
    249
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes premium works and in this instance the value for premium is "yes" I use premium for other tasks like displaying icons and such. The problem is not that it won't display, rather that it will not write to the database in the above format.

    Thanks

  4. #4
    Non-Member coo_t2's Avatar
    Join Date
    Feb 2003
    Location
    Dog Street
    Posts
    1,819
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    You mean you're actually trying store the code in the database?
    If that's the the case then use mysql_real_escape_string
    to escape the string.

    --ed

  5. #5
    SitePoint Addict caddyfixr's Avatar
    Join Date
    Aug 2004
    Location
    Albuquerque, NM
    Posts
    249
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No, I mean I am trying to edit the contents of the text box just like we are doing when we post in this forum.

    If the member is a Premium Member he sees the text box and is allowwed to edit it's contents.

    Else the member is not Premium and can not see the text box.

    Thanks
    Steve

  6. #6
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    At My Desk!!
    Posts
    1,642
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    just something i saw there is no { and } brackets around the if satement surely that will stop it from working!!!
    Try this:
    PHP Code:
    <?php if ($premium == "yes")
    {
     echo (
    "<textarea  name='games' cols='50' rows='10'><?=$games?></textarea>");
    }
    ?>
    "Am I the only one doing ASP.NET in Delphi(Pascal)?"

  7. #7
    SitePoint Addict caddyfixr's Avatar
    Join Date
    Aug 2004
    Location
    Albuquerque, NM
    Posts
    249
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The curly brakets had no effect. acted the same with or without

    Thanks

  8. #8
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    At My Desk!!
    Posts
    1,642
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try this :

    PHP Code:
    <?php if ($premium == TRUE)
    {
    echo (
    "<textarea  name='games' cols='50' rows='10'><?=$games?></textarea>");
    }
    ?>
    "Am I the only one doing ASP.NET in Delphi(Pascal)?"

  9. #9
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    At My Desk!!
    Posts
    1,642
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ive just seen something else that "might" be a problem, try it like this:

    PHP Code:
    <?php if ($premium == TRUE)
    {
    ?>
    <textarea  name="games" cols="50" rows="10"><? echo $games ?></textarea>
    <?
    }
    ?>
    So we end php so the html can, this is really no different from your code just a bit easier (i find) and also you were starting and ending php around the $game when there was no need as it was already started. Try this code, there shouldnt beany reason why i wont work
    "Am I the only one doing ASP.NET in Delphi(Pascal)?"

  10. #10
    SitePoint Addict caddyfixr's Avatar
    Join Date
    Aug 2004
    Location
    Albuquerque, NM
    Posts
    249
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Rats, TRUE acts the same as "yes"

  11. #11
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    At My Desk!!
    Posts
    1,642
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thought it might, but try the other lot of code i sent
    "Am I the only one doing ASP.NET in Delphi(Pascal)?"

  12. #12
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    At My Desk!!
    Posts
    1,642
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i have just tested my latest code i gave you and it works
    "Am I the only one doing ASP.NET in Delphi(Pascal)?"

  13. #13
    SitePoint Addict caddyfixr's Avatar
    Join Date
    Aug 2004
    Location
    Albuquerque, NM
    Posts
    249
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well drat, all of the variations act the same. They display what is on the database but will not edit the database.

    Steve

  14. #14
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    At My Desk!!
    Posts
    1,642
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    can u post all your code so that we can look, maybe something else is wrong because i have tried the code i gave you and it works fine. So post your entire php code and we'll probably be able to help
    "Am I the only one doing ASP.NET in Delphi(Pascal)?"

  15. #15
    SitePoint Addict caddyfixr's Avatar
    Join Date
    Aug 2004
    Location
    Albuquerque, NM
    Posts
    249
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oh my god! ok here it comes.

    PHP Code:
    <?php include 'access/membercontrol.php';?>
    <!-- editcontact.php -->
    <!DOCTYPE html PUBLIC "-//W3C/DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">

    <head>
    <title>Update Contact Info</title>
    <script type="text/javascript"> 
     var newWindow = null; 
      
     function closeWin(){ 
     if (newWindow != null){ 
     if(!newWindow.closed) 
     newWindow.close(); 
     } 
     } 
      
     function popUpWin(url, type, strWidth, strHeight){ 
      
     closeWin(); 
      
     if (type == "fullScreen"){ 
      
     strWidth = screen.availWidth - 10; 
     strHeight = screen.availHeight - 160; 
     } 
      
     var tools=""; 
     if (type == "standard" || type == "fullScreen") tools = "resizable,toolbar=yes,location=yes,scrollbars=yes,menubar=yes,width="+strWidth+",height="+strHeight+",top=0,left=0"; 
    if (type == "console") tools = "resizable,toolbar=no,location=no,scrollbars=no,width="+strWidth+",height="+strHeight+",left=0,top=0"; 
     newWindow = window.open(url, 'newWin', tools); 
     newWindow.focus(); 
     } 
     </script> 
    </head>
    <body alink="#0033FF"  link="#0033FF" vlink="#0033FF">

    <?php


    if (isset($_POST['submit'])): 
      
    // The team's details have 
      // been updated. 
     
      
    $id $_GET['id']; 
      
    $teamname $_POST['teamname']; 
      
    $id $_POST['id'];
      
    $password $_POST['password']; 
      
    $teamcity $_POST['teamcity'];
      
    $cteamstate $_POST['teamstate'];
      
    $division $_POST['division'];
      
    $manager $_POST['manager'];
      
    $mphone $_POST['mphone'];
      
    $mfax $_POST['mfax'];
      
    $memail $_POST['memail'];
      
    $coach $_POST['coach'];
      
    $cphone $_POST['cphone'];
      
    $cfax $_POST['cfax'];
      
    $cemail $_POST['cemail'];
      
    $webpage $_POST['webpage'];
      
    $games $_POST['games'];
      
    $players $_POST['players'];
       

    $sql "UPDATE contacts SET 
              teamname='
    $teamname', 
              password='
    $password', 
              teamcity='
    $teamcity',
              teamstate='
    $teamstate',
              division='
    $division',
              manager='
    $manager',
              mphone='
    $mphone',
              mfax='
    $mfax',
              memail='
    $memail',
              coach='
    $coach',
              cphone='
    $cphone',
              cfax='
    $cfax',
              cemail='
    $cemail',
              webpage='
    $webpage',
              games='
    $games',
              players='
    $players',
              date=CURDATE()
              WHERE id ='
    $id'"
          
      

      if (
    mysql_query($sql)) { 
       
        echo(
    "<div align='center'>
          <p>&nbsp;</p>
          <p>&nbsp;</p>
          <p>&nbsp;</p>

    <h1><strong><font face='Arial, Helvetica, sans-serif'>Contact info has been updated</font></strong></h1></div>"
    ); 
               

      } else { 
        die(
    '<p>Error updating Team details: ' 
            
    mysql_error() . '</p>'); 
      }
      

    else: 
    // Allow the user to edit the Team 
          // with ID=$id 


      
    $ID $_GET['id']; 

      
    $EditTeam=@mysql_query("SELECT *
                              FROM contacts 
                              WHERE id='
    $id'"); 
      if (!
    $EditTeam) { 
        die(
    '<p>Error fetching contacts details: ' 
            
    mysql_error() . '</p>'); 
      } 

      
    $contacts mysql_fetch_array($EditTeam); 

      
    $teamname $contacts['teamname']; 
      
    $id $contacts['id'];
      
    $password $contacts['password'];
      
    $teamcity $contacts['teamcity'];
      
    $teamstate $contacts['teamstate'];
      
    $division $contacts['division'];
      
    $manager $contacts['manager'];
      
    $mphone $contacts['mphone'];
      
    $mfax $contacts['mfax'];
      
    $memail $contacts['memail'];
      
    $coach $contacts['coach'];
      
    $cphone $contacts['cphone'];
      
    $cfax $contacts['cfax'];
      
    $cemail $contacts['cemail'];
      
    $webpage $contacts['webpage'];
      
    $games $contacts['games'];
      
    $players $contacts['players'];
      
    $premium $contacts['premium'];
      
      
    // Convert HTML special characters 
      // in database value for use in 
      // an HTML document. 
      
    $contactemail htmlspecialchars($contactemail);
      
    $coachemail htmlspecialchars($coachemail);

      
    //for future note module  
      
    if ($notes == '') {
       
    $message '';
        } else {
          
    $message 'You have a message! Click to read it';
         }

       
    ?>
    <font face="Arial, Helvetica, sans-serif"> </font>
    <form action= "editcontact.php?id=<?=$ID?>" method="post">
      <font face="Arial, Helvetica, sans-serif">
      <input type="hidden" name="id" value="<?=$ID?>" />
      <div align="center">
        <table width="80%" border="0" cellspacing="0" cellpadding="5">
          <tr> 
            <td width="26%"><strong><a href="delete.php?id=<?=$id?>"><font face="Arial, Helvetica, sans-serif">Delete 
              this Team</font></a></strong></td>
            <td width="26%"><div align="center"><font face="Arial, Helvetica, sans-serif"><strong><a href="notes.php?id=<?=$ID?>" onclick="popUpWin(this.href,'console',400,350);return false;" onkeypress="popUpWin(this.href,'console',400,350);return false;" title="Link open's in a new window"> 
                <?php if ($notes == '') {  $message '';} else { $message 'You have a message! 
            <br /> Click to read it'
    ;} 
             print 
    $message ?>
                </a></strong> </font> </div></td>
            <td width="26%"><div align="right"><font face="Arial, Helvetica, sans-serif"> 
                </font><font color="#FF0000" face="Arial, Helvetica, sans-serif"><strong> 
                </strong> </font></div></td>
          </tr>
        </table>
        
      </div>
      </font> <font face="Arial, Helvetica, sans-serif">
      <hr align="center" width="80%" />
      </font> 
      <center>
        <table width="80%" border="0" cellspacing="0" cellpadding="5">
          <tr>
            <td width="33%">&nbsp;</td>
            <td width="33%"><center><font face="Arial, Helvetica, sans-serif"><strong>Select division 
              for team.</strong> <br />
              </font> <table width="31%" border="0" cellspacing="0" cellpadding="5">
                <tr> 
                  <td width="25%"><div align="center"><font face="Arial, Helvetica, sans-serif"><strong>10U<br />
                      </strong> 
                      <input type="radio" name="division" value="10U"<?php if ($division == "10U") echo ("checked");?> />
                      </font></div></td>
                  <td width="25%"><div align="center"><font face="Arial, Helvetica, sans-serif"><strong>12U<br />
                      </strong> 
                      <input type="radio" name="division" value="12U"<?php if ($division == "12U") echo ("checked");?> />
                      </font></div></td>
                  <td width="25%"><div align="center"><font face="Arial, Helvetica, sans-serif"><strong>14U<br />
                      </strong> 
                      <input type="radio" name="division" value="14U"<?php if ($division == "14U") echo ("checked");?> />
                      </font></div></td>
                  <td width="24%"><div align="center"><font face="Arial, Helvetica, sans-serif"><strong>16U</strong><br />
                      <input type="radio" name="division" value="16U"<?php if ($division == "16U") echo ("checked");?> />
                      </font></div></td>
                  <td width="26%"><div align="center"><font face="Arial, Helvetica, sans-serif"><strong>18U</strong><br />
                      <input type="radio" name="division" value="18U"<?php if ($division == "18U") echo ("checked");?> />
                      </font></div></td>
                  <td width="25%"><div align="center"><font face="Arial, Helvetica, sans-serif"><strong>18Gold</strong></font><font face="Arial, Helvetica, sans-serif"> 
                      <input type="radio" name="division" value="18Gold"<?php if ($division == "18Gold") echo ("checked");?> />
                        </font></div></td>
                </tr>
              </table></center></td>
            <td width="33%"><div align="center"><font face="Arial, Helvetica, sans-serif">
                <input type="submit" name="submit" value="Save Changes" />
                </font></div></td>
          </tr>
        </table>
        <font face="Arial, Helvetica, sans-serif">
        <hr align="center" width="80%">
        </font> 
        <table width="90%" border="0">
          <tr> 
            <td height="27" colspan="2"><font face="Arial, Helvetica, sans-serif"><strong>Team 
              Name, Manager and Head Coach info</strong></font> </td>
            <td><font face="Arial, Helvetica, sans-serif">Password</font> 
            <td><font face="Arial, Helvetica, sans-serif"> 
              <input name="password" type="text" id="password" value="<?=$password?>" />
              </font></td>
          </tr>
          <tr> 
            <td width="12%" height="29"><font face="Arial, Helvetica, sans-serif">Team 
              Name</font></td>
            <td width="33%"><font face="Arial, Helvetica, sans-serif"> 
              <input name="teamname" type="text" id="teamname" value="<?=$teamname?>" size="30">
              </font></td>
            <td width="14%"><font face="Arial, Helvetica, sans-serif">Team<br />
              Base City</font> 
            <td width="41%"> <font face="Arial, Helvetica, sans-serif"> 
              <input name="teamcity" type="text"  id="teamcity" value="<?=$teamcity?>" size="15" />
              State 
              <input name="teamstate" type="text"  value="<?=$teamstate?>" size="2" />
              </font></td>
          </tr>
          <tr> 
            <td><font face="Arial, Helvetica, sans-serif">Manager</font></td>
            <td><font face="Arial, Helvetica, sans-serif"> 
              <input name="manager" type="text" id="manager" value="<?=$manager?>" size="30">
              </font></td>
            <td><font face="Arial, Helvetica, sans-serif"> Coach</font></td>
            <td><font face="Arial, Helvetica, sans-serif"> 
              <input name="coach" type="text" id="coach" value="<?=$coach?>" size="30">
              </font></td>
          </tr>
          <tr> 
            <td><font face="Arial, Helvetica, sans-serif">Phone</font></td>
            <td><font face="Arial, Helvetica, sans-serif"> 
              <input name="mphone" type="text" id="mphone" value="<?=$mphone?>" size="12">
              Fax 
              <input name="mfax" type="text"  id="mfax" value="<?=$mfax?>" size="12" />
              </font></td>
            <td><font face="Arial, Helvetica, sans-serif">Phone</font></td>
            <td><font face="Arial, Helvetica, sans-serif"> 
              <input name="cphone" type="text" id="cphone2" value="<?=$cphone?>" size="12" />
              Fax 
              <input name="cfax" type="text" id="cfax" value="<?=$cfax?>" size="12">
              </font></td>
          </tr>
          <tr> 
            <td><font face="Arial, Helvetica, sans-serif">Email</font></td>
            <td><font face="Arial, Helvetica, sans-serif"> 
              <input name="memail" type="text" id="memail" value="<?=$memail?>" size="30" />
              </font></td>
            <td><font face="Arial, Helvetica, sans-serif">Email</font></td>
            <td><font face="Arial, Helvetica, sans-serif"> 
              <input name="cemail" type="text" id="cemail" value="<?=$cemail?>" size="30" />
              </font></td>
          </tr>
          <tr> 
            <td><font face="Arial, Helvetica, sans-serif">Web Page</font></td>
            <td colspan="3"> <input name="webpage" type="text" id="webpage" value="<?=$webpage?>" size="90" /></td>
          </tr>
        </table>
      <table width="90%" border="0">
       <tr>
         <td width="25%"><font face="Arial, Helvetica, sans-serif"> 
         <?php if ($premium == "yes") echo ("<center><img src='images/icon_trophy.gif' width='24' height='24''><br>Enter Games or Tourneys<br>you are hosting here.<br><br>Leave it blank<br>if you are not hosting<br>any games.</center>");?>
              </font></td>
         <td width="75%">
              
         <?php if ($premium == TRUE) { ?> <textarea  name="games" cols="50" rows="10"><?=$games?></textarea> <? ?>  
         </td>
       </tr>
       <tr>
         <td><font face="Arial, Helvetica, sans-serif">
         <?php if ($premium == "yes") echo ("<center><img src='images/players.jpg' width='24' height='24''><br>Discribe what players<br>you are looking for.<br><br>Leave it blank<br>if you are not seeking<br>any players.</center>");?>
              </font></td>
         <td>
         <?php if ($premium == "yes") echo ("<textarea  name='players' cols='50' rows='10'>$players</textarea></font>");?>
         </td>
      </tr>
    </table>

      </center>
      <hr align="center" width="80%">
      
    </form>

    <?php endif;?>
    </font> 
    </body>
    </html>

  16. #16
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    At My Desk!!
    Posts
    1,642
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    wow thats a lot of work . Hmmm well the only thing that could be wrong is the premium variable. Im not exactly sure what but if its working without it. Have a look to make sure that $premium actually becomes true through your script like putting a little message in

    PHP Code:
    if ($premium == TRUE)
    {
    echo
    "Yay";
    }
    else
    {
    echo
    "Oh dear";

    Then at least we'll know whether or not its that, that is the problem
    "Am I the only one doing ASP.NET in Delphi(Pascal)?"

  17. #17
    SitePoint Addict caddyfixr's Avatar
    Join Date
    Aug 2004
    Location
    Albuquerque, NM
    Posts
    249
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    after inserting your test code it displayed Yay

  18. #18
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    At My Desk!!
    Posts
    1,642
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    when u say it will not update the database wht do u mean, because the code u are suplying will only show whatever is stored in $game in the text box, how do u want it to work?
    "Am I the only one doing ASP.NET in Delphi(Pascal)?"

  19. #19
    SitePoint Addict caddyfixr's Avatar
    Join Date
    Aug 2004
    Location
    Albuquerque, NM
    Posts
    249
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You are correct but it can also be edited using the query

    PHP Code:
    else: // Allow the user to edit the Team 
          // with ID=$id 


      
    $ID $_GET['id']; 

      
    $EditTeam=@mysql_query("SELECT * 
                              FROM contacts 
                              WHERE id='
    $id'"); 
      if (!
    $EditTeam) { 
        die(
    '<p>Error fetching contacts details: ' 
            
    mysql_error() . '</p>'); 
      } 

      
    $contacts mysql_fetch_array($EditTeam); 
    I use the same code on another site and it works flawlesly using
    PHP Code:
    <textarea  name='games' cols='50' rows='10'><?=$games?></textarea>
    MY problem is trying to overcome the qaulifier "premium" that has been the only change in the code

  20. #20
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    At My Desk!!
    Posts
    1,642
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmm, well im sorry mate but im stumped

    Hope you get it sorted
    "Am I the only one doing ASP.NET in Delphi(Pascal)?"

  21. #21
    SitePoint Addict caddyfixr's Avatar
    Join Date
    Aug 2004
    Location
    Albuquerque, NM
    Posts
    249
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I really thank you for your help and will post it here when I do.

  22. #22
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    At My Desk!!
    Posts
    1,642
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    just seen something, im not sure whether this is meant to be SELECT but the code you have will only SELECT from the database not update maybe if it was:
    PHP Code:
    $EditTeam=@mysql_query("UPDATE *
                              SET contacts
                              WHERE id='
    $id'"); 
    That as i can see it would be the only way that it would be able to update


    EDIT: thats not the full syntax but you get the pic

    Failing that im missing something
    "Am I the only one doing ASP.NET in Delphi(Pascal)?"

  23. #23
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    At My Desk!!
    Posts
    1,642
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    forget the last post because i remebre you said that it works without the premium, my bad
    "Am I the only one doing ASP.NET in Delphi(Pascal)?"

  24. #24
    SitePoint Addict caddyfixr's Avatar
    Join Date
    Aug 2004
    Location
    Albuquerque, NM
    Posts
    249
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes that is in there if you scan all the code you will find
    PHP Code:
    $sql "UPDATE contacts SET 
    thanks again

  25. #25
    SitePoint Addict caddyfixr's Avatar
    Join Date
    Aug 2004
    Location
    Albuquerque, NM
    Posts
    249
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Success! the problem was an oversight at where I was posting it to. I change the name of this page from editcontacts.php to editcontactsPremium.php. so naturally this peice of code needed to be changed as well.
    PHP Code:
    <form action= "editcontactPremium.php?id=<?=$ID?>" method="post">
    Since all the code was identical except my addition of the "premium" qualifier the rest of the code would still work. I guess sometimes sleep is all you need to see the all of the code

    Thanks
    Steve


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •