farisbadii Posted July 22, 2007 Share Posted July 22, 2007 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 Quote Link to comment Share on other sites More sharing options...
Fadion Posted July 24, 2007 Share Posted July 24, 2007 <?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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.