Hi,
heres what i am trying to do. I created a script that adds the entered information into the database and now i am trying to create one that will display the information entered by selecting which user you want to show. In short the script should list the names of the people in the database and that it does what it does not do is display their information when the user is selected and the button clicked. Below is the code: Thanks in advance for the help guys!
<?php
//connect to database
$conn = mysql_connect("localhost", "user", "pass") or die(mysql_error());
mysql_select_db("TestDB",$conn) or die(mysql_error());
if ($_POST[op] != "delete"){
//haven't seen the form, so show it
$display_block = "<h1>Select an Entry</h1>";
//get parts of records
$get_list = "select id, concat_ws(', ', l_name, f_name) as display_name from master_name order by l_name, f_name";
$get_list_res = mysql_query($get_list) or die(mysql_error());
if (mysql_num_rows($get_list_res) < 1) {
//no records
$display_block .= "<p><em>Sorry, no records to select!</em></p>";
} else {
//has records, so get results and print in a form
$display_block .= "
<form method=\"post\" action=\"$_SERVER[PHP_SELF]\">
<P><strong>Select a Record to Delete:</strong><br>
<select name=\"sel_id\">
<option value=\"\">-- Select One --</option>";
while ($recs = mysql_fetch_array($get_list_res)) {
$id = $recs['id'];
$display_name = stripslashes($recs['display_name']);
$display_block .= "<option value=\"$id\">
$display_name</option>";
}
$display_block .= "
</select>
<input type=\"hidden\" name=\"op\" value=\"view\">
<p><input type=\"submit\" name=\"submit\" value=\"View Selected Entry\"></p>
</FORM>";
}
} else if ($_POST[op] == "delete") {
//check for required fields
if ($_POST[sel_id] == "") {
header("Location: selentry.php");
exit;
}
//get master_info
$get_master = "select concat_ws(' ', f_name, l_name) as display_name from master_name where id = $_POST[sel_id]";
$get_master_res = mysql_query($get_master);
$display_name = stripslashes(mysql_result($get_master_res, 0,'display_name'));
$display_block = "<h1>Showing Record for $display_name</h1>";
//get all addresses
$get_addresses = "select address, city, state, zipcode, type from address where master_id = $_POST[sel_id]";
$get_addresses_res = mysql_query($get_addresses);
if (mysql_num_rows($get_addresses_res) > 0) {
$display_block .= "<P><strong>Addresses:</strong><br>
<ul>";
while ($add_info = mysql_fetch_array($get_addresses_res)) {
$address = $add_info[address];
$city = $add_info[city];
$state = $add_info[state];
$zipcode = $add_info[zipcode];
$address_type = $add_info[type];
$display_block .= "<li>$address $city $state $zipcode ($address_type)";
}
$display_block .= "</ul>";
}
//get all tel
$get_tel = "select tel_number, type from telephone where master_id = $_POST[sel_id]";
$get_tel_res = mysql_query($get_tel);
if (mysql_num_rows($get_tel_res) > 0) {
$display_block .= "<P><strong>Telephone:</strong><br>
<ul>";
while ($tel_info = mysql_fetch_array($get_tel_res)) {
$tel_number = $tel_info[tel_number];
$tel_type = $tel_info[type];
$display_block .= "<li>$tel_number ($tel_type)";
}
$display_block .= "</ul>";
}
//get all fax
$get_fax = "select fax_number, type from fax where master_id = $_POST[sel_id]";
$get_fax_res = mysql_query($get_fax);
if (mysql_num_rows($get_fax_res) > 0) {
$display_block .= "<P><strong>Fax:</strong><br>
<ul>";
while ($fax_info = mysql_fetch_array($get_fax_res)) {
$fax_number = $fax_info[fax_number];
$fax_type = $fax_info[type];
$display_block .= "<li>$fax_number ($fax_type)";
}
$display_block .= "</ul>";
}
//get all email
$get_email = "select email, type from email where master_id = $_POST[sel_id]";
$get_email_res = mysql_query($get_email);
if (mysql_num_rows($get_email_res) > 0) {
$display_block .= "<P><strong>Email:</strong><br>
<ul>";
while ($email_info = mysql_fetch_array($get_email_res)) {
$email = $email_info[email];
$email_type = $email_info[type];
$display_block .= "<li>$email ($email_type)";
}
$display_block .= "</ul>";
}
//get personal note
$get_notes = "select note from personal_notes where master_id = $_POST[sel_id]";
$get_notes_res = mysql_query($get_notes);
if (mysql_num_rows($get_notes_res) == 1) {
$note = nl2br(stripslashes(mysql_result($get_notes_res,0,'note')));
$display_block .= "<P><strong>Personal Notes:</strong><br>$note";
}
$display_block .= "<br><br><P align=center><a href=\"$_SERVER[PHP_SELF]\">select another</a></p>";
}
?>
<HTML>
<HEAD>
<TITLE>My Records</TITLE>
</HEAD>
<BODY>
<? print $display_block; ?>
</BODY>
</HTML>