Jump to content

help php/mysql array selection drop down


thafroggy

Recommended Posts

Hello all, this is my first post.  Very newbie.

 

I am modifying a "simple customer"  release.  I would like to have my drop down (which gets the users listed) to not only show the user name but to also select another column from the same data so that info is what is written to the mysql database.

 

Basicly I have two tables in mysql,  one for customers (follows_contacts) and one for admin users (follows_users).  I am trying to populate a field in the follows_contacts (contact_user) table with a value taken from the follows_user field (user_id).  I want to be able to assign customers their own personal admin user for tracking and followup.

 

I have my form pull from the mysql database table (follows_users) the field(s) user_name right now, this displas the first and last name of the admin user, I can select one and then this fills in the form field with that value and sends it and populates a field in the table (follows_users) called (user_assignment) well this is no longer working for me because I need more information about the admin user that is assigned to the customer, I am going to be adding a notification system so now I also need the admin users email address and may even need the phone number.  that is why I would still like the form drop down selection box to display the admin users first and last name , pulled from the (follows_users) table , but when they select this user I want instead for the field value of (user_id) sent to the mysql table of (follows_contacts) (contact_user) field, so later I can just create a variable from this field and can use it for queries to get more information directly from the (follows_users) table using the (user_id) field for that given admin.

 

Can somone help me with this?

 

Thank you very very much... I am so new to this and just love PHP so far.

 

<?php require_once('includes/config.php'); ?>

<?php

include('includes/sc-includes.php');

$pagetitle = Contact;

 

$update = 0;

if (isset($_GET['id'])) {

$update = 1;

}

?>

<?php

if (!function_exists("GetSQLValueString")) {

function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")

{

  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

 

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

 

  switch ($theType) {

    case "text":

      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

      break;   

    case "long":

    case "int":

      $theValue = ($theValue != "") ? intval($theValue) : "NULL";

      break;

    case "double":

      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";

      break;

    case "date":

      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

      break;

    case "defined":

      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;

      break;

  }

  return $theValue;

}

}

 

$editFormAction = $_SERVER['PHP_SELF'];

if (isset($_SERVER['QUERY_STRING'])) {

  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);

}

 

 

 

//

if ($update==1) {

mysql_select_db($database_follows, $follows);

$query_contact = "SELECT * FROM follows_contacts WHERE contact_id = ".$_GET['id']."";

$contact = mysql_query($query_contact, $follows) or die(mysql_error());

$row_contact = mysql_fetch_assoc($contact);

$totalRows_contact = mysql_num_rows($contact);

}

//

 

 

 

 

 

//UPLOAD PICTURE

$picture = $_POST['image_location'];

$time = substr(time(),0,5);

  if($HTTP_POST_FILES['image'] && $HTTP_POST_FILES['image']['size'] > 0){

$ori_name = $_FILES['image']['name'];

$ori_name = $time.$ori_name;

$tmp_name = $_FILES['image']['tmp_name'];

$src = imagecreatefromjpeg($tmp_name);

list($width,$height)=getimagesize($tmp_name);

$newwidth=95;

$newheight=($height/$width)*95;

$tmp=imagecreatetruecolor($newwidth,$newheight);

imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);

$filename = "images/". $ori_name;

imagejpeg($tmp,$filename,100);

$picture = $ori_name;

imagedestroy($src);

imagedestroy($tmp);

}

//END UPLOAD PICTURE

 

if ($update==0) {

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {

  $insertSQL = sprintf("INSERT INTO follows_contacts (contact_first, contact_last, contact_date, contact_userassign, contact_image, contact_profile, contact_method, contact_street, contact_city, contact_state, contact_zip, contact_phone, contact_cell, contact_email, contact_web, contact_updated) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",

                      GetSQLValueString(trim($_POST['contact_first']), "text"),

                      GetSQLValueString(trim($_POST['contact_last']), "text"),

                      GetSQLValueString(time(), "date"),

  GetSQLValueString(trim($_POST['contact_userassign']), "text"),

                      GetSQLValueString($picture, "text"),

                      GetSQLValueString(trim($_POST['contact_profile']), "text"),

                      GetSQLValueString(trim($_POST['contact_method']), "text"),

                      GetSQLValueString(trim($_POST['contact_street']), "text"),

                      GetSQLValueString(trim($_POST['contact_city']), "text"),

                      GetSQLValueString(trim($_POST['contact_state']), "text"),

                      GetSQLValueString(trim($_POST['contact_zip']), "text"),

                      GetSQLValueString(trim($_POST['contact_phone']), "text"),

                      GetSQLValueString(trim($_POST['contact_cell']), "text"),

                      GetSQLValueString(trim($_POST['contact_email']), "text"),

                      GetSQLValueString(trim($_POST['contact_web']), "text"),

                      GetSQLValueString($_POST['contact_updated'], "int"));

 

  mysql_select_db($database_follows, $follows);

  $Result1 = mysql_query($insertSQL, $follows) or die(mysql_error());

set_msg('Contact Added');

$cid = mysql_insert_id();

$redirect = "contact-details.php?id=$cid";

header(sprintf('Location: %s', $redirect)); die;

}

}

 

