Jump to content

dispaly and edit simultaneously


farisbadii

Recommended Posts

Any help with the following is highly appreciated. I have a table which includes names and addresses. I need to let the visitors to my web page to be able to see their own address as well as be able to edit it at the same time. In other words be able to just type over the old address and click save. Can any one tell me how I can accomplish this please. I need help for both reading and displaying the current info as well as edit part.

 

Thanks

Link to comment
Share on other sites

<?php
//get the id from the url and clean it, assuming it is smth like profile.php?id=7
$id = mysql_real_escape_string($_GET['id']);
//check if the button is pressed
if(array_key_exists('submit', $_POST)){
       //clean up the address
       $address = htmlentities($_POST['address']);
       //make the query and echo a message
       $queryEdit = "UPDATE users SET address='$address' WHERE id='$id'";
       $resultsEdit = @mysql_query($queryEdit) or die();
       echo "Your address was changed successfully";
}
//make the query to show the results in the input box
$queryShow = "SELECT address FROM users WHERE id='$id'";
$resultsShow = @mysql_query($queryShow) or die();
$valuesShow = mysql_fetch_array($resultsShow);
?>
<form name="form1" method="post" action="">
     <input type="text" name="address" value="<?php echo $valuesShow['address']; ?>">
     <input name="submit" type="submit" value="Change">
</form>

 

The code was written assuming certain conditions but you can modify it to fit your needs. What it does is display the address in an input box, so if the user wants to change it, he just clicks in the input, changes it and then clicks the submit button, which reloads the same page. When the page reloads, it checks if the button is pressed and if it is the case it modifies the database with the new address. Pretty simple and straightforward. You can modify the styles of the input so it can look a little better then the default.

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.