Hi all..
I got this code that dealing with ajax..Basically the ajax code is to get the data from the html element and insert it to the database.

this is ajax and the html code :

<script type="text/javascript">
$(document).ready(function(){
 $("form#post_reply").submit(function() {
 
 var discuss_text = $('#discuss_text').attr('value');
 var test5 = $('#test5').attr('value');
	
 $.ajax({
	type: "POST",
	url: "reply.php",
	data: "discuss_text="+ discuss_text,
	success: function(){
	          $("ul.reply_text").prepend("<li style='display:none' class='stbody'>   <div class='stimg'></div>
<div class='sttext'>"+discuss_text+
"<div class='below'>
<div class='sttime'>2 seconds ago</div>
<div class='like'>| like |</div>
<div class='dislike'>dislike |</div>
</div></div></li>");
   $("ul.reply_text li:first").fadeIn();
	       }
		});	
	return false;
	});	
});
</script>
<form name='disscuss_text' id='post_reply' id='post_reply'>
   <input type="hidden" name="test5" id="test5" value="<?php echo $row['id']; ?>">
   <textarea rows='3' cols='87' id='discuss_text' name='discuss_text'></textarea>
   <input type='submit' value='Post' name='Help' id='post-button' />
</form>

and this is the reply.php file :

<?php
// Change this parameter with your connection's info.
$db_host="localhost";
$db_name="*******";
$username="******";
$password="******";
$db_con=mysql_connect($db_host,$username,$password);
$connection_string=mysql_select_db($db_name);
// Connection
mysql_connect($db_host,$username,$password);
mysql_select_db($db_name);
?>
<?php
if(isset($_POST['discuss_text'])){
	/* Connection to Database */

	/* Remove HTML tag to prevent query injection */
	$message = strip_tags($_POST['discuss_text']);
	
	$sql = 'INSERT INTO reply (message) VALUES("'.$message.'")';

	mysql_query($sql);
	
	echo $message;
	} else { }
?>

So, if you notice,there is this code above :

<input type="hidden" name="test5" id="test5" value="<?php echo $row['id']; ?>">

$row value is what i am trying to insert into the 'reply' database into the post_id table..
So how to add one or more data to this line of code "data: "discuss_text="+ discuss_text," ??
so that i could be able to insert more than just one data at a time into the database by using ajax..


ask me if unclear bout this question,
Thanks for helping :)

Hi all..
I got this code that dealing with ajax..Basically the ajax code is to get the data from the html element and insert it to the database.

this is ajax and the html code :

<script type="text/javascript">
$(document).ready(function(){
 $("form#post_reply").submit(function() {
 
 var discuss_text = $('#discuss_text').attr('value');
 var test5 = $('#test5').attr('value');
	
 $.ajax({
	type: "POST",
	url: "reply.php",
	data: "discuss_text="+ discuss_text,
	success: function(){
	          $("ul.reply_text").prepend("<li style='display:none' class='stbody'>   <div class='stimg'></div>
<div class='sttext'>"+discuss_text+
"<div class='below'>
<div class='sttime'>2 seconds ago</div>
<div class='like'>| like |</div>
<div class='dislike'>dislike |</div>
</div></div></li>");
   $("ul.reply_text li:first").fadeIn();
	       }
		});	
	return false;
	});	
});
</script>
<form name='disscuss_text' id='post_reply' id='post_reply'>
   <input type="hidden" name="test5" id="test5" value="<?php echo $row['id']; ?>">
   <textarea rows='3' cols='87' id='discuss_text' name='discuss_text'></textarea>
   <input type='submit' value='Post' name='Help' id='post-button' />
</form>

and this is the reply.php file :

<?php
// Change this parameter with your connection's info.
$db_host="localhost";
$db_name="*******";
$username="******";
$password="******";
$db_con=mysql_connect($db_host,$username,$password);
$connection_string=mysql_select_db($db_name);
// Connection
mysql_connect($db_host,$username,$password);
mysql_select_db($db_name);
?>
<?php
if(isset($_POST['discuss_text'])){
	/* Connection to Database */

	/* Remove HTML tag to prevent query injection */
	$message = strip_tags($_POST['discuss_text']);
	
	$sql = 'INSERT INTO reply (message) VALUES("'.$message.'")';

	mysql_query($sql);
	
	echo $message;
	} else { }
?>

So, if you notice,there is this code above :

<input type="hidden" name="test5" id="test5" value="<?php echo $row['id']; ?>">

$row value is what i am trying to insert into the 'reply' database into the post_id table..
So how to add one or more data to this line of code "data: "discuss_text="+ discuss_text," ??
so that i could be able to insert more than just one data at a time into the database by using ajax..


ask me if unclear bout this question,
Thanks for helping :)

Yes, you can pass multiple variables through jqueyr ajax

<script type="text/javascript">
function resultPublish()
{
	 var myindex  = ....
	 var selValue = ....
	 
	  $.ajax({
		url: "yourPage.php",	
		type: "GET",		
		data: "data1="+myindex+"&data2="+selValue,	
		cache: false,
		success: function (html) {	
		
			...do something	
		}		
	});
}
</script>

In "yourPage.php" you can access "data1" and "data2" like following

echo $_GET['data1'];
echo $_GET['data2'];

Hope it will help you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.