ambo Posted September 17, 2008 Share Posted September 17, 2008 $someUserId = 23523; $query = "SELECT * FROM de_user WHERE userid = '$someUserId'"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_assoc($result); echo "{$row['email']}<br />{$row['name']}<br />{$row['sex']}"; I used that to get the data But how do i Change the Data i wanna make a edit profile page would i use a new form to post the data or can it be done with php to verify the user is actully being the one edited??? Link to comment https://forums.phpfreaks.com/topic/124677-editing-tables-using-php/ Share on other sites More sharing options...
F1Fan Posted September 17, 2008 Share Posted September 17, 2008 That's a really complicated request. But, the basic steps are to create a form that has all the fields that they can modify populated by the results of your query. Then when they submit the page, do an update query that changes the data. You'll probably want to check for special characters and stuff so they don't bomb the page if they enter a quote or something. As far as validating who they are, you'll have to do some kind of check with something they enter against a value in the database to see if it matches. If it does, allow the update. If not, display an error. Link to comment https://forums.phpfreaks.com/topic/124677-editing-tables-using-php/#findComment-643947 Share on other sites More sharing options...
ambo Posted September 17, 2008 Author Share Posted September 17, 2008 you know of anywhere i can find a tutorial on how to do this? Link to comment https://forums.phpfreaks.com/topic/124677-editing-tables-using-php/#findComment-643953 Share on other sites More sharing options...
F1Fan Posted September 17, 2008 Share Posted September 17, 2008 W3Schools is my fav. Start here: http://www.w3schools.com/php/php_mysql_intro.asp Link to comment https://forums.phpfreaks.com/topic/124677-editing-tables-using-php/#findComment-643960 Share on other sites More sharing options...
ambo Posted September 17, 2008 Author Share Posted September 17, 2008 Ok you have to use the <?php $con = mysql_connect("localhost","peter","abc123"); if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("my_db", $con); mysql_query("UPDATE Person SET Age = '36'WHERE FirstName = 'Peter' AND LastName = 'Griffin'");mysql_close($con); ?> how does the <form> tag relate to what is red how do i get the for to post that data Link to comment https://forums.phpfreaks.com/topic/124677-editing-tables-using-php/#findComment-643976 Share on other sites More sharing options...
F1Fan Posted September 17, 2008 Share Posted September 17, 2008 OK, I'll try and simplify this as much as possible. <form method="post"> <?php if (!isset($_POST['id'])){ ?> Enter your ID here: <input type="text" size="5" name="id"><input type="submit" value="Submit"> <?php } elseif (!isset($_POST['name'])){ $result = mysql_query("SELECT name FROM users WHERE id = {$_POST['id']}"); $row = mysql_fetch_array($result); ?> <input type="hidden" name="id" value="<?=$_POST['id?>"> Change your name: <input type="text" size="25" name="name" value="<?=$row[0]?>"><input type="submit" value="Submit"> <?php } else{ $result = mysql_query("UPDATE users SET name = '{$_POST['name']}' WHERE id = {$_POST['id']}") if ($result) echo "Name saved"; else echo "Problem saving"; } ?> </form> Hope that helps. Link to comment https://forums.phpfreaks.com/topic/124677-editing-tables-using-php/#findComment-643991 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.