Jump to content

Recommended Posts

I want to be able to update a record from a MySQL database from the page that displays the data on this page http://flw.org/memberships/admin/index.php. I just want to be able to click on the ID number and have it open to the edit(update) page. I have the query set up but I'm not sure how to link the ID number. Would I do something like this: <a href="'.$memberID.'">'.$memberID.'</a> or would it be something like <a href="'.$memberID.'&edit=edit&memberID = $memberID">'.$memberID.'</a>

Link to comment
https://forums.phpfreaks.com/topic/145577-not-sure-how-to-do-this/
Share on other sites

The link should be similar to: *Not tested*

 


 

Then when you grab it on the next page (your_page.php), use the GET method:

 

$memberID = $_GET['memberID'];
$query = "SELECT * FROM members WHERE memberID = '$memberID'";
//blah blah blah

I still cannot get this to work. I want to be able to click on the memberID and have the page open to the edit page. I tried <a href="./update2.php?edit=edit&memberID=<?php echo $memberID; ?>">'.$memberID.'</a> but it did not work. I know there's a way to do this but I cannot figure it out. Here's the sql info maybe I'm missing something here:

case 'editmember':
// 
foreach($_POST as $key=>$value){
$$key = $value;
}

// if the form has been submited ($_POST['Submit) 
if(isset($Submit))

// if form has been submited process the form
 {

// 
foreach($_POST as $key=>$value){
$$key = ValidateInput($value);
}

if($edit == 'edit') {

// update record with the posted data into the database
mysql_query("UPDATE members SET memberID='$memberID',firstName='$firstName', lastName='$lastName',firstName2='$firstName2', lastName2='$lastName2',address='$address', city='$city',state='$state', zip='$zip', telephone='$telephone', email='$email',expiration='$expiration', type='$type', childName='$childName',interests='$interests', dateAdded='$dateAdded', updated='$updated', additionalNotes='$additionalNotes' WHERE memberID = ".NumValidate($memberID)."");
// echo a successfull message and redirect to another page
echo '<center><b>Record successfully updated</b><br /><br />Please wait while you are redirected ...</center><br /><br />
<meta http-equiv="refresh" content="2; url=./index.php">';

 

here's how I have the data diplay page set up:

echo '<tr>
<td class="display"><a href="includes/update2.php?edit=edit&memberID=<?php echo $memberID; ?>">'.$memberID.'</a></td>
<td width="150px" class="display">'.$firstName.' '.' '.$lastName.'</td>
<td class="display">'.$firstName2.' '.' '.$lastName2.'</td>
<td width="300px" class="display">'.$address.' <br> '.$city.' '.' '.$state.' '.' '.$zip.'</td>
<td width="200px" class="display">'.$telephone.'</td>
<td class="display"><a href="mailto:'.$email.'">'.$email.'</a></td>
<td class="display">'.$expiration.'</td>
<td class="display">'.$type.'</td>
<td width="150px" class="display">'.$childName.'</td>
<td class="display">'.$interests.'</td>
<td width="200px" class="display">'.$dateAdded.'</td>
<td width="150px" class="display">'.$updated.'</td>
<td class="display">'.$additionalNotes.'</td>
</tr>';
}
?>

What doesn't work?  Does it not update?  Does the page load?  Are there errors?

 

I'm getting confused.  First you said you wanted links that pass the ID to the update page to process the information.  Here are a couple of things that could/are wrong:

 

1) You never assign $memberID = $_GET['memberID'];

 

2) Your query could be wrong, I would suggest something such as: (so you can debug)

 

$query = "UPDATE members SET memberID='$memberID',firstName='$firstName', lastName='$lastName',firstName2='$firstName2', lastName2='$lastName2',address='$address', city='$city',state='$state', zip='$zip', telephone='$telephone', email='$email',expiration='$expiration', type='$type', childName='$childName',interests='$interests', dateAdded='$dateAdded', updated='$updated', additionalNotes='$additionalNotes' WHERE memberID = ".NumValidate($memberID)."";
echo $query;
mysql_query($query) or die(mysql_error());

 

3) I also have no clue where the POSTs are coming from.  Maybe you could post the form as well, make sure to label each page.

 

4) Are you sure you don't want: (notice the extra dot)

 

../update2.php

 

rather than

 

./update2.php

 

 

 

 

your data is already being echoed so no need to use <?echo?> inside an echo

 

 

<a href="your_page.php?memberID='.$memberID.'">'.$memberID.'</a>

 

the next page  your_page.php

 

remember to use

 

$memberID= $_GET["memberID"];

$query = "SELECT * FROM members WHERE memberID = '$memberID'";

 

hard to see without the coding you already have although in url links i would use a shorter thing which is harder for users to work out like

 

<a href="your_page.php?mid='.$memberID.'">'.$memberID.'</a>

 

$memberID= $_GET["mid"];

$query = "SELECT * FROM members WHERE memberID = '$memberID'";

 

 

 

sorry i am tired just edited this 3 times

 

 

 

