Jump to content

Recomend a tutorial


Fearpig

Recommended Posts

Hi,
Basically its a telephone book. I want to list all names as links. When you click on the link it takes you to a form where you can edit the details for that person (first_name, last_name, role, number, department... etc.) .

It seems simple enough and I can get most of it working but the last few steps seem to outwit everybody so I was going back to basics.
Link to comment
Share on other sites

;D

Went back to basics and did it already..... just incase anyone else was having the same issue.... or thinking about it can anyone spot a problem with doing it this way?

I did this in three pages:

1. list of clickable names that link to a form - Edit_ListPeople.php
2. A form to fill out and post results - Edit_Person.php
3. A page to process the form contents - Edit_ProcessForm.php

Edit_ListPeople.php
[code]
<html>
<head>
</head>
<body>
<?php

$db = mysql_connect("localhost", "root", "password");

mysql_select_db("Telephonelist",$db);

$result = mysql_query("SELECT * FROM tbl_telephonenumbers",$db);

echo "<table border=1>\n";

echo "<tr><td><b>Name</b></td><td><b>Position</b></tr>\n";
//colum names

while ($myrow = mysql_fetch_array($result)) {

printf("<tr><td><a href=\"%s?id=%s\">%s %s</a></td><td>%s</td></tr>\n",
//lay out results 2 in the first column and 1 in the second
"Edit_Person.php", $myrow["ID"], $myrow["First_Name"], $myrow["Last_Name"], $myrow["Role"]);



}
echo "</table>\n";

?>

</body>
</html>
[/code]

Edit_Person.php
[code]
<html>
<head>
</head>
<body>
<?php

$db = mysql_connect("localhost", "root", "password");
mysql_select_db("Telephonelist",$db);

$id = $_GET["id"];
$sql = "SELECT * FROM tbl_telephonenumbers WHERE ID=$id";
$result = mysql_query($sql);       
$myrow = mysql_fetch_array($result);
?>
   
        <form action="Edit_ProcessForm.php" method="post">
        <input type=hidden name="Frm_ID" value="<?php echo $myrow["ID"] ?>">
 
        First Name:<INPUT TYPE="TEXT" NAME="Frm_First" VALUE="<?php echo $myrow["First_Name"] ?>" SIZE=30><br>
        Last Name:<INPUT TYPE="TEXT" NAME="Frm_Last" VALUE="<?php echo $myrow["Last_Name"] ?>" SIZE=30><br>
        Role:<INPUT TYPE="TEXT" NAME="Frm_Role" VALUE="<?php echo $myrow["Role"] ?>" SIZE=30><br>
 
        <input type="hidden" name="cmd" value="edit">
        <input type="submit" name="submit" value="submit">
 
          </form>

</body>
</html>
[/code]

Edit_ProcessForm.php
[code]
<html>
<head>
</head>
<body>
<?php

$db = mysql_connect("localhost", "root", "password");
mysql_select_db("Telephonelist",$db);

$id = $_POST["Frm_ID"];
$First = $_POST["Frm_First"];
$Last = $_POST["Frm_Last"];
$Role = $_POST["Frm_Role"];
   
$sql = "UPDATE tbl_telephonenumbers SET First_Name='$First',Last_Name='$Last',Role='$Role' WHERE ID=$id";
//replace news with your table name above
$result = mysql_query($sql);
echo "Thank you! Information updated.";
echo "<br>";
echo "<a href='index.htm'>Click here to return to the phone index</a>";


?>

</body>
</html>
[/code]
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.