-
i got it!!! well the link part
i used <a href="edit.php?RegID='.$u['RegID'].'">Edit</a> as the link and it seems to work.
still when i run the edit it does not update. here is the code. can you tell me what i have wrong?
Code:
<?php
require('link.php');
// Get the user id
$id = $_GET['RegID'];
// Get data from user with the specified id
$info = mysql_query("SELECT * FROM `form` WHERE RegID = '$id'") or die ('Error Getting User Data! <br />' .mysql_error());
$chk = mysql_num_rows($info);
$u = mysql_fetch_array($info);
// If edit not hit
if (!$_POST['edit']) {
// If user id returns no results
if ($chk < 1) {
echo 'The user with the id <b>'.$id.'</b> does not exist!';
}
else {
// Edit Form
?>
<!-- Edit Form -->
<form method="post" action="">
<table width="250">
<tr>
<td>First Name:</td>
<td><input type="text" name="firstname" value="<?php echo $u['FName'] ?>" /></td>
</tr>
<tr>
<td>Last Name:</td>
<td><input type="text" name="lastname" value="<?php echo $u['LName'] ?>" /></td>
</tr>
<tr>
<td>Username:</td>
<td><input type="text" name="EMail" value="<?php echo $u['EMail'] ?>" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="edit" value="Edit" /></td>
</tr>
</table>
</form>
<!-- /Edit Form -->
<?
}
// If edit was hit
if ($_POST['edit']) {
$firstname = $_POST['FName'];
$lastname = $_POST['LName'];
$username = $_POST['EMail'];
// Update data
$update = mysql_query("UPDATE `form` SET FName = '$FName', LName = '$LName', EMail = '$EMail' WHERE RegID = '$id'") or die ('Error Updating Data! <br />' .mysql_error());
echo 'Update successfull';
}
}
?>
-
Ok, here is what you would do to add a delete function. The first part is the delete link.
PHP Code:
<?php
echo '<a href="index.php?act=chk_del&id='.$qry['id'].'">[X]</a>';
// If delete was hit, ask for confirm
if ($_GET[['act'] == 'chk_del') {
$id = $_GET['id'];
echo 'Are you sure you want to delete this user?
<br />
<a href="index.php?act=delete&id='.$id.'">Yes, delete it</a> | <a href="javascript:history.back();">Cancel</a>';
}
// If delete confirmed
elseif ($_GET['act'] == 'delete') {
$id = $_GET['id'];
$del = mysql_query("DELETE FROM `form` WHERE id ='$id'") or die ('Error Deleting User! <br />' .mysql_error());
echo 'The user has been deleted.
<br />
<a href="index.php">Back To Main</a>';
}
?>
It has a confirm delete before it actually deletes.
As for your edit problem, I will take a look when I get home, got to be heading out at the moment.
Hope this helps
-
i have just tried your code above. it runs through fine, but doesnt seem to do anything. i still have the record i was deleting. see for yourself at www.beinhealth.com/form/bih.html and then click on search by last name. enter mcleod in there. you can click on edit or delete there. neither give errors, just done do the function. i am stumped
-
here is the code i am using for all of three pages incase it is any one of them.
first the search one
Code:
<?php
require('link.php');
// If search is active
if ($_POST['search']) {
$date = $_POST['LName'];
// Get results from database
$users = mysql_query("SELECT * FROM `form` WHERE LName = '$date' ORDER BY RegID DESC") or die ('Error Getting Users! \n<br />\n' .mysql_error());
$chk = mysql_num_rows($users);
// If no users found
if ($chk < 1) {
echo 'There are no users registered on the date: <b>'.$date.'</b>
<br />
<a href="bih.html"><<Back</a>';
}
// If there are users
// If there are users
else {
// Start table to display users
echo '
<h3>Users Registerd With Last Name of '.$date.'</h3>
<table border="1">
<tr>
<td></td><td></td>
<td><b>First Name</b></td>
<td><b>Last Name</b></td>
<td><b>Date Attending</b></td>
<td><b>Email</b></td>
<td><b>Phone Number</b></td>
</tr>';
// For each user found
while($u = mysql_fetch_array($users)) {
// Show data for each user
echo '
<tr>
<td><a href="edit.php?RegID='.$u['RegID'].'">Edit</a></td>
<td><a href="delete.php?act=chk_del&id='.$qry['RegID'].'">Delete</a></td>
<td>'.$u['RegID'].'</td>
<td>'.$u['FName'].'</td>
<td>'.$u['LName'].'</td>
<td>'.$u['Date'].'</td>
<td>'.$u['EMail'].'</td>
<td>'.$u['Phone'].'</td>
</tr>';
}
// End table
echo '
</table><br><br><a href="bih.html">Back</a>';
}
}
// If form was not submitted
if (!$_POST['search']) {
echo '
<form method="post" action="">
<b>Last Name:</b> <input type="text" name="LName" />
<input type="submit" name="search" value="Search" />
</form><br><br><a href="bih.html">Back</a>';
}
if ($_GET['act'] == 'edit') {
require('edit.php');
}
?>
next the edit one:
Code:
<?php
require('link.php');
// Get the user id
$RegID = $_GET['RegID'];
// Get data from user with the specified id
$info = mysql_query("SELECT * FROM `form` WHERE RegID = '$RegID'") or die ('Error Getting User Data! <br />' .mysql_error());
$chk = mysql_num_rows($info);
$u = mysql_fetch_array($info);
// If edit not hit
if (!$_POST['edit']) {
// If user id returns no results
if ($chk < 1) {
echo 'The user with the id <b>'.$RegID.'</b> does not exist!';
}
else {
// Edit Form
?>
<!-- Edit Form -->
<form method="post" action="">
<table width="250">
<tr>
<td>First Name:</td>
<td><input type="text" name="firstname" value="<?php echo $u['FName'] ?>" /></td>
</tr>
<tr>
<td>Last Name:</td>
<td><input type="text" name="lastname" value="<?php echo $u['LName'] ?>" /></td>
</tr>
<tr>
<td>Username:</td>
<td><input type="text" name="EMail" value="<?php echo $u['EMail'] ?>" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="edit" value="Edit" /></td>
</tr>
</table>
</form>
<!-- /Edit Form -->
<?
}
// If edit was hit
if ($_POST['edit']) {
$firstname = $_POST['FName'];
$lastname = $_POST['LName'];
$username = $_POST['EMail'];
// Update data
$update = mysql_query("UPDATE `form` SET FName = '$FName', LName = '$LName', EMail = '$EMail' WHERE RegID = '$RegID'") or die ('Error Updating Data! <br />' .mysql_error());
echo 'Update successfull
<br />
<a href="bih.html">Back To Main</a>';
}
}
?>
last the delete one:
Code:
<?php
require('link.php');
// If delete was hit, ask for confirm
if ($_GET['act'] == 'chk_del') {
$RegID = $_GET['RegID'];
echo 'Are you sure you want to delete this user?
<br />
<a href="delete.php?act=delete&RegID='.$RegID.'">Yes, delete it</a> | <a href="javascript:history.back();">Cancel</a>';
}
// If delete confirmed
elseif ($_GET['act'] == 'delete') {
$RegID = $_GET['RegID'];
$del = mysql_query("DELETE FROM `form` WHERE RegID ='$RegID'") or die ('Error Deleting User! <br />' .mysql_error());
echo 'The user has been deleted.
<br />
<a href="bih.html">Back To Main</a>';
}
?>
man sorry for all the trouble i am causing you. i really appreciate the help though.
-
ok, figured out the edit part. had a ] at the end instead of at the end of the first if (edit) statment. now working in delete.
-
What you need to do is change this:
Code:
<a href="delete.php?act=delete&id='.$RegID.'">
To this:
Code:
<a href="delete.php?act=delete&RegID='.$RegID.'">
In your main page that displays the delete link and it should work.
Hope this helps out.
Also, if you don't mind, could you tell me how you got it to force the download of the text file rather than just display it? I would really like to learn that. Thanks
-
i will give that a try. here is what i used to export. it is your code that i just tweeked a bit. mostly changing the document type to attachment.
PHP Code:
<?php
require('link.php');
// If search is active
if ($_POST['search']) {
$date = $_POST['date'];
// Get results from database
$users = mysql_query("SELECT * FROM `form` WHERE Date = '$date' ORDER BY RegID DESC") or die ('Error Getting Users! \n<br />\n' .mysql_error());
$chk = mysql_num_rows($users);
// If no users found
if ($chk < 1) {
echo 'There are no users registered on the date: <b>'.$date.'</b>
<br />
<a href="bih.html"><<Back</a>';
}
// If there are users
else {
// Set header to download users
header("Content-type: text/plain");
header("Content-disposition: attachment; filename=Registered.TXT");
// For each user found
while($u = mysql_fetch_array($users)) {
// Show data for each user
echo $u['FName'].'|'.$u['LName'].'|'.$u['EMail'].'|'.$u['Phone'].'|'.$u['Address'].'|'.$u['City'].'|'.$u['State'].'|'.$u['Zip'].'|'.$u['OState'].'|'.$u['Country'].'|'.$u['DOB'].'|'.$u['Occ'].'|'.$u['Meds'].'|'.$u['Married'].'|'.$u['Accom'].'|'.$u['ReadAMEW'].'|'.$u['ListenTapes'].'|'.$u['AttendSeminar'].'|'.$u['AttendWhere'].'|'.$u['Knowledge'].'|'.$u['KnowledgeHow'].'|'.$u['Issues1'].'|'.$u['Issues2'].'|'.$u['Issues3'].'|'.$u['Issues4'].'|'.$u['Comments']."\n";
}
// End table
}
}
// download on click
if (!$_POST['search']) {
echo ' <center><h2>Download Program Signups.</h2></center><br><br>
<form method="post" action="">
<b>Date:</b> <input type="text" name="Date" value="">
<input type="submit" name="search" value="Search" />
</form><br><br><br><a href="bih.html"><<Back</a>';
}
?>
hope that helps you. you have been a huge help. much appreciation.
-
still not deleting though. i am going over the code hoping to find it. if you have any other ideas..... would be much appreciated.
-
Never mind... i got it. bah it is always the little things.
thanks for your help. you have saved me a ton of head scratching
brent
-
Thanks for showing me how to make it download. Glad to hear you got it working. Was it just the link like I said or something else?