Jump to content

Recommended Posts

Hi Guys,

 

on my site the users can goto the control panel and edit there profile (age,location etc) from input boxes and drop down boxes, but if i just for the heck of it press the "update profile" button WITHOUT putting in the correct data it is all lost (no input in the input boxes defaults to zero in mysql)

 

what would be the best way to only update mysql when the user input the data, i have attatched a screencap of some of the fields

 

http://img61.imageshack.us/my.php?image=testvx9.jpg

 

cheers

 

Graham

Link to comment
https://forums.phpfreaks.com/topic/57944-solved-edit-profile-form/
Share on other sites

Is that right? Yes, No, and Maybe, and depends on how your code retrieves information from the database (code we've not seen).

 

For a data field such as text:

 

<?php echo '<input type="text" name="something" value="'. $something. '"/>';?>

 

For a drop down, you'll want all of the possible values in an array, and display the chosen value, something like this

 

<?php
for ($i=0;$i<count($myvalues);$i++) {
    echo 'option value="'. $myvalues[$i]. '";
    if ($myvalues[$i]== $database_value) {
        echo ' selected="selected"';
    }
    echo '>'. $myvalues[$i]. '</option>\n';
}?>

 

 

Hi Andy,

 

this is how im getting the information from mysql:

 

     $display_query = "SELECT * FROM `users` WHERE `username`='$member'";
     $display_result = mysql_query($display_query) or die (mysql_error());
     $display = mysql_fetch_array($display_result) or die (mysql_error());
     $fname = $display['first_name'];
     $lname = $display['last_name'];
     $mail = $display['email'];
     $bmonth = $display['birth_month'];
     $bday = $display['birth_day'];
     $byear = $display['birth_year'];
     $gender_dis = $display['gender'];
     $tphone = $display['telephone'];
     $mbile = $display['mobile'];
     $ctry = $display['country'];
     $ft = $display['feet'];
     $in = $display['inches'];
     $st = $display['stones'];
     $lb = $display['lbs'];
     $eyec = $display['eye'];
     $hairc = $display['hair'];
     $bild = $display['build'];
     $pf = $display['play_ages_from'];
     $pt = $display['play_ages_to'];
     $eth = $display['ethnicity'];
     $skillz = $row['skills'];
     $add_inf = $row['add_info'];

 

this is the smallest drop down example:

 

           <td align="right">Gender:</td><td align="left"><select name="gender">
                                                          <option value="Male">Male</option>
                                                          <option value="Female">Female</option>
                                                          </select>
           </td>

 

the text areas are easy enough i have them down , it just seems to be the drop down boxes i have trouble displaying the selected information

 

also i have some for each loops cycling through the initial screen to input you data like:

 

           <td align="right">Country:</td><td align="left">';
           
     echo '<select name="country">';
        
        foreach ($country_list as $value) {
           
           echo "<option value=\"$value\">$value</option>\n";
           
       }   
               
     echo '</select>

 

how would i go about implememnting the code you have selected with this one?

 

thanks for any help guys

 

Graham

<td align="right">Country:</td><td align="left">';
echo '<select name="country">';
foreach ($country_list as $value) {
    echo "<option value='". $value. "'";
    if ($value == $ctry) {
        echo " selected='selected'";
    }
    echo ">". $value. "</option>\n";
}
echo '</select>';

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.