Patrick Kirk said: Good Lord - its eaten contacts.php again!

<?php
/*
Setup connection

if ($grouping)
// called as contacts.php?grouping?=blah
// print table with group members
elseif ($lastname)
// called as contacts.php?lastname starts with blah
// print table of suitable last names
elseif ($organisation)
// called as contacts.php?organisation starts with blah
/ print table of suitable organisation names
elseif (person_id)
// called as contacts.php?person_id=blah
// print addedit form
else
//default case
// called as contacts.php and show navigation tools
*/
?>

<?php
require ("config.php");
$db = mysql_pconnect($hostname,$user,$password);
mysql_select_db("contacts",$db);

if ($grouping) {
// called as contacts.php?grouping?=blah
// print table with group members

        printGrouping($grouping);
}
elseif ($person_id) {
        require ("config.php");
        $db = mysql_pconnect($hostname,$user,$password);
        mysql_select_db("contacts",$db);
        $sql = "SELECT * FROM people WHERE person_id=$person_id";
        $result = mysql_query($sql);
        $myrow = mysql_fetch_array($result);
        $person_id = $myrow["person_id"];
        $first_name = $myrow["first_name"];
        $last_name = $myrow["last_name"];
        $organisation = $myrow["organisation"];
        $home_phone = $myrow["home_phone"];
        $work_phone = $myrow["work_phone"];
        $mobile_phone = $myrow["mobile_phone"];
        $dob = $myrow["dob"];
        $email1 = $myrow["email1"];
        $notes = $myrow["notes"];
        $title = $myrow["title"];
        $home_address = $myrow["home_address"];
        $work_address = $myrow["work_address"];
        $grouping = $myrow["grouping"];
?>
                <form method="post" action="contacts.php"><P>
                <body bgcolor="#A0B8C8">
                <input type=hidden name="person_id" value="<?php echo $person_id ?>">
                <title>Contacts/<?php echo $grouping ?>/<?php echo
$first_name?>&nbsp<?php echo $last_name?></title>
                <CENTER><h3><a href=<?php echo $PHP_SELF?>>Contacts</a>&nbsp/
                &nbsp<a href=<?php echo $PHP_SELF?>?grouping=<?php echo
$grouping?>><?php echo $grouping?></a>&nbsp/
                &nbsp<?php echo $first_name?>&nbsp<?php echo $last_name?></h3></CENTER>
                <div align="center">
                <table width="100%" border="1">
                <tr>
                <td>First Name:</td>
                <td><input name="first_name" type="text" id="first_name"
value="<?php echo $first_name ?>" size="30"></td>
                <td>Last Name:</td>
                <td><input name="last_name" type="text" id="last_name"
value="<?php echo $last_name ?>" size="30"></td>
                <td>Organisation:</td>
                <td><input name="organisation" type="text" id="organisation"
value="<?php echo $organisation ?>" size="30"></td>
                </tr>
                <tr>
                <td>Home Phone:</td>
                <td><input name="home_phone" type="text" id="home_phone"
value="<?php echo $home_phone ?>" size="30"></td>
                <td>Work Phone:</td>
                <td><input name="work_phone" type="text" id="work_phone"
value="<?php echo $work_phone ?>" size="30"></td>
                <td>Mobile Phone:</td>
                <td><input name="mobile_phone" type="text" id="mobile_phone"
value="<?php echo $mobile_phone ?>" size="30"></td>
                </tr>
                <tr>
                <td>Email:</td>
                <td><input name="email1" type="text" id="email1" value="<?php
echo $email1 ?>" size="30"></td>
                <td>Title:</td>
                <td><input name="title" type="text" id="title" value="<?php echo
$title?>" size="30"></td>
                <td>Date of birth:</td>
                <td><input name="textfield" type="text" value="<?php echo $dob
?>" size="30"></td>
                </tr>
                </table>
                </div>
                <p align="center">Home Address:
                <input name="home_address" type="text" id="home_address"
value="<?php echo $home_address ?>" size="100">
                </p>
                <p align="center">Work Address:
                <input name="work_address" type="text" id="work_address"
value="<?php echo $work_address ?>" size="100">
                </p>
                <p align="center">Grouping:
                <select name='grouping'>
                        <option><?php echo $grouping ?></option>
                        <option>Club</option>
                        <option>Players</option>
                        <option>Archives</option>
                        <option>Enterprise</option>
                        <option>Business</option>
                        <option>Children</option>
                        <option>Partners</option>
                        <option>Resources</option>
                        <option>Personal</option>
                        <option>Elizabeth Mews</option>
                </select>
                </p>
                <p align="center">Notes:</p>
                <p align="center">
                <textarea name="notes" cols="100" rows="10" id="notes"><?php echo
$notes ?></textarea></p>
                <p align="center">
                <input type="submit" name="submit" value="Enter information">
<?php



}

