I am creating a RSVP management system for a site. I have already created a page that displays all the results of people who have already registered. I want to be able to create a link on each row that allows the information to be brought up in another page and allows me to edit or delete the information. My thought is that I could but all the information in corresponding text boxes and make the values the original information. I could then change the values and use a update php script.
Could really use some help on this, as I am still a beginner at PHP and MYSQL. Will post code if it will make i easier, but really looking for the code that I would add in the loop on the display page and then the code for an edit.php page that will get the information from only the row selected.
[code=php]echo "<td><a href="edit.php?id=$row['id']">Edit</a></td><td><a href="delete.php?id=$row['id']">Delete</a></td>";[/code]
[code=php]$member_id = $_GET['id'];
$results = mysql_query("select * from member where id = $member_id");
$row = mysql_fetch_assoc($results);[/code]
[code=php]header("Location: index.php"); // bring back to original page
$member_id = $_GET['id'];
mysql_query("delete from member where id = $member_id limit 1");[/code]
[code=php]<?php
// Retrieve data from database
$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
// Start looping rows in mysql database.
while($rows=mysql_fetch_array($result)){
?>
<div align="center">
<table width="80%" border="0" cellspacing="0" cellpadding="5">
<tr>
<td width="10%"><a href="edit.php?id=$row['id']">Edit</a></td><td><a href="delete.php?id=$row['id']">Delete</a></td>
<td width="20%" valign="top" class="accomodations">
1. <? echo $rows['guest_1']; ?><br>
2. <? echo $rows['guest_2']; ?><br>
3. <? echo $rows['guest_3']; ?><br>
4. <? echo $rows['guest_4']; ?><br>
5. <? echo $rows['guest_5']; ?></td>
<td width="10%" valign="top" align="center" class="accomodations"><? echo $rows['total_guests']; ?></td>
<td width="10%" valign="top" align="center" class="accomodations"><? echo $rows['vegetarian']; ?></td>
<td width="22%" valign="top" class="accomodations"><? echo $rows['email']; ?></td>
<td width="18%" valign="top" class="accomodations"><? echo $rows['accomodations']; ?></td>
</tr>
<hr width="80%" align="center">
</table>
</div>
<?
// close while loop
}
// close connection
mysql_close();
?>[/code]
[code=php]<?php
session_start();
if (@$_SESSION['auth'] !="yes")
{
header("Location: login_form.php");
exit();
}
?>
<?php
$host="localhost";
$username="username";
$password="password";
$db_name="db_namer";
$tbl_name="table";
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$member_id = $_GET['id'];
$results = mysql_query("select * from member where id = $member_id");
$row = mysql_fetch_assoc($results);
?>
<html>
<head>
<link href="style.css" type="text/css" rel="stylesheet">
</head>
<body>
<div align="center">
<table width="80%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td>Guest 1 <input type="text" value="<? echo $row['guest_1']; ?>" name="guest_1"></td>
</tr>
</div>
</body>
</html>[/code]
[code=php]<?php
$host="localhost";
$username="username";
$password="password";
$db_name="db_namer";
$tbl_name="table";
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
header("Location: rsvp_view.php"); // bring back to original page
$member_id = $_GET['id'];
mysql_query("delete from member where id = $member_id limit 1");
?>[/code]
[code=php]<td width="10%"><a href="edit.php?id=$row['id']">Edit</a></td><td><a href="delete.php?id=$row['id']">Delete</a></td>[/code]
[code=php]<td width="10%"><a href="edit.php?id=<?php echo $rows['id']; ?>">Edit</a></td><td><a href="delete.php?id=<?php echo $rows['id']; ?>">Delete</a></td>[/code]
[code=php]<?php
session_start();
if (@$_SESSION['auth'] !="yes")
{
header("Location: login_form.php");
exit();
}
?>
<html>
<head>
<link href="style.css" type="text/css" rel="stylesheet">
</head>
<body>
<div align="center">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td height="30"></td>
</tr>
<tr>
<td class="header" align="center">RSVP Results</td>
</tr>
<tr>
<td height="20"></td>
</tr>
<tr>
<td align="center" class="accomodations">
<form name="form" action="search.php" method="get">
Search Registrants <input type="text" name="q" />
<input type="submit" name="Submit" value="Search" />
</form>
</td>
</tr>
</table>
</div>
<?php
$host="localhost";
$username="usernamer";
$password="password";
$db_name="db_name";
$tbl_name="table";
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$total_result = mysql_query( "SELECT guest_1, guest_2, guest_3, guest_4, guest_5, total_guests, email, vegetarian, accomodations FROM guests" )
or die("SELECT Error: ".mysql_error());
$num_rows = mysql_num_rows($total_result);
$vegetarian = mysql_query( "SELECT SUM(vegetarian) FROM guests");
$total_vegetarian = mysql_result($vegetarian, 0)
or die(mysql_error());
$guests = mysql_query( "SELECT SUM(total_guests) FROM guests" );
$total_guests = mysql_result($guests, 0)
or die(mysql_error());
$email = mysql_query("SELECT email FROM guests");
?>
<div align="center">
<table width="80%" border="0" cellspacing="0" cellpadding="5">
<tr>
<td height="20"></td>
</tr>
<tr>
<td class="accomodations" width="33%"><b>Total Replies:</b> <? echo $num_rows; ?></td>
<td class="accomodations" width="33%"><b>Total Number of Guests:</b> <? echo $total_guests; ?></td>
<td class="accomodations" width="33%" align="center"><b>Total # of Vegetarian Meals:</b> <? echo $total_vegetarian; ?></td>
</tr>
<tr>
<td height="20"></td>
</tr>
</table>
<table width="80%" border="0" cellspacing="0" cellpadding="5">
<tr>
<td width="10%"></td>
<td width="20%" class="accomodations"><b>Guests</b></td>
<td width="10%" align="center" class="accomodations"><b>Total Guests</b></td>
<td width="10%" align="center" class="accomodations"><b>Veg. Meals</b></td>
<td width="22%" class="accomodations"><b>Email</b></td>
<td width="18%" class="accomodations"><b>Accomodations</b></td>
</tr>
</table>
</div>
<?php
// Retrieve data from database
$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
// Start looping rows in mysql database.
while($rows=mysql_fetch_array($result)){
?>
<div align="center">
<table width="80%" border="0" cellspacing="0" cellpadding="5">
<tr>
<td width="10%"><a href="edit.php?id=<?php echo $rows['id']; ?>">Edit</a></td><td><a href="delete.php?id=<?php echo $rows['id']; ?>">Delete</a></td>
<td width="20%" valign="top" class="accomodations">
1. <? echo $rows['guest_1']; ?><br>
2. <? echo $rows['guest_2']; ?><br>
3. <? echo $rows['guest_3']; ?><br>
4. <? echo $rows['guest_4']; ?><br>
5. <? echo $rows['guest_5']; ?></td>
<td width="10%" valign="top" align="center" class="accomodations"><? echo $rows['total_guests']; ?></td>
<td width="10%" valign="top" align="center" class="accomodations"><? echo $rows['vegetarian']; ?></td>
<td width="22%" valign="top" class="accomodations"><? echo $rows['email']; ?></td>
<td width="18%" valign="top" class="accomodations"><? echo $rows['accomodations']; ?></td>
</tr>
<hr width="80%" align="center">
</table>
</div>
<?
// close while loop
}
// close connection
mysql_close();
?>
</body>
</html>[/code]
[code=php]<?php
session_start();
if (@$_SESSION['auth'] !="yes")
{
header("Location: login_form.php");
exit();
}
?>
<?php
$host="localhost";
$username="usernamer";
$password="password";
$db_name="db_name";
$tbl_name="table";
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$member_id = $_GET['id'];
$results = mysql_query("select * from member where id = $member_id");
$row = mysql_fetch_assoc($results);
?>
<html>
<head>
<link href="style.css" type="text/css" rel="stylesheet">
</head>
<body>
<div align="center">
<table width="80%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td>Guest 1 <input type="text" value="<? echo $row['guest_1']; ?>" name="guest_1"></td>
</tr>
</div>
</body>
</html>[/code]
[code=php]<?php
$host="localhost";
$username="usernamer";
$password="password";
$db_name="db_name";
$tbl_name="table";
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
header("Location: rsvp_view.php"); // bring back to original page
$member_id = $_GET['id'];
mysql_query("delete from member where id = $member_id limit 1");
?>[/code]
Ok I figured out what was going wrong. My SQL table did not have an 'id' column. Once I added one, presto everything worked. Thanks for the help.[/QUOTE]
$result = mysql_query("select * from people where id = $update");
$row = mysql_fetch_assoc($result);
<form action="update.php" method="post">
ID: <input type="text" name="id" value="<?php echo $row["id"] ?>" />
FirstName: <input type="text" name="first_name" value="<?php echo $row["first_name"]?>" />
<br />
LastName: <input type="text" name="last_name" value="<?php echo $row["last_name"] ?>" />
<br />
Phone#: <input type="text" name="ph_no" value="<?php echo $row["ph_no"] ?>" />
<br />
<br />
<input type="submit" name="submit" />
</form>
in your sql table, you need to have a column "id" that auto-increments.[/QUOTE]
0.1.9 — BETA 6.16