Jump to content

Recommended Posts

I have this awesome little script that I have to configure.  My php is limited but I can get by, my javascripting is very limited to say the least but I can see whats wrong with the script.

 

ok first I will post some of the orginal javascript and the query that it runs.....

 


<script type="text/javascript"> 

// <![CDATA[	

$(document).ready(function(){	

	$('#shareButton').click(function(){

		var a = $("#watermark").val();
		if(a != "What's on your mind?")
		{
			$.post("posts.php?value="+a, {

			}, function(response){

				$('#posting').prepend($(response).fadeIn('slow'));
				$("#watermark").val("What's on your mind?");
			});
		}
	});	





 

next the form itself......

 

<form action="" method="post" name="postsForm">

	<div class="UIComposer_Box">

	<span class="w">
	<textarea class="input" id="watermark" name="watermark" style="height:20px" cols="60"></textarea>
	</span>

		<br clear="all" />

		<div align="left" style="height:30px; padding:10px 5px;">

			    
			 
			</span>
			<a id="shareButton" style="float:left" class="smallbutton Detail"> Share</a>

		</div>

	</div>

	</form>

 

now the php which is in an external sheet called posts.php    .........

 

<?php
include('dbcon.php');
function checkValues($value)
{
	 $value = trim($value); 

	if (get_magic_quotes_gpc()) {
		$value = stripslashes($value);

	}

	 $value = strtr($value,array_flip(get_html_translation_table(HTML_ENTITIES)));

	 $value = strip_tags($value);
	$value = mysql_real_escape_string($value);
	$value = htmlspecialchars ($value);

	return $value;

}	

function clickable_link($text = '')
{
	$text = preg_replace('#(script|about|applet|activex|chrome):#is', "\\1:", $text);
	$ret = ' ' . $text;
	$ret = preg_replace("#(^|[\n ])([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $ret);

	$ret = preg_replace("#(^|[\n ])((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $ret);
	$ret = preg_replace("#(^|[\n ])([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", "\\1<a href=\"mailto:\\2@\\3\">\\2@\\3</a>", $ret);
	$ret = substr($ret, 1);
	return $ret;
}

$next_records = 10;
$show_more_button = 0;
if(checkValues($_REQUEST['value']))
{
	$userip = $_SERVER['REMOTE_ADDR'];
	echo "INSERT INTO facebook_posts (post,f_name,userip,date_created) VALUES('".checkValues($_REQUEST['value'])."','".danny."','".$userip."','".strtotime(date("Y-m-d H:i:s"))."')";

	mysql_query("INSERT INTO facebook_posts (post,f_name,userip,date_created) VALUES('".checkValues($_REQUEST['value'])."','".danny."','".$userip."','".strtotime(date("Y-m-d H:i:s"))."')");

	$result = mysql_query("SELECT *,
	UNIX_TIMESTAMP() - date_created AS TimeSpent FROM facebook_posts order by p_id desc limit 1");

}


//etc

 

In the php section in the values there is this "danny" for the f_name

 

The issue is simple. Instead of danny i want $User['memberID'].  The problem I have is I dont know how to add the row to the javascript at the beginning to make it work.  The best I have is this......

 

<script type="text/javascript"> 

// <![CDATA[	

$(document).ready(function(){	

	$('#shareButton').click(function(){

		var a = $("#watermark").val();

		var b = $("<?php echo $User['memberID']; ?>").val();



		if(a != "What's on your mind?")
		{
			$.post("posts.php?value="+a+"&mem="+b, {

			}, function(response){

				$('#posting').prepend($(response).fadeIn('slow'));
				$("#watermark").val("What's on your mind?");
			});
		}
	});	
//etc

 

but this is not working.  I would really appreciate some help on this as im all out of ideas.  I would love this feature or one similar to work within my site. Thank you

Link to comment
https://forums.phpfreaks.com/topic/232948-wall-posting-issue/
Share on other sites

var a = $("#watermark").val();
var b = $("<?php echo $User['memberID']; ?>").val();

 

$(..) is a jQuery selector. The top line here passes "#watermark", which is referencing the element with the #ID of "watermark". The method .val() is available because the object that is created has a .value property (.val() also has some more advanced capabilities, but that's for another day).

 

All you need to do is store the value of $User['memberID'] within a normal JavaScript variable:

 

var b = '<?php echo $User['memberID']; ?>';

Link to comment
https://forums.phpfreaks.com/topic/232948-wall-posting-issue/#findComment-1198109
Share on other sites

I wonder what alert(b) would output :)

 

All you need to do is store the value of $User['memberID'] within a normal JavaScript variable:

 

var b = '<?php echo $User['memberID']; ?>';

 

fife, if this solves your issue please mark as solved, which would make you a cool person ;)

 

Link to comment
https://forums.phpfreaks.com/topic/232948-wall-posting-issue/#findComment-1198116
Share on other sites

I wonder what alert(b) would output :)

 

Probably 'undefined', as there's no .value property of a string. jQuery isn't about string operations anyway, it's about "document traversing, event handling, animating, and Ajax interactions". It doesn't replace standard JavaScript objects like Date, Number, String, etc.

Link to comment
https://forums.phpfreaks.com/topic/232948-wall-posting-issue/#findComment-1198119
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.