if ($update==1) {

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {

  $updateSQL = sprintf("UPDATE follows_contacts SET contact_first=%s, contact_last=%s, contact_userassign=%s, contact_image=%s, contact_profile=%s, contact_method=%s, contact_street=%s, contact_city=%s, contact_state=%s, contact_zip=%s, contact_phone=%s, contact_cell=%s, contact_email=%s, contact_web=%s, contact_updated=%s WHERE contact_id=%s",

                      GetSQLValueString(trim($_POST['contact_first']), "text"),

                      GetSQLValueString(trim($_POST['contact_last']), "text"),

                      GetSQLValueString(trim($_POST['contact_userassign']), "text"),

                      GetSQLValueString($picture, "text"),

                      GetSQLValueString(trim($_POST['contact_profile']), "text"),

                      GetSQLValueString(trim($_POST['contact_method']), "text"),

                      GetSQLValueString(trim($_POST['contact_street']), "text"),

                      GetSQLValueString(trim($_POST['contact_city']), "text"),

                      GetSQLValueString(trim($_POST['contact_state']), "text"),

                      GetSQLValueString(trim($_POST['contact_zip']), "text"),

                      GetSQLValueString(trim($_POST['contact_phone']), "text"),

                      GetSQLValueString(trim($_POST['contact_cell']), "text"),

                      GetSQLValueString(trim($_POST['contact_email']), "text"),

                      GetSQLValueString(trim($_POST['contact_web']), "text"),

                      GetSQLValueString(trim($_POST['contact_updated']), "int"),

                      GetSQLValueString(trim($_POST['contact_id']), "int"));

 

  mysql_select_db($database_follows, $follows);

  $Result1 = mysql_query($updateSQL, $follows) or die(mysql_error());

set_msg('Contact Updated');

$cid = $_GET['id'];

$redirect = "contact-details.php?id=$cid";

header(sprintf('Location: %s', $redirect)); die;

}

}

?>

<!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=iso-8859-1" />

<title><?php if ($update==0) { echo "Add Contact"; } ?><?php echo $row_contact['contact_first']; ?> <?php echo $row_contact['contact_last']; ?></title>

<script src="includes/lib/prototype.js" type="text/javascript"></script>

<script src="includes/src/effects.js" type="text/javascript"></script>

<script src="includes/validation.js" type="text/javascript"></script>

<script src="includes/src/scriptaculous.js" type="text/javascript"></script>

<script language="javascript">

function toggleLayer(whichLayer)

{

if (document.getElementById)

{

// this is the way the standards work

var style2 = document.getElementById(whichLayer).style;

style2.display = style2.display? "":"block";

}

else if (document.all)

{

// this is the way old msie versions work

var style2 = document.all[whichLayer].style;

style2.display = style2.display? "":"block";

}

else if (document.layers)

{

// this is the way nn4 works

var style2 = document.layers[whichLayer].style;

style2.display = style2.display? "":"block";

}

}

</script>

<link href="includes/style.css" rel="stylesheet" type="text/css" />

<link href="includes/simplecustomer.css" rel="stylesheet" type="text/css" />

</head>

 

<body>

<?php include('includes/header.php'); ?>

<div class="container">

  <div class="leftcolumn">

    <h2><?php if ($update==1) { echo Update; } else { echo Add; } ?> Follow-Up </h2>

    <p> </p>

    <form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" name="form1" id="form1">

      <table width="100%" border="0" cellspacing="0" cellpadding="0">

        <tr>

          <td width="28%">First Name<br />

            <input name="contact_first" type="text" class="required" id="contact_first" value="<?php echo $row_contact['contact_first']; ?>" size="25" /></td>

          <td width="72%">Last Name<br />

                <input name="contact_last" type="text" class="required" id="contact_last" value="<?php echo $row_contact['contact_last']; ?>" size="25" />

            </p></td>

        </tr>

        <tr>

          <td>First Contacted<br /><!---<input name="contact_title" type="none" id="contact_title" value="--><?php echo date('F d, Y', $row_contact['contact_date']); ?><!---" size="25" />-->          </td>

          <td>Contacted via<br />

            <select name="contact_method" id="contact_method">

<option value="">Select</option>

                            <option value="New Harvest Outreach" <?php if (!(strcmp("New Harvest Outreach", $row_contact['contact_method']))) {echo "selected=\"selected\"";} ?>>New Harvest Outreach</option>

                            <option value="Indvidual Outreach" <?php if (!(strcmp("Indvidual Outreach", $row_contact['contact_method']))) {echo "selected=\"selected\"";} ?>>Indvidual Outreach</option>

                            <option value="Celebreate Recovery" <?php if (!(strcmp("Celebreate Recovery", $row_contact['contact_method']))) {echo "selected=\"selected\"";} ?>>Celebrate Recovery</option>

                            <option value="Church Visit / Invite" <?php if (!(strcmp("Church Visit / Invite", $row_contact['contact_method']))) {echo "selected=\"selected\"";} ?>>Church Visit / Invite</option>

                            <option value="182 Visit / Invite" <?php if (!(strcmp("182 Visit / Invite", $row_contact['contact_method']))) {echo "selected=\"selected\"";} ?>>182 Visit / Invite</option>

                            <option value="Other" <?php if (!(strcmp("Other", $row_contact['contact_method']))) {echo "selected=\"selected\"";} ?>>Other</option>

            </select></td>

        </tr>

        <tr>

          <td colspan="2">Email <br />

            <input name="contact_email" type="text" class="required validate-email" id="contact_email" value="<?php echo $row_contact['contact_email']; ?>" size="35" /></td>

        </tr>

        <tr>

          <td colspan="2"><hr />

        <?php if ($update!=1) { ?>  <p><a href="#" onclick="new Effect.toggle('morecontact', 'slide'); return false;">+Add more Follow-Up information </a></p><?php } ?>

 

<div <?php if ($update!=1) { ?>id="morecontact" style="display:none"<?php } ?>>

            <table  width="100%" border="0" cellspacing="0" cellpadding="0">

              <tr>

                <td>Street<br />

                    <input name="contact_street" type="text" id="contact_street" value="<?php echo $row_contact['contact_street']; ?>" size="35" /></td>

              </tr>

              <tr>

                <td><table width="100%" border="0" cellspacing="0" cellpadding="0">

                    <tr>

                      <td width="39%">City<br />

                          <input name="contact_city" type="text" id="contact_city" value="<?php echo $row_contact['contact_city']; ?>" size="35" /></td>

                     

                      <td width="27%" valign="top">State<br />

                          <select name="contact_state" id="contact_state">

<option value="">Select a state...</option>

                            <option value="AL" <?php if (!(strcmp("AL", $row_contact['contact_state']))) {echo "selected=\"selected\"";} ?>>Alabama</option>

                            <option value="AK" <?php if (!(strcmp("AK", $row_contact['contact_state']))) {echo "selected=\"selected\"";} ?>>Alaska</option>

                            <option value="AZ" <?php if (!(strcmp("AZ", $row_contact['contact_state']))) {echo "selected=\"selected\"";} ?>>Arizona</option>

                            <option value="AR" <?php if (!(strcmp("AR", $row_contact['contact_state']))) {echo "selected=\"selected\"";} ?>>Arkansas</option>

                            <option value="CA" <?php if (!(strcmp("CA", $row_contact['contact_state']))) {echo "selected=\"selected\"";} ?>>California</option>

                            <option value="CO" <?php if (!(strcmp("CO", $row_contact['contact_state']))) {echo "selected=\"selected\"";} ?>>Colorado</option>

                            <option value="CT" <?php if (!(strcmp("CT", $row_contact['contact_state']))) {echo "selected=\"selected\"";} ?>>Connecticut</option>

                            <option value="DE" <?php if (!(strcmp("DE", $row_contact['contact_state']))) {echo "selected=\"selected\"";} ?>>Delaware</option>

                            <option value="DC" <?php if (!(strcmp("DC", $row_contact['contact_state']))) {echo "selected=\"selected\"";} ?>>District of Columbia</option>

                            <option value="FL" <?php if (!(strcmp("FL", $row_contact['contact_state']))) {echo "selected=\"selected\"";} ?>>Florida</option>

                            <option value="GA" <?php if (!(strcmp("GA", $row_contact['contact_state']))) {echo "selected=\"selected\"";} ?>>Georgia</option>

                            <option value="HI" <?php if (!(strcmp("HI", $row_contact['contact_state']))) {echo "selected=\"selected\"";} ?>>Hawaii</option>

                            <option value="ID" <?php if (!(strcmp("ID", $row_contact['contact_state']))) {echo "selected=\"selected\"";} ?>>Idaho</option>

                            <option value="IL" <?php if (!(strcmp("IL", $row_contact['contact_state']))) {echo "selected=\"selected\"";} ?>>Illinois</option>

                            <option value="IN" <?php if (!(strcmp("IN", $row_contact['contact_state']))) {echo "selected=\"selected\"";} ?>>Indiana</option>

                            <option value="IA" <?php if (!(strcmp("IA", $row_contact['contact_state']))) {echo "selected=\"selected\"";} ?>>Iowa</option>

                            <option value="KS" <?php if (!(strcmp("KS", $row_contact['contact_state']))) {echo "selected=\"selected\"";} ?>>Kansas</option>

                            <option value="KY" <?php if (!(strcmp("KY", $row_contact['contact_state']))) {echo "selected=\"selected\"";} ?>>Kentucky</option>

                            <option value="LA" <?php if (!(strcmp("LA", $row_contact['contact_state']))) {echo "selected=\"selected\"";} ?>>Louisiana</option>

                            <option value="ME" <?php if (!(strcmp("ME", $row_contact['contact_state']))) {echo "selected=\"selected\"";} ?>>Maine</option>

                            <option value="MD" <?php if (!(strcmp("MD", $row_contact['contact_state']))) {echo "selected=\"selected\"";} ?>>Maryland</option>

                            <option value="MA" <?php if (!(strcmp("MA", $row_contact['contact_state']))) {echo "selected=\"selected\"";} ?>>Massachusetts</option>

                            <option value="MI" <?php if (!(strcmp("MI", $row_contact['contact_state']))) {echo "selected=\"selected\"";} ?>>Michigan</option>

                            <option value="MN" <?php if (!(strcmp("MN", $row_contact['contact_state']))) {echo "selected=\"selected\"";} ?>>Minnesota</option>

                            <option value="MS" <?php if (!(strcmp("MS", $row_contact['contact_state']))) {echo "selected=\"selected\"";} ?>>Mississippi</option>

                            <option value="MO" <?php if (!(strcmp("MO", $row_contact['contact_state']))) {echo "selected=\"selected\"";} ?>>Missouri</option>

                            <option value="MT" <?php if (!(strcmp("MT", $row_contact['contact_state']))) {echo "selected=\"selected\"";} ?>>Montana</option>

                            <option value="NE" <?php if (!(strcmp("NE", $row_contact['contact_state']))) {echo "selected=\"selected\"";} ?>>Nebraska</option>

                            <option value="NV" <?php if (!(strcmp("NV", $row_contact['contact_state']))) {echo "selected=\"selected\"";} ?>>Nevada</option>

                            <option value="NH" <?php if (!(strcmp("NH", $row_contact['contact_state']))) {echo "selected=\"selected\"";} ?>>New Hampshire</option>

                            <option value="NJ" <?php if (!(strcmp("NJ", $row_contact['contact_state']))) {echo "selected=\"selected\"";} ?>>New Jersey</option>

                            <option value="NM" <?php if (!(strcmp("NM", $row_contact['contact_state']))) {echo "selected=\"selected\"";} ?>>New Mexico</option>

                            <option value="NY" <?php if (!(strcmp("NY", $row_contact['contact_state']))) {echo "selected=\"selected\"";} ?>>New York</option>

                            <option value="NC" <?php if (!(strcmp("NC", $row_contact['contact_state']))) {echo "selected=\"selected\"";} ?>>North Carolina</option>

                            <option value="ND" <?php if (!(strcmp("ND", $row_contact['contact_state']))) {echo "selected=\"selected\"";} ?>>North Dakota</option>

                            <option value="OH" <?php if (!(strcmp("OH", $row_contact['contact_state']))) {echo "selected=\"selected\"";} ?>>Ohio</option>

                            <option value="OK" <?php if (!(strcmp("OK", $row_contact['contact_state']))) {echo "selected=\"selected\"";} ?>>Oklahoma</option>

                            <option value="OR" <?php if (!(strcmp("OR", $row_contact['contact_state']))) {echo "selected=\"selected\"";} ?>>Oregon</option>

                            <option value="PA" <?php if (!(strcmp("PA", $row_contact['contact_state']))) {echo "selected=\"selected\"";} ?>>Pennsylvania</option>

                            <option value="RI" <?php if (!(strcmp("RI", $row_contact['contact_state']))) {echo "selected=\"selected\"";} ?>>Rhode Island</option>

                            <option value="SC" <?php if (!(strcmp("SC", $row_contact['contact_state']))) {echo "selected=\"selected\"";} ?>>South Carolina</option>

                            <option value="SD" <?php if (!(strcmp("SD", $row_contact['contact_state']))) {echo "selected=\"selected\"";} ?>>South Dakota</option>

                            <option value="TN" <?php if (!(strcmp("TN", $row_contact['contact_state']))) {echo "selected=\"selected\"";} ?>>Tennessee</option>

                            <option value="TX" <?php if (!(strcmp("TX", $row_contact['contact_state']))) {echo "selected=\"selected\"";} ?>>Texas</option>

                            <option value="UT" <?php if (!(strcmp("UT", $row_contact['contact_state']))) {echo "selected=\"selected\"";} ?>>Utah</option>

                            <option value="VT" <?php if (!(strcmp("VT", $row_contact['contact_state']))) {echo "selected=\"selected\"";} ?>>Vermont</option>

                            <option value="VA" <?php if (!(strcmp("VA", $row_contact['contact_state']))) {echo "selected=\"selected\"";} ?>>Virginia</option>

                            <option value="WA" <?php if (!(strcmp("WA", $row_contact['contact_state']))) {echo "selected=\"selected\"";} ?>>Washington</option>

                            <option value="WV" <?php if (!(strcmp("WV", $row_contact['contact_state']))) {echo "selected=\"selected\"";} ?>>West Virginia</option>

                            <option value="WI" <?php if (!(strcmp("WI", $row_contact['contact_state']))) {echo "selected=\"selected\"";} ?>>Wisconsin</option>

                            <option value="WY" <?php if (!(strcmp("WY", $row_contact['contact_state']))) {echo "selected=\"selected\"";} ?>>Wyoming</option>

                        </select></td>

                      <td width="34%">Zip<br />

                          <input name="contact_zip" type="text" id="contact_zip" value="<?php echo $row_contact['contact_zip']; ?>" size="10" /></td>

                    </tr>

                </table></td>

              </tr>

              <tr>

                <td><table width="100%" border="0" cellspacing="0" cellpadding="0">

                    <tr>

                      <td width="39%">Phone<br />

                          <input name="contact_phone" type="text" id="contact_phone" value="<?php echo $row_contact['contact_phone']; ?>" size="35" /></td>

                      <td width="61%">Cell<br />

                          <input name="contact_cell" type="text" id="contact_cell" value="<?php echo $row_contact['contact_cell']; ?>" size="35" /></td>

                    </tr>

                </table></td>

              </tr>

              <tr>

                <td>Image<br />

                    <input name="image" type="file" id="image" /><?php if ($row_contact['contact_image']) { ?>

                <br />

                <img src="images/<?php echo $row_contact['contact_image']; ?>" width="95" />

<?php } ?>

