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);
}
//
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;
}
}
<td>Assign to Member
<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>
thanks.