michaelness Posted June 23, 2009 Share Posted June 23, 2009 Right I have a page set up where a user can edit fields in the database specific to that user (interests, music etc). What i want to be able to do is to have the data from the database that the user has already put in showing in the text area when the user goes to edit them. Because at the moment everytime the user goes to edit a field and send it. it resets the other field to blank if there is nothing in their. <?php echo '<link rel="stylesheet" type="text/css" href="original.css" />'; include 'connection.php'; ?> <head> <title>yourFace</title> </head> <body> <?php $var = $_COOKIE['username']; include 'connection.php'; $query = "SELECT * FROM `userinfo` WHERE username='$var'"; $result = mysql_query($query); $row = mysql_fetch_object($result); if(isset($_COOKIE['username'])){ echo ' <form enctype="multipart/form-data" action="uploader.php" method="POST"> Choose a file to upload: <input name="uploadedfile" type="file" /><br /> <input type="submit" value="Upload File" /> </form> <form action="updateprofile.php" method="post"> <label>Age: </label><br> <input type="int" name="age" id="age"><br> <label>Interests: </label><br> <TEXTAREA name="interests", ROWS="5", COLS="45", wrap=virtual></TEXTAREA><br> <label>Hometown: </label><br> <TEXTAREA name="hometown", ROWS="1", COLS="45", wrap=virtual></TEXTAREA><br> <label>Hometown: </label><br> <TEXTAREA name="music", ROWS="5", COLS="45", wrap=virtual> </TEXTAREA><br> <label>:Favourite TV: </label><br> <TEXTAREA name="tv", ROWS="5", COLS="45", wrap=virtual><"$tv";</TEXTAREA><br> <label>:Favourite Films: </label><br> <TEXTAREA name="films", ROWS="5", COLS="45", wrap=virtual></TEXTAREA><br> <label>:Relationship Status: </label><br> <TEXTAREA name="relation", ROWS="5", COLS="45", wrap=virtual></TEXTAREA><br> <input type="submit" name="submit" id="submit" value="Submit"> </form> '; } //when not logged in else { echo 'You Are Not Logged In'; } ?> </body> </html> Please help me with this problem, I know something should go into the text area bits but i cant figure out what. Quote Link to comment https://forums.phpfreaks.com/topic/163432-data-from-database-into-text-area/ Share on other sites More sharing options...
elis Posted June 23, 2009 Share Posted June 23, 2009 Put whatever you want shown into a variable <textarea><?php=$variable?></textarea> or echo '<textarea>' . $variable . '</textarea>'; Quote Link to comment https://forums.phpfreaks.com/topic/163432-data-from-database-into-text-area/#findComment-862282 Share on other sites More sharing options...
michaelness Posted June 23, 2009 Author Share Posted June 23, 2009 I cant seem to get it to work echo '<TEXTAREA name="music", ROWS="5", COLS="45", wrap=virtual>' . $music . '</TEXTAREA>'; Quote Link to comment https://forums.phpfreaks.com/topic/163432-data-from-database-into-text-area/#findComment-862289 Share on other sites More sharing options...
Alex Posted June 23, 2009 Share Posted June 23, 2009 I cant seem to get it to work echo '<TEXTAREA name="music", ROWS="5", COLS="45", wrap=virtual>' . $music . '</TEXTAREA>'; That's fine as long as $music has the value you want.. Quote Link to comment https://forums.phpfreaks.com/topic/163432-data-from-database-into-text-area/#findComment-862290 Share on other sites More sharing options...
michaelness Posted June 23, 2009 Author Share Posted June 23, 2009 hmmm well im getting the error Parse error: parse error, expecting `','' or `';'' in C:\xampp\htdocs\yourFace\editprofile.php on line 50 I am so lost ??? Quote Link to comment https://forums.phpfreaks.com/topic/163432-data-from-database-into-text-area/#findComment-862293 Share on other sites More sharing options...
Alex Posted June 23, 2009 Share Posted June 23, 2009 hmmm well im getting the error Parse error: parse error, expecting `','' or `';'' in C:\xampp\htdocs\yourFace\editprofile.php on line 50 I am so lost ??? Show us more code. Quote Link to comment https://forums.phpfreaks.com/topic/163432-data-from-database-into-text-area/#findComment-862294 Share on other sites More sharing options...
michaelness Posted June 23, 2009 Author Share Posted June 23, 2009 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <?php echo '<link rel="stylesheet" type="text/css" href="original.css" />'; include 'connection.php'; ?> <head> <title>yourFace</title> </head> <body> <?php $var = $_COOKIE['username']; include 'connection.php'; $query = "SELECT * FROM `userinfo` WHERE username='$var'"; $result = mysql_query($query); $row = mysql_fetch_object($result); if(isset($_COOKIE['username'])){ echo ' <form enctype="multipart/form-data" action="uploader.php" method="POST"> Choose a file to upload: <input name="uploadedfile" type="file" /><br /> <input type="submit" value="Upload File" /> </form> <form action="updateprofile.php" method="post"> <label>Age: </label><br> <input type="int" name="age" id="age"><br> <label>Interests: </label><br> <TEXTAREA name="interests", ROWS="5", COLS="45", wrap=virtual></TEXTAREA><br> <label>Hometown: </label><br> <TEXTAREA name="hometown", ROWS="1", COLS="30", wrap=virtual></TEXTAREA><br> <label>Music: </label><br> <TEXTAREA name="music", ROWS="1", COLS="30", wrap=virtual>$music</TEXTAREA><br> echo '<TEXTAREA name="music", ROWS="5", COLS="45", wrap=virtual>' . $music . '</TEXTAREA>'; <br> <label>:Favourite TV: </label><br> <TEXTAREA name="tv", ROWS="5", COLS="45", wrap=virtual></TEXTAREA><br> <label>:Favourite Films: </label><br> <TEXTAREA name="films", ROWS="5", COLS="45", wrap=virtual></TEXTAREA><br> <label>:Relationship Status: </label><br> <TEXTAREA name="relation", ROWS="5", COLS="45", wrap=virtual></TEXTAREA><br> <input type="submit" name="submit" id="submit" value="Submit"> </form> '; } //when not logged in else { echo 'You Are Not Logged In'; } ?> </body> </html> I've been messing around with $music = $_POST['music']; aswell. the problem is im exceedingly tired. this is literally the last thing I have to do on this site, and im slowly going insane Quote Link to comment https://forums.phpfreaks.com/topic/163432-data-from-database-into-text-area/#findComment-862296 Share on other sites More sharing options...
J.Daniels Posted June 23, 2009 Share Posted June 23, 2009 You added a second echo inside the first echo <TEXTAREA name="music", ROWS="1", COLS="30", wrap=virtual>$music</TEXTAREA><br> <TEXTAREA name="music", ROWS="5", COLS="45", wrap=virtual>' . $music . '</TEXTAREA> <br> Quote Link to comment https://forums.phpfreaks.com/topic/163432-data-from-database-into-text-area/#findComment-862299 Share on other sites More sharing options...
michaelness Posted June 23, 2009 Author Share Posted June 23, 2009 im sorry, that was a typo and me being tired. this is the actual code <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <?php echo '<link rel="stylesheet" type="text/css" href="original.css" />'; include 'connection.php'; ?> <head> <title>yourFace</title> </head> <body> <?php $var = $_COOKIE['username']; $music = $_GET['music']; include 'connection.php'; $query = "SELECT * FROM `userinfo` WHERE username='$var'"; $result = mysql_query($query); $row = mysql_fetch_object($result); if(isset($_COOKIE['username'])){ echo ' <form enctype="multipart/form-data" action="uploader.php" method="POST"> Choose a file to upload: <input name="uploadedfile" type="file" /><br /> <input type="submit" value="Upload File" /> </form> <form action="updateprofile.php" method="post"> <label>Age: </label><br> <input type="int" name="age" id="age"><br> <label>Interests: </label><br> <TEXTAREA name="interests", ROWS="5", COLS="45", wrap=virtual></TEXTAREA><br> <label>Hometown: </label><br> <TEXTAREA name="hometown", ROWS="1", COLS="30", wrap=virtual></TEXTAREA><br> <label>Music: </label><br> <TEXTAREA name="music", ROWS="5", COLS="45", wrap=virtual>' . $music . '</TEXTAREA>; <br> <label>:Favourite TV: </label><br> <TEXTAREA name="tv", ROWS="5", COLS="45", wrap=virtual></TEXTAREA><br> <label>:Favourite Films: </label><br> <TEXTAREA name="films", ROWS="5", COLS="45", wrap=virtual></TEXTAREA><br> <label>:Relationship Status: </label><br> <TEXTAREA name="relation", ROWS="5", COLS="45", wrap=virtual></TEXTAREA><br> <input type="submit" name="submit" id="submit" value="Submit"> </form> '; } //when not logged in else { echo 'You Are Not Logged In'; } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/163432-data-from-database-into-text-area/#findComment-862301 Share on other sites More sharing options...
J.Daniels Posted June 23, 2009 Share Posted June 23, 2009 You have a semi-colon at the end of line 50 <TEXTAREA name="music", ROWS="5", COLS="45", wrap=virtual>' . $music . '</TEXTAREA> Quote Link to comment https://forums.phpfreaks.com/topic/163432-data-from-database-into-text-area/#findComment-862303 Share on other sites More sharing options...
Alex Posted June 23, 2009 Share Posted June 23, 2009 $music the a $_GET variable, I thought you wanted it to get it from your query? Change it from $music to $row['music'] Quote Link to comment https://forums.phpfreaks.com/topic/163432-data-from-database-into-text-area/#findComment-862305 Share on other sites More sharing options...
michaelness Posted June 23, 2009 Author Share Posted June 23, 2009 $music the a $_GET variable, I thought you wanted it to get it from your query? Change it from $music to $row['music'] im sorry to sound ignorant but im not sure what you mean mate Quote Link to comment https://forums.phpfreaks.com/topic/163432-data-from-database-into-text-area/#findComment-862308 Share on other sites More sharing options...
Alex Posted June 23, 2009 Share Posted June 23, 2009 $music the a $_GET variable, I thought you wanted it to get it from your query? Change it from $music to $row['music'] im sorry to sound ignorant but im not sure what you mean mate Don't you want the stuff inside the text area to be taken from the database? If your query is right, and there's a row in the table called 'music' replace $music with $row['music'] inside of your textarea. Quote Link to comment https://forums.phpfreaks.com/topic/163432-data-from-database-into-text-area/#findComment-862310 Share on other sites More sharing options...
michaelness Posted June 23, 2009 Author Share Posted June 23, 2009 ahh after i posted that i did what you just explained anyway and it didnt work. i got this line Parse error: parse error, expecting `','' or `';'' in C:\xampp\htdocs\yourFace\editprofile.php on line 49 using this <TEXTAREA name="music", ROWS="5", COLS="45", wrap=virtual>$row['music']</TEXTAREA> Quote Link to comment https://forums.phpfreaks.com/topic/163432-data-from-database-into-text-area/#findComment-862312 Share on other sites More sharing options...
Alex Posted June 23, 2009 Share Posted June 23, 2009 You still have to have it like.. <TEXTAREA name="music", ROWS="5", COLS="45", wrap=virtual>' . $row['music'] . '</TEXTAREA> Quote Link to comment https://forums.phpfreaks.com/topic/163432-data-from-database-into-text-area/#findComment-862314 Share on other sites More sharing options...
michaelness Posted June 23, 2009 Author Share Posted June 23, 2009 I'd tried that aswell. that comes up with Fatal error: Cannot use object of type stdClass as array in C:\xampp\htdocs\yourFace\editprofile.php on line 49 if it helps on my other page View Profile i am accessing the tables like this $row->music but i havent been able to get that to work either. is my variable at the top of the page right? the $email = $_POST['music']; bit? Quote Link to comment https://forums.phpfreaks.com/topic/163432-data-from-database-into-text-area/#findComment-862315 Share on other sites More sharing options...
Alex Posted June 23, 2009 Share Posted June 23, 2009 Oh, that's because you're using mysql_fetch_object, and not like mysql_fetch_assoc, or mysql_fetch_array.. Still if $row->music isn't working then there's something wrong with your query. Quote Link to comment https://forums.phpfreaks.com/topic/163432-data-from-database-into-text-area/#findComment-862318 Share on other sites More sharing options...
michaelness Posted June 23, 2009 Author Share Posted June 23, 2009 Oh, that's because you're using mysql_fetch_object, and not like mysql_fetch_assoc, or mysql_fetch_array.. Still if $row->music isn't working then there's something wrong with your query. hmmm i have no idea what to do. Quote Link to comment https://forums.phpfreaks.com/topic/163432-data-from-database-into-text-area/#findComment-862320 Share on other sites More sharing options...
michaelness Posted June 23, 2009 Author Share Posted June 23, 2009 It cant be that complex surely? all i need for it to do is to get info from the database. i cant believe im stuck on this :S Quote Link to comment https://forums.phpfreaks.com/topic/163432-data-from-database-into-text-area/#findComment-862323 Share on other sites More sharing options...
J.Daniels Posted June 23, 2009 Share Posted June 23, 2009 It's possible there is a problem with the query. To check the query: $result = mysql_query($query) or trigger_error('SQL Failed', E_USER_ERROR); Also, you might have an empty result set. Try echoing out the number of rows returned: echo mysql_num_rows($result); Quote Link to comment https://forums.phpfreaks.com/topic/163432-data-from-database-into-text-area/#findComment-862329 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.