www.webdeveloper.com
Results 1 to 5 of 5

Thread: I want to display a users data in a form field.

  1. #1
    Join Date
    Jul 2008
    Posts
    11

    Angry I want to display a users data in a form field.

    Ok I have been trying and trying for ages and I just can't figure this thing out basically I have an email for on my website where users will beable to edit their account information, and then have it sent to me in an email so I can change it on the database.
    But I want them to see their existing information so they can make edits to it and add and delete stuff therefore I want to display the existing information in the boxes.

    I've done it fine with the username and password due to a session already been created.

    Page where users edit details:
    Code:
    <?
    session_start();
    if(!session_is_registered(myusername)){
    header("location:notloggedin.php");
    }
    ?>
    
    <?php
    $host="sql207.byethost17.com"; // Host name
    $username="b17_2102460"; // Mysql username
    $password="CENSORED"; // Mysql password
    $db_name="b17_2102460_members"; // Database name
    $tbl_name="members"; // Table name
    
    // Connect to server and select database.
    mysql_connect("$host", "$username", "$password")or die("Cannot connect to the database");
    mysql_select_db("$db_name")or die("cannot select DB");
    
    $query = mysql_query("SELECT * FROM members WHERE email='$myemail' AND profile='$myprofile'");
    $row = mysql_fetch_array($query);
    
    ?>
    
    <!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>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>My Account</title>
    <style type="text/css">
    <!--
    .style40 {
    	font-size: 24px;
    	font-family: Geneva, Arial, Helvetica, sans-serif;
    	color: #EEC310;
    }
    .style43 {font-size: 14px}
    .style44 {color: #EEC310}
    .style47 {
    	font-family: Geneva, Arial, Helvetica, sans-serif;
    	font-size: 14px;
    }
    .style48 {color: #EEC310; font-family: Geneva, Arial, Helvetica, sans-serif; font-size: 14px; }
    -->
    </style>
    </head>
    
    <body>
    <table width="751" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <th width="752" height="196" background="banner.png" scope="row"><p>&nbsp;</p></th>
      </tr>
      <tr>
        <th height="35" valign="top" scope="row"><img src="navigation_exclusive.png" alt="exclusive navbar" width="752" height="35" border="0" usemap="#Map" /></th>
      </tr>
      <tr>
        <th height="196" valign="top" background="wrapper.png" scope="row"><table width="748" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <th width="12" scope="col">&nbsp;</th>
            <th width="720" align="center" valign="top" scope="col"><p class="style40">My Account<br />
                <span class="style43">Hello <?php echo $_SESSION['myusername']; ?> below enter your existing username and password, and then fill in any required details that you would like changed. Please allow upto 48hrs for the change to be made.</span></p>
              <table width="393" height="269" border="8" align="center" cellpadding="0" cellspacing="0" bordercolor="#FFFFFF">
                <tr>
                  <td width="375" height="253" bgcolor="#0033CC"><script src="http://jotform.com/js/form.js?v2.0.727" type="text/javascript"></script>
    <style type="text/css">html,body{height:100%; margin:0;}
    .tbmain{ 
     /* Changes on the form */
     background: white !important; 
    }
    .left{
      /* Changes on the form */
      color: black !important; 
      font-family: Verdana !important;
      font-size: 12px !important;
    }
    .head{
      color:#333333;
      font-size:20px;;
      text-decoration:underline;
      font-family:"Verdana";
    }
    td.left {
      font-family:"Verdana";
      font-size:12px;
      color:black;
    }
    .pagebreak{
      font-family:"Verdana";
      font-size:12px;
      color:black;
    }
    .tbmain{
      height:100%;
      background:white;
    }
    span.required{
      font-size: 13px !important;
      color: red !important;
    }
    
    </style> 
    </head>
    <body>
    <table width="100%" cellpadding="2" cellspacing="0" class="tbmain">
    <tr><td width="10" height="10" bgcolor="#0033CC" class="topleft">&nbsp;</td>
    <td bgcolor="#0033CC" class="topmid">&nbsp;</td>
    <td width="10" height="10" bgcolor="#0033CC" class="topright">&nbsp;</td>
      </tr>
    <tr>
    <td width="10" bgcolor="#0033CC" class="midleft">&nbsp;&nbsp;&nbsp;</td>
    <td valign="top" bgcolor="#0033CC" class="midmid">
    <form  action="http://jotform.com/submit.php"  method="post" name="q_form_82023709968">
    <input type="hidden" name="formID" value="82023709968" />
    <div id="main"> 
    <table width="520" cellpadding="5" cellspacing="0">
     <tr >
       <td width="150" bgcolor="#0033CC" class="left" ><span class="style48">
         <label >Current Username *</label>
       </span> </td>
       <td bgcolor="#0033CC" class="right" >
       <input name="q9_CurrentUsername" type="text" class="text" id="q9"  onblur="validate(this,'Required')" value="<?php echo $_SESSION['myusername']; ?>" size="35"  maxlength="100" maxsize="100" />  </td>
     </tr>
     <tr >
       <td width="150" bgcolor="#0033CC" class="left" ><span class="style48">
         <label >Current Password *</label>
       </span> </td>
       <td bgcolor="#0033CC" class="right" >
       <input name="q10_CurrentPassword" type="password" class="text" id="q10"  onblur="validate(this,'Required')" value="<?php echo $_SESSION['mypassword']; ?>" size="35"  maxlength="100" maxsize="100" />  </td>
     </tr>
     <tr >
      <td colspan="2" bgcolor="#0033CC" class="left style44 style47" >&nbsp;</td>
     </tr>
     <tr >
       <td width="150" bgcolor="#0033CC" class="left" ><span class="style48">
         <label >New Username</label>
       </span> </td>
       <td bgcolor="#0033CC" class="right" >
       <input type="text" size="35" name="q12_NewUsername" class="text" value="" id="q12"  maxlength="100" maxsize="100" />  </td>
     </tr>
     <tr >
       <td width="150" bgcolor="#0033CC" class="left" ><span class="style48">
         <label >New Password</label>
       </span> </td>
       <td bgcolor="#0033CC" class="right" >
       <input type="password" size="35" name="q13_NewPassword" class="text" value="" id="q13"  maxlength="100" maxsize="100" />  </td>
     </tr>
     <tr >
       <td width="150" bgcolor="#0033CC" class="left" ><span class="style48">
         <label >Email Address</label>
       </span> </td>
       <td bgcolor="#0033CC" class="right" >
       <input name="q14_EmailAddress" type="text" class="text" id="q14"  onblur="validate(this,'Email')" value="<?php echo $row['myemail']?>" size="35"  maxlength="100" maxsize="100" />  </td>
     </tr>
     <tr >
       <td width="150" valign="top" bgcolor="#0033CC" class="left"  ><span class="style48">
         <label>Profile</label>
       </span> </td>
       <td bgcolor="#0033CC" class="right" >
       <textarea cols="27" rows="2" name="q15_Profile" class="text" id="q15" ><?php echo $row['myprofile']?></textarea>  </td>
     </tr>
     <tr >
      <td width="150" bgcolor="#0033CC" class="left" >&nbsp;  </td>
      <td bgcolor="#0033CC" class="right">
      <input type="submit" class="btn" value="Submit" /> </td>
     </tr>
    </table>
    </div>
    </form>
    </td>
    <td width="10" bgcolor="#0033CC" class="midright">&nbsp;&nbsp;&nbsp;</td>
    </tr>
    <tr>
     <td width="10" height="10" bgcolor="#0033CC" class="bottomleft">&nbsp;</td>
     <td bgcolor="#0033CC" class="bottommid">&nbsp;</td>
     <td width="10" height="10" bgcolor="#0033CC" class="bottomright">&nbsp;</td>
    </tr>
    </table>
    <script type="text/javascript">
    validate("q_form_82023709968");
    </script>
    &nbsp;</td>
                </tr>
              </table>          <p class="style40">&nbsp;</p></th>
            <th width="20" height="210" scope="col">&nbsp;</th>
          </tr>
        </table></th>
      </tr>
      <tr>
        <th height="25" background="footer.png" scope="row">&nbsp;</th>
      </tr>
    </table>
    <map name="Map" id="Map">
      <area shape="rect" coords="530,5,594,33" href="logout.php" />
      <area shape="rect" coords="156,8,211,29" href="list_records.php" />
    </map>
    </body>
    </html>
    Any help here?
    Nothing is printed in the form fields, they appear BLANK.

  2. #2
    Join Date
    Nov 2007
    Location
    Ohio
    Posts
    308
    If you do:

    $query = mysql_query("SELECT * FROM members WHERE email='$myemail' AND profile='$myprofile'");
    $row = mysql_fetch_array($query);
    print_r($row);

    Does that print out the data? Otherwise your query is bad and that would explain why the fields are blank.

  3. #3
    Join Date
    Jul 2008
    Posts
    85
    Don't bother sstalder.. He made a topic earlier, he doesn't know PHP and he doesn't know where variables in his SQL statement came from or what they contain (SQL is returning blank because $myemail and $myprofile are empty).

    Like I said europeanteens, read the website I gave you a link to and get an understanding of PHP, because any answer we give you you won't understand. Until we know how you're getting the information for $myemail and $myprofile, it won't work.

    You yourself don't know where that information came from except a friend telling you to write it. It must come from somewhere. Whilst it is empty, your page will not work as you want it to.

    I highly suggest learning PHP before coding it. Using source from the internet will only get you so far.

  4. #4
    Join Date
    Jul 2008
    Posts
    11
    Quote Originally Posted by maveruk
    Don't bother sstalder.. He made a topic earlier, he doesn't know PHP and he doesn't know where variables in his SQL statement came from or what they contain (SQL is returning blank because $myemail and $myprofile are empty).

    Like I said europeanteens, read the website I gave you a link to and get an understanding of PHP, because any answer we give you you won't understand. Until we know how you're getting the information for $myemail and $myprofile, it won't work.

    You yourself don't know where that information came from except a friend telling you to write it. It must come from somewhere. Whilst it is empty, your page will not work as you want it to.

    I highly suggest learning PHP before coding it. Using source from the internet will only get you so far.
    I'm getting the information from a MySQL database.

  5. #5
    Join Date
    Jul 2008
    Posts
    85
    Quote Originally Posted by europeanteens
    I'm getting the information from a MySQL database.
    That's my point. You don't know what we're talking about.

    I said "Where are you getting $myemail and $myprofile from in your SQL statement".

    You said "I'm getting the information from a MySQL database".

    Those variables need to be set BEFORE your statement, otherwise it WILL return no results, just like the problem you are having. The difference is you have no idea why you put those details because someone "told" you to do it.


    You obviously have no clue what you're doing. To further support that, you're manually updating peoples passwords for them by having them email it to you. Why don't they just update it themselves via your page? Because you probably don't know how to do it. So read the damn page I gave you a link to. It's a crash course in PHP / MySQL and it won't take you half an hour to go through. This only benefits yourself because everything about the page you've made is wrong, and I don't think there is a single person here who can help you without building your page from scratch. You need to help yourself first.

    I'm not going to get pissed about it, because I don't have to help you.. Nobody here does, you need to help yourself by actually learning the basics rather than pinching bits of code you've seen on the internet, because that's not how you learn PHP.
    So why am I posting? To help you. Learn the basics and then perhaps you will see why this doesn't work, and fix it, because we've told you why it doesn't work, but only you can fix that problem. $myemail and $myprofile need to be set. They need to match a persons record. They are variables that have no value, so they return no results. If you give them a value it will return results, and I told you HOW to do that in your other post, but again, since you don't understand PHP at all, you don't know how to implement it.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles