Jump to content

Data from Database into Text Area?


michaelness

Recommended Posts

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.

Link to comment
Share on other sites

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..

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

<!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

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

$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.

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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);

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.