Jump to content


Photo

Recomend a tutorial


  • Please log in to reply
7 replies to this topic

#1 Fearpig

Fearpig
  • Members
  • PipPipPip
  • Advanced Member
  • 195 posts

Posted 11 August 2006 - 11:36 AM

Hello,
Can anyone recomend a tutorial on editing MySQL data with PHP forms. I've tried a hundred ways and I just get stuck.  :'(

Cheers
Tom
"Whats wrong with the cat?" - Mrs Schrödinger

#2 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 11 August 2006 - 11:41 AM

wat do you want to do, retrieve the data from a table in a form for editing.... is it one record at a time or multiple

#3 Fearpig

Fearpig
  • Members
  • PipPipPip
  • Advanced Member
  • 195 posts

Posted 11 August 2006 - 11:46 AM

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.
"Whats wrong with the cat?" - Mrs Schrödinger

#4 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 11 August 2006 - 11:50 AM

email me the link to rberbe2002@msn.com so i can have a look mate

#5 Fearpig

Fearpig
  • Members
  • PipPipPip
  • Advanced Member
  • 195 posts

Posted 11 August 2006 - 11:54 AM

Sorry... its on an IntrAnet server with no public access! The webserver doesn't have PHP / MySQL.
"Whats wrong with the cat?" - Mrs Schrödinger

#6 Fearpig

Fearpig
  • Members
  • PipPipPip
  • Advanced Member
  • 195 posts

Posted 11 August 2006 - 12:01 PM

Can anyone recommend a tutorial or lesson I can download...? ???
"Whats wrong with the cat?" - Mrs Schrödinger

#7 Fearpig

Fearpig
  • Members
  • PipPipPip
  • Advanced Member
  • 195 posts

Posted 11 August 2006 - 02:23 PM

;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
<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>

Edit_Person.php
<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>

Edit_ProcessForm.php
<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>

"Whats wrong with the cat?" - Mrs Schrödinger

#8 HeyRay2

HeyRay2
  • Members
  • PipPipPip
  • Advanced Member
  • 223 posts

Posted 11 August 2006 - 02:46 PM

It looks that should work fine for you.

However, be sure to validate user input before updating the database.

Head to the link below for more information:

http://www.phpfreaks...-injection.html




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users