princeofpersia Posted November 18, 2010 Share Posted November 18, 2010 Hi guys I have created a profile page where users can update their profile. what I need to do is to echo back the users details in the inout text I have name and telephone number any ideas how to do it? here is my code <?php session_start(); include ("global.php"); //username session $_SESSION['username']=='$username'; $username=$_SESSION['username']; //welcome messaage echo "Welcome, " .$_SESSION['username']."!<p>"; if ($_POST['register']) { //get form data $name = addslashes(strip_tags($_POST['name'])); $telephonenumber = addslashes(strip_tags($_POST['telephonenumber'])); $query = "UPDATE users SET name = ' $name' WHERE username='$username'"; $result = mysql_query($query); $query = "UPDATE users SET telephonenumber = ' $telephonenumber' WHERE username='$username'"; $result = mysql_query($query); } ?> <form action='updateprofile.php' method='POST'> Company Name:<br /> <input type='text' name='name'><p /> <input type='text' name='telephonenumber'><p /> <input type='submit' name='register' value='Register'> </form> _______ the reason i want to do this is because when user is updating the name field the empty input text for telephone number ovverides the telephone number field in the database. I would aprreciate your help guys, Link to comment https://forums.phpfreaks.com/topic/219107-echo-from-database-to-input-text/ Share on other sites More sharing options...
litebearer Posted November 18, 2010 Share Posted November 18, 2010 a rough idea <input type="text" name="telephonenumber" value="<?PHP echo $telephone_number_from_the_database; ?>"><p /> Link to comment https://forums.phpfreaks.com/topic/219107-echo-from-database-to-input-text/#findComment-1136212 Share on other sites More sharing options...
seanlim Posted November 18, 2010 Share Posted November 18, 2010 after the registration conditional: $query = "SELECT name, users WHERE username='$username'"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); and your html: <input type='text' name='name' value='<?php echo $row['name']; ?>'><p /> <input type='text' name='telephonenumber' value='<?php echo $row['telephonenumber']; ?>'><p /> Some points to note: 1. You don't have to do 2 update commands, they can be combined "SET name = '$name', telephonenumber='$telephonenumber'" etc 2. The following lines don't make sense: //username session $_SESSION['username']=='$username'; $username=$_SESSION['username']; == checks for equality Link to comment https://forums.phpfreaks.com/topic/219107-echo-from-database-to-input-text/#findComment-1136214 Share on other sites More sharing options...
princeofpersia Posted November 18, 2010 Author Share Posted November 18, 2010 yeah, easy and straight forward, u r amazing Link to comment https://forums.phpfreaks.com/topic/219107-echo-from-database-to-input-text/#findComment-1136217 Share on other sites More sharing options...
princeofpersia Posted November 18, 2010 Author Share Posted November 18, 2010 one more question when i login and go to my update profile page the data doesnt show up in text field but if I add the new entries, after data has been added, it will show the data in text field, do u know whyy? thanks Link to comment https://forums.phpfreaks.com/topic/219107-echo-from-database-to-input-text/#findComment-1136227 Share on other sites More sharing options...
seanlim Posted November 18, 2010 Share Posted November 18, 2010 is the MySQL SELECT query part outside of the if($_POST['register']){} conditional? Link to comment https://forums.phpfreaks.com/topic/219107-echo-from-database-to-input-text/#findComment-1136240 Share on other sites More sharing options...
princeofpersia Posted November 18, 2010 Author Share Posted November 18, 2010 it was inside the conditional statement, so I moved it out and now it works as charm, thanks Link to comment https://forums.phpfreaks.com/topic/219107-echo-from-database-to-input-text/#findComment-1136244 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.