</td>

              </tr>

              <tr>

                <td>Assign to  Member<br />

                        <select name="contact_userassign" id="contact_userassign">

                        <option value="">Assign someone to this followup</option>

<?php

  $query_userassign = "SELECT user_name FROM follows_users WHERE 1";

  $userassign = mysql_query($query_userassign, $follows);

    if(mysql_num_rows($userassign)) {

      // we have at least one user, so show all users as options in select form

      while($row_userassign = mysql_fetch_row($userassign))

      {

          print("<option value=\"$row_userassign[0]\">$row_userassign[0]</option>");

      }

    } else {

      print("<option value=\"\">No users created yet</option>");

    }

?>

</select>

                </td>

              </tr>

              <tr>

                <td>Background/Profile<br />

                    <textarea name="contact_profile" cols="60" rows="3" id="contact_profile"><?php echo $row_contact['contact_profile']; ?></textarea></td>

              </tr>

            </table> 

</div>         

          <p> </p></td>

        </tr>

 

        <tr>

          <td colspan="2"><p>

            <input type="submit" name="Submit2" value="<?php if ($update==1) { echo Update; } else { echo Add; } ?> Follow-Up" />

            <input name="contact_updated" type="hidden" id="contact_updated" value="<?php echo time(); ?>" />

            <input type="hidden" name="MM_insert" value="form1" />

            <input name="contact_id" type="hidden" id="contact_id" value="<?php echo $row_contact['contact_id']; ?>" />

            <input name="image_location" type="hidden" id="image_location" value="<?php echo $row_contact['contact_image']; ?>" />

          </p></td>

        </tr>

      </table>

      <p> </p>

      <input type="hidden" name="MM_update" value="form1">

    </form>

  </div>

  <?php include('includes/right-column.php'); ?>

  <br clear="all" />

</div>

 

<?php include('includes/footer.php'); ?>

 

</body>

</html>

 

 

 

 

thx.

Link to comment
Share on other sites

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.