Jump to content


Photo

Saving Option Select to MySQL


  • Please log in to reply
1 reply to this topic

#1 wastedthelight

wastedthelight
  • Members
  • PipPipPip
  • Advanced Member
  • 32 posts

Posted 03 October 2006 - 08:30 PM

Doesn't seem to work.  Not to good with this stuff yet.  The input box worked but once I changed it to a option menu, it stopped and errored: Notice: Undefined index: showtime in C:\Inetpub\wwwroot\djs\edit_profile.php on line 162...Thanks.


<?php
session_start();
require("config.php");
require("functions.php");
//echo some styles to spice it up...
echo "
<style>
body
{
background: #000000;
font-family: Verdana, Arial;
font-weight: bold;
font-size: 9px;
color: #FFFFFF;
}
.register_box
{
border: 1px solid #323232;
background: #202020;
font-family: Verdana, Arial;
font-weight: bold;
font-size: 9px;
color: #FFFFFF;
}
</style>
";
if(isset($_SESSION['logged_in']))
{
$session_username = $_SESSION['username'];
// further checking...
if(username_exists($session_username))
{
$get_info = mysql_query("SELECT username, email, bio, showname, showtime, aim, yahoo, myspace, msn, website, facebook, major, minor, favcd, favgenre, favartist, favmovie, home, name, showgenre FROM user_system WHERE username = '$session_username' LIMIT 1");
if(mysql_num_rows($get_info) > 0)
{
$user_info = mysql_fetch_assoc($get_info);
if(!isset($_POST['do_edit']))
{
echo '
<img src="images/djcp.jpg"><br>
<a href="memberlist.php">View Member List</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;
<a href="logout.php">Log Out</a>
<br><br>
<form action="edit_profile.php" method="post">
  <table width="300" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td bgcolor="blue"><b>Real Name:</b></td>
      <td><input type="text" name="name"   class="register_box" value="' . $user_info['name'] . '" /></td>
    </tr>
    <tr>
      <td> <p><b>Show Name:</b> </p></td>
      <td><input type="text" name="showname"  class="register_box" value="' . $user_info['showname'] . '" /></td>
    </tr>
    <tr>
      <td bgcolor="blue"><b>Show Time: </b></td>
      <td>
          <label>
          <select name="showtime" value="' . $user_info['showtime'] . '" class="register_box" />
            <option value="12-3AM" selected>12-3AM</option>
            <option value="3-6AM">3-6AM</option>
            <option value="6-8AM">6-8AM</option>
            <option value="8-10AM">8-10AM</option>
            <option value="10-12PM">10-12PM</option>
            <option value="12-2PM">12-2PM</option>
            <option value="2-4PM">2-4PM</option>
            <option value="4-6PM">4-6PM</option>
            <option value="6-8PM">6-8PM</option>
            <option value="8-10PM">8-10PM</option>
            <option value="10-12AM">10-12AM</option>
          </select>
          </label>
</p></td>
    </tr>
    <tr>
      <td><b>Show Genre:</b> </td>
      <td><input type="text" name="showgenre" class="register_box"  value="' . $user_info['showgenre'] . '" /></td>
    </tr>
    <tr>
      <td bgcolor="blue"> <b>E-mail:</b> </td>
      <td><input type="text" name="email" class="register_box"  value="' . $user_info['email'] . '" /></td>
    </tr>
    <tr>
      <td><b>AIM:</b> </td>
      <td><input type="text" name="aim" class="register_box"  value="' . $user_info['aim'] . '" /></td>
    </tr>
    <tr>
      <td bgcolor="blue"><b>Yahoo:</b> </td>
      <td><input type="text" name="yahoo" class="register_box"  value="' . $user_info['yahoo'] . '" /></td>
    </tr>
    <tr>
      <td><b>MSN:</b></td>
      <td><input type="text" name="msn"  class="register_box" value="' . $user_info['msn'] . '" /></td>
    </tr>
    <tr>
      <td bgcolor="blue"><b>Website:</b></td>
      <td><input type="text" name="website"  class="register_box" value="' . $user_info['website'] . '" /></td>
    </tr>
    <tr>
      <td><b>Facebook:</b></td>
      <td><input type="text" name="facebook" class="register_box"  value="' . $user_info['facebook'] . '" /></td>
    </tr>
    <tr>
      <td bgcolor="blue"><b>MySpace:</b></td>
      <td><input type="text" name="myspace" class="register_box"  value="' . $user_info['myspace'] . '" /></td>
    </tr>
    <tr>
      <td><b>Major:</b></td>
      <td><input type="text" name="major"  class="register_box" value="' . $user_info['major'] . '" /></td>
    </tr>
    <tr>
      <td bgcolor="blue"><b>Minor:</b></td>
      <td><input type="text" name="minor" class="register_box"  value="' . $user_info['minor'] . '" /></td>
    </tr>
    <tr>
      <td><b>Home:</b></td>
      <td><input type="text" name="home" class="register_box"  value="' . $user_info['home'] . '" /></td>
    </tr>
    <tr>
      <td bgcolor="blue"><b>Favorite Genre: </b></td>
      <td><input type="text" name="favgenre" class="register_box"  value="' . $user_info['favgenre'] . '" /></td>
    </tr>
    <tr>
      <td><b>Favorite Artist:</b> </td>
      <td><input type="text" name="favartist" class="register_box"  value="' . $user_info['favartist'] . '" /></td>
    </tr>
    <tr>
      <td bgcolor="blue"><b>Favorite CD: </b></td>
      <td><input type="text" name="favcd" class="register_box"  value="' . $user_info['favcd'] . '" /></td>
    </tr>
    <tr>
      <td><b>Favorite Movie: </b></td>
      <td><input type="text" name="favmovie"  class="register_box" value="' . $user_info['favmovie'] . '" /></td>
    </tr>
    <tr>
      <td bgcolor="blue"><b>Biography:</b></td>
      <td><input type="textarea" name="bio" class="register_box"  value="' . $user_info['bio'] . '" /></td>
    </tr>
    <tr>
      <td>&nbsp;<br><br><br></td>
      <td><input type="submit" name="do_edit" class="register_box"  value="Update Profile" /></td>
    </tr>
  </table>
  <p><br />
  </p>
</form>
';
}
elseif(isset($_POST['do_edit']))
{
$email = mysql_real_escape_string($_POST['email']);
$name = mysql_real_escape_string($_POST['name']);
$showname = mysql_real_escape_string($_POST['showname']);
$showtime = mysql_real_escape_string($_POST['showtime']);
$showgenre = mysql_real_escape_string($_POST['showgenre']);
$aim = mysql_real_escape_string($_POST['aim']);
$yahoo = mysql_real_escape_string($_POST['yahoo']);
$msn = mysql_real_escape_string($_POST['msn']);
$website = mysql_real_escape_string($_POST['website']);
$facebook = mysql_real_escape_string($_POST['facebook']);
$myspace = mysql_real_escape_string($_POST['myspace']);
$major = mysql_real_escape_string($_POST['major']);
$minor = mysql_real_escape_string($_POST['minor']);
$home = mysql_real_escape_string($_POST['home']);
$favgenre = mysql_real_escape_string($_POST['favgenre']);
$favartist = mysql_real_escape_string($_POST['favartist']);
$favcd = mysql_real_escape_string($_POST['favcd']);
$favmovie = mysql_real_escape_string($_POST['favmovie']);
$bio = mysql_real_escape_string($_POST['bio']);

// assign all errors to an array
$errors = array();
if(empty($email))
{
$errors[] = 'Your email was empty.';
}
if(!is_valid_email($email))
{
$errors[] = 'Your email was not in a valid email format.';
}
// if array elements is greater than 0,
// then we KNOW there was an error
// else, no error, move on to processing
if(count($errors) > 0)
{
echo '<b>ERRORS:</b><br />';
foreach($errors as $err)
{
echo $err . '<br />';
}
}
else
{
// everything is ok, update the DB
mysql_query("UPDATE user_system SET email = '$email', bio = '$bio', name = '$name', showname = '$showname', showtime = '$showtime', aim = '$aim', yahoo = '$yahoo', msn = '$msn', website = '$website', facebook = '$facebook', myspace = '$myspace', major = '$major', minor = '$minor', home = '$home', favgenre = '$favgenre', favartist = '$favartist', favcd = '$favcd', favmovie = '$favmovie', showgenre = '$showgenre' WHERE username = '$session_username'");
echo "Profile Updated";

}
}
}
else
{
echo 'Could not find profile info for your username.';
}
}
else
{
echo '<b>Sorry, your session username doesnt exist</b>.';
}
}
else
{
echo 'You must be logged in to edit your profile.';
}
?> 


#2 printf

printf
  • Staff Alumni
  • Advanced Member
  • 889 posts

Posted 03 October 2006 - 10:41 PM

You can't use value='' in a select element declaration! There is no HTTP version that allows this! Only... (are allowed)

    * NAME: name of this form element
    * MULTIPLE: allow more than one choice
    * SIZE: how many options to show
    * READONLY: don't let the user change the value of this field
    * DISABLED: don't let the user do anything with this field



    * LANGUAGE: scripting language to use
    * onChange: what to do when a new option is selected
    * TABINDEX: tab order
    * onFocus: script to run when this field gets the focus
    * onBlur: script to run when this field loses the focus
    * any other JavaScript function will also work (ie: onkeyup, ...)


me!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users