ok the link formed like this <a href="../admin/includes/update2.php?edit=edit&memberID='.$memberID.'">'.$memberID.'</a> worked in that it showed the correct ID number when clicked. But the page stays blank - in the url you can see the correct ID based on what was clicked. Here's the form used for the edit:

echo '<form name="description" method="post" action="'.$_SERVER['PHP_SELF'].'?action=editmember">
 	<table width="95%" align="center" cellpadding="4" cellspacing="1">
   <tr> 
   <td align="center"><b>Edit FLW Member</b>This is the record of:<span style="color:#FF0000; font-size: 11px; font-family:Arial, Helvetica, sans-serif;"> <? '.$firstName.' '.' '.$lastName.'?></span>
</td>
   </tr>
   <tr> 
   <td> </td>
   </tr>
   <tr>
   <td align="center"><input name="memberID" type="text" value="<? echo $memberID ?>" /></td>
   </tr>
 <tr>
   <td align="center"><input name="firstName" type="text" value="<? echo $firstName ?>" /></td>
   </tr>
   <tr>
   <td align="center"><input name="lastName" type="text" value="<? echo $lastName ?>" /></td>
   </tr>
 <tr>
   <td align="center"><input name="firstName2" type="text" value="<? echo $firstName2 ?>" /></td>
   </tr>
   <tr>
   <td align="center"><input name="lastName2" type="text" value="<? echo $lastName2 ?>" /></td>
   </tr>
 <tr>
   <td align="center"><input name="address" type="text" value="<? echo $address ?>" /></td>
   </tr>
   <tr>
   <td align="center"><input name="city" type="text" value="<? echo $city ?>" /></td>
   </tr>
 <tr>
   <td align="center"><input name="state" type="text" value="<? echo $state ?>" /></td>
   </tr>
	 <tr>
   <td align="center"><input name="zip" type="text" value="<? echo $zip ?>" /></td>
   </tr>
 <tr>
   <td align="center"><input name="telephone" type="text" value="<? echo $telephone?>" /></td>
   </tr>
   <tr>
   <td align="center"><input name="email" type="text" value="<? echo $email ?>" /></td>
   </tr>
 <tr>
   <td align="center"><input name="expiration" type="text" value="<? echo $expiration ?>" /></td>
   </tr>
 <tr>
   <td align="center"><input name="type" type="text" value="<? echo $type?>" /></td>
   </tr>
   <tr>
   <td align="center"><input name="childName" type="text" value="<? echo $childName ?>" /></td>
   </tr>
 <tr>
   <td align="center"><input name="interests" type="text" value="<? echo $interests ?>" /></td>
   </tr>
 <tr>
   <td align="center"><input name="dateAdded" type="text" value="<? echo $dateAdded?>" /></td>
   </tr>
   <tr>
   <td align="center"><input name="updated" type="text" value="<? echo $updated ?>" /></td>
   </tr>
 <tr>
   <td align="center"><input name="additionalNotes" type="text" value="<? echo $additionalNotes ?>" /></td>
   </tr>
   <tr>
   <td align="center">
<input name="edit" type="hidden" value="'.$_REQUEST['edit'].'" />
<input name="memberID" type="hidden" value="'.$_REQUEST['memberID'].'" />
   <input type="submit" name="Submit" value="Submit">
</td>
   </tr>
 	</table>
</form>';
}

should this <input name="memberID" type="hidden" value="'.$_REQUEST['memberID'].'" /> be changed to <input name="memberID" type="hidden" value="'.$_GET['memberID'].'" />?

 

Never mind - that didn't work

I did that - still no luck

Here's the code - I've been staring at this for hours. I'm sure the answer is right in front of me but I can't see it.

case 'editmember':
// this also converts all post varibles 
foreach($_POST as $key=>$value){
$$key = $value;
}

// if the form has been submited ($_POST['Submit) 
if(isset($Submit))

