Jump to content

HELP with woking with multiple tables for populating an update form for users...


ellegua220

Recommended Posts

In php and sql how can i use multiple tables to populate a form for updating user information?

Here is a simplified table structure:

 

user

userid PK

first_name

last_name

 

parent

parent_id PK

parent_first_name

parent_last name

 

parent_user

parent_user_id PK

parent_id FK

userid FK

 

Here is what I have tried. I need to use the new table parent and parent_user to populate parent_first_name and parent_last_name. I think i need to JOIN the info in the select statement:

 

Here is the select statement I was trying to use but its not working:

$query = "SELECT user.userid, user.username, user.email, user.first_name, user.last_name, user.password, user.phone, user.street_address, user.other_address, city, state, zipcode, type, school, school_district, DATE_ADD(user.date_registered, INTERVAL $time_diff HOUR),user.double_gui,user.status_id,use… parent.parent_first_name from user, parent_user, parent where user.userid=$userid and parent_user.userid=$userid and parent.parent_id=$userid";

 

this is the original code that just uses the user table:

query = "SELECT userid, username, email, first_name, last_name, password, phone, street_address, other_address, city, state, zipcode, type, school, school_district, DATE_ADD(date_registered, INTERVAL $time_diff HOUR),double_gui,status_id,notes from user where userid=$userid";
$result = mysql_query($query, $mysql_link);
if((!result) || (! mysql_num_rows($result)))
{
die("<p class=highlight>error getting details of user userid=$userid from db</p>");
}

if ($row = mysql_fetch_row($result))
{
$userid = $row[0];
$username = $row[1];
$email = $row[2];
$first_name = $row[3];
$last_name = $row[4];
//$parent_last_name = $row[5];
$password = $row[5]; // no it didn't print "<tr><td> will this print next to the password??????</td></tr>";
$phone = $row[6];
$street_address = $row[7];
$other_address = $row[8];
$city = $row[9];
$state = $row[10];
$zipcode = $row[11];
$type = $row[12];
$school = $row[13];
$school_district = $row[14];
$date_registered = $row[15];
$double_gui = $row[16];
$status_id = $row[17];
$notes = $row[18];
if ($type == "S")
{
$student_selected = "selected";
}
elseif ($type == "T")
{
$tutor_selected = "selected";
}
elseif ($type == "A")
{
$admin_selected = "selected";
}
elseif ($type == "K")
{
$tech_selected = "selected";
}
}
}
print "<form>";
print "<table>";
if ($action == "edit")
{
print "<input type=hidden name=action value=update>";
print "<input type=hidden name=userid value='$userid'>";
}
else
{
print "<input type=hidden name=action value=insert>";
}

// action is not edit then has to be add mp
print "<tr><td>Username:</td><td><input type=text maxlength=40 name=username value=\"$username\"> (REQUIRED)</td><tr>";
print "<tr><td>Status:</td><td><select name=status_id><option value=\"\"></option>";

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.