Jump to content

(php/java) changing text


squiblo

Recommended Posts

I have some data in a database (about_me).  When there is no data in "about_me", everything works fine and the user can upload data but when data is put in by the user, and the user then wants to edit it again, it doesnt work.

 

 

This is the php to upload the data

<!-- about me upload -->
<?php
if (isset($_POST['submit_about']))
{
if (isset($_POST['textarea_about']))
{
$textarea_about = nl2br($_POST['textarea_about']);

	if (strlen($textarea_about) < 301)
	{
		mysql_query("UPDATE page_set_data SET about_me='$textarea_about' WHERE username='$username'");
		header("location:http://www.squiblo.com/content.php?content=myhub&myhub=mypage&mypage=mypage&cont=$cont");

	}
	else
	$about_error = "<ul><li>About you have as maximum of 300 characters.</li></ul>";

}

}
?>

 

This gets the data from the database and puts it into variable

<?php
$about_me_query = mysql_query("SELECT * FROM page_set_data WHERE username='$username'");

while ($row = mysql_fetch_assoc($about_me_query))
{
$about_me = nl2br($row['about_me']);
}

if (!$about_me)
{
$about_me = "Write about yourself";
}
?>

 

This is the javascript to change from showing the data in textarea or not

<script type="text/javascript">
function toggle_visibility(id)
{	
var div = document.getElementById(id);	
var text = document.getElementById("about_me_text");		

if(div.style.display == 'block' ) 
	{		
	div.style.display = 'none';		
	text.innerHTML = "<?php echo $about_me; ?>";

	}	
	else 
	{		
	div.style.display = 'block';		
	text.innerHTML = "<?php echo $about_error; ?><form action='' method='POST'><textarea cols='23' rows='6' name='textarea_about' id='textarea_about' style='font-family:arial;font-size:13px;overflow:hidden'><?php echo nl2br($about_me);?></textarea><br><input type='submit' name='submit_about' value='Save'>   <input type='button' name='cancel_about' value='Cancel' onClick=\"window.location.href='content.php?content=myhub&myhub=mypage&mypage=mypage&cont=<?php echo $cont; ?>'\"></form>";	
	}
}
</script>

 

And finaly here is some HTML

<div id='about_me_text'>

	<?php echo $about_me; ?>
	</div>

	<div id='about_me_popup' style="display:none">

	</div>

 

 

If you are finding it hard to understand me, please say so and ill link you to the page. Or i you know how to do this and please could you show me a better way for doing this. :D thanks

Link to comment
Share on other sites

What "doesn't work"?

 

Is the update failing? Is the data missing from the textarea? etc.

 

Whether or not you show the textarea or hide it, it still exists within the page so that shouldn't make a difference.

 

On a side note, javascript is not java :)

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.