elseif ($submit) {

  // here if no ID then adding else we're editing

  if ($person_id) {
                require ("config.php");
                $db = mysql_pconnect($hostname,$user,$password);
                mysql_select_db("contacts",$db);
                $sql = "UPDATE people SET
                first_name='$first_name',
                last_name='$last_name',
                organisation='$organisation',
                title='$title',
                home_phone='$home_phone',
                work_phone='$work_phone',
                mobile_phone='$mobile_phone',
                email1='$email1',
                dob='$dob',
                grouping='$grouping',
                home_address='$home_address',
                work_address='$work_address',
                notes='$notes'
                WHERE person_id=$person_id";


  }
else {
        $sql = "INSERT INTO people (
                first_name,
                last_name,
                organisation,
                title,
                home_phone,
                work_phone,
                mobile_phone,
                email1,
                dob,
                grouping,
                home_address,
                work_address,
                notes)
                VALUES (
                '$first_name',
                '$last_name',
                '$organisation',
                '$title',
                '$home_phone',
                '$work_phone',
                '$mobile_phone',
                '$email1',
                '$dob',
                '$grouping',
                '$home_address',
                '$work_address',
                '$notes')";

  }

  // run SQL against the DB

  $result = mysql_query($sql);

   echo "<CENTER><h3><a href=\"index.php\">Contacts</a>&nbsp/&nbsp<a
href=\"index.php?grouping=$grouping\">$grouping</a>&nbsp/&nbsp<a
href=\"addedit.php?person_id=$person_id\">$first_name
$last_name</a></h3>";

  echo "Record updated/edited!<p></CENTER>";



} elseif ($delete) {

        // delete a record
echo "<CENTER><h3><a href=\"index.php\">Contacts</a>&nbsp/&nbsp<a
href=\"index.php?grouping=$grouping\">$grouping</a></h3></CENTER>";

    $sql = "DELETE FROM people WHERE person_id=$person_id";

    $result = mysql_query($sql);


    echo "$sql Record deleted!<p>";






} else {

?>
<title>Contacts</title>
<CENTER>
<H4>Filter by Grouping: </H4>

<form action=<?php echo $PHP_SELF ?>>

<p>Grouping: <select name='grouping'>
<option>Club</option>
<option>Players</option>
<option>Archives</option>
<option>Enterprise</option>
<option>Business</option>
<option>Children</option>
<option>Partners</option>
<option>Resources</option>
<option>Personal</option>
<option>Elizabeth Mews</option>


</select>
</p>
<p><input type='submit' value='Filter'/>

</p></form><body bgcolor="#A0B8C8">
<?php

}

// Function printGrouping($grouping)

function printGrouping($grouping) {
        require ("config.php");
        $db = mysql_pconnect($hostname,$user,$password);
        mysql_select_db("contacts",$db);
        $result = mysql_query("SELECT * FROM people where grouping =
'$grouping'ORDER BY last_name ASC",$db);

        echo "<title>Contacts/$grouping</title>";

        echo "<center><h3><a
href=$PHP_SELF?>Contacts</a>&nbsp/&nbsp$grouping</a></h3></center>";

        echo "<center><a href=\"addedit.php\"> Add a New Contact </a>";

        echo "<table cellpadding=0 cellspacing=0 border=0><tr><td><b>First
Name</b></td><td>&nbsp&nbsp&nbsp</td><td><b>Last
Name</b></td><td>&nbsp&nbsp&nbsp</td><td><b>Organisation</b></td><td>&nbsp&nbsp&nbsp</td><td><b>Details</b></td>";
        $alternate = "2";
        while ($row = mysql_fetch_array($result)) {
                $first_name = $row["first_name"];
                $last_name = $row["last_name"];
                $organisation = $row["organisation"];
                $person_id = $row["person_id"];

                if ($alternate == "1") {
                        $color =  "#A0B8C8";
                        $alternate = "2";
                }
                else {
                        $color =  "#ffffff";
                        $alternate = "1";
                }
                echo "<tr
bgcolor=$color><td>$first_name</td><td>&nbsp&nbsp&nbsp</td><td>$last_name</td><td>&nbsp&nbsp&nbsp</td><td>$organisation</td><td>&nbsp&nbsp&nbsp</td><td><a
href=\"$PHP_SELF?person_id=$person_id\"> More... </a></td></td></tr>";

        }
        // echo "<body bgcolor="#A0B8C8">";
        echo "</center></table></HTML>";
}       // Function printGrouping

?>




-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to