// if form has been submited process the form
 {

// 
foreach($_POST as $key=>$value){
$$key = ValidateInput($value);
}

if($edit == 'edit') {
$memberID = $_GET['memberID'];

// update record with the posted data into the database
mysql_query("UPDATE members SET memberID='$memberID',firstName='$firstName', lastName='$lastName',firstName2='$firstName2', lastName2='$lastName2',address='$address', city='$city',state='$state', zip='$zip', telephone='$telephone', email='$email',expiration='$expiration', type='$type', childName='$childName',interests='$interests', dateAdded='$dateAdded', updated='$updated', additionalNotes='$additionalNotes' WHERE memberID = ".NumValidate($memberID)."");

// echo a successfull message and redirect to another page
echo '<center><b>Record successfully updated</b><br /><br />Please wait while you are redirected ...</center><br /><br />
<meta http-equiv="refresh" content="2; url=./index.php">';

}else{

// add new record inserting the posted data into the database
mysql_query("INSERT INTO members (memberID,firstName, lastName,firstName2, lastName2,address, city,state, zip, telephone, email,expiration, type, childName,interests, dateAdded, updated, additionalNotes) VALUES ('$memberID','$firstName','$lastName','$firstName2','$lastName2','$address','$city','$state','$zip','$telephone','$email','$expiration','$type','$childName','$interests','$dateAdded','$updated','$additionalNotes')");
// echo a successfull message and redirect to another page
echo '<center><b>Record successfully added</b><br /><br />Please wait while you are redirected ...</center><br /><br />
<meta http-equiv="refresh" content="2; url=./index.php">';

}

//--------------

// else display the form again because $error_msg was not empty
}else{

// grab the data from databse to display in text fields for editing
$sql = mysql_query("SELECT * FROM members WHERE memberID ='".NumValidate($_GET['memberID'])."'");
while ($row = mysql_fetch_array($sql)) {
foreach($row as $key=>$value){
$$key = stripslashes($value);
  }
}

// this is the form posting to case 'addnews':
// notice $error_msg, if its not empty it will echo the message created above
// buttons() displays the buttons created in clean.php for the BBcode
echo '<form name="description" method="post" action="'.$_SERVER['PHP_SELF'].'?action=editmember">
  	<table width="95%" align="center" cellpadding="4" cellspacing="1">
    <tr> 
    <td align="center"><b>Edit FLW Member</b>This is the record of:<span style="color:#FF0000; font-size: 11px; font-family:Arial, Helvetica, sans-serif;"> <? '.$firstName.' '.' '.$lastName.'?></span>
</td>
    </tr>
    <tr> 
    <td> </td>
    </tr>
    <tr>
    <td align="center"><input name="memberID" type="text" value="'.$memberID.'" /></td>
    </tr>
 <tr>
    <td align="center"><input name="firstName" type="text" value="'.$firstName.'" /></td>
    </tr>
   <tr>
    <td align="center"><input name="lastName" type="text" value="'.$lastName.'" /></td>
    </tr>
 <tr>
    <td align="center"><input name="firstName2" type="text" value="'.$firstName2.'" /></td>
    </tr>
   <tr>
    <td align="center"><input name="lastName2" type="text" value="'.$lastName2.'" /></td>
    </tr>
 <tr>
    <td align="center"><input name="address" type="text" value="'.$address.'" /></td>
    </tr>
   <tr>
    <td align="center"><input name="city" type="text" value="'.$city.'" /></td>
    </tr>
 <tr>
    <td align="center"><input name="state" type="text" value="'.$state.'" /></td>
    </tr>
	 <tr>
    <td align="center"><input name="zip" type="text" value="'.$zip.'" /></td>
    </tr>
 <tr>
    <td align="center"><input name="telephone" type="text" value="'.$telephone.'" /></td>
    </tr>
   <tr>
    <td align="center"><input name="email" type="text" value="'.$email.'" /></td>
    </tr>
 <tr>
    <td align="center"><input name="expiration" type="text" value="'.$expiration.'" /></td>
    </tr>
 <tr>
    <td align="center"><input name="type" type="text" value="'.$type.'" /></td>
    </tr>
   <tr>
    <td align="center"><input name="childName" type="text" value="'.$childName.'" /></td>
    </tr>
 <tr>
    <td align="center"><input name="interests" type="text" value="'.$interests.'" /></td>
    </tr>
 <tr>
    <td align="center"><input name="dateAdded" type="text" value="'.$dateAdded.'" /></td>
    </tr>
   <tr>
    <td align="center"><input name="updated" type="text" value=" '.$updated.' " /></td>
    </tr>
 <tr>
    <td align="center"><input name="additionalNotes" type="text" value="'.$additionalNotes.'" /></td>
    </tr>
    <tr>
    <td align="center">
<input name="edit" type="hidden" value="'.$_REQUEST['edit'].'" />
<input name="memberID" type="hidden" value="'.$_REQUEST['memberID'].'" />
    <input type="submit" name="Submit" value="Submit">
</td>
    </tr>
  	</table>
</form>';
}

break;

// not sure if this is placed correctly $memberID = $_GET['memberID'];

where is the original url link i edited for you?

echo '<tr>
<td class="display"><a href="../admin/includes/update2.php?edit=edit&memberID='.$memberID.'">'.$memberID.'</a></td>
<td width="150px" class="display">'.$firstName.' '.' '.$lastName.'</td>
<td class="display">'.$firstName2.' '.' '.$lastName2.'</td>
<td width="300px" class="display">'.$address.' <br> '.$city.' '.' '.$state.' '.' '.$zip.'</td>
<td width="200px" class="display">'.$telephone.'</td>
<td class="display"><a href="mailto:'.$email.'">'.$email.'</a></td>
<td class="display">'.$expiration.'</td>
<td class="display">'.$type.'</td>
<td width="150px" class="display">'.$childName.'</td>
<td class="display">'.$interests.'</td>
<td width="200px" class="display">'.$dateAdded.'</td>
<td width="150px" class="display">'.$updated.'</td>
<td class="display">'.$additionalNotes.'</td>
</tr>';
}
?>

 

also in  your first lines you have a $$ on $$key = $value;

what should it be - this part someone wrote for me

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.