Jump to content

How to jQuery inbox system


jayjay159

Recommended Posts

Okay so i'm making an inbox system with jQuery but i can't get it to work, basically i want the user to click on a link and jQuery will send get data to read.php, i will post both of the pages of code!

Thanks All!

Inbox Page.

<?php
session_start();
?>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type='text/javascript'>
function doVar() {
$.get('read.php', {messageid: $('#in').val()},
function(output){
	$('#read').html(output).slideToggle(500);	
}
);	
}
</script>
<div id="inbox_wrap">
<?php
$_SESSION['username'] = "[email protected]";
$user = $_SESSION['username'];

require("connect.php");
//$id = mysql_query("SELECT id FROM mail WHERE to_name = '$user' ORDER BY id DESC") or die (mysql_error());
$inbox = mysql_query("SELECT * FROM mail WHERE to_name = '$user' ORDER BY id DESC") or die (mysql_error());
$num_msg = mysql_num_rows($inbox);
if($num_msg==0) {echo "You have no messages";}
for($count = 1; $count <= $num_msg; $count++) {
	$row = mysql_fetch_array($inbox);
	$idi = $row['id'];
	$read = $row['read_yn'];
	$from = $row['from_name'];
	$input = "<a href='#' id='in' onClick='doVar();' />";//need to send a value or something have tried <input type='text' value='$idi' /> doesn't work
	echo $input;
if($read==0) echo "New!";

}
?>
</div>
<div id='read'></div>

Read Page.
<?php
session_start();

$_SESSION['username'] = "[email protected]";
$user = $_SESSION['username'];
$messageid = $_GET['messageid'];
require("connect.php");
mysql_query("UPDATE mail SET read_yn='1' WHERE id='$messageid'")or die(mysql_error());
$gm = mysql_query("SELECT * FROM mail WHERE id = '$messageid' AND to_name = '$user'") or die(mysql_error());
	$gmr = mysql_fetch_assoc($gm);
	$to = $gmr['to_name'];
	$from = $gmr['from_name'];
	$message = $gmr['message'];
	$read = $gmr['read_yn'];
	echo "To: ".$to."<br />"."From: ".$from."<br />"."Message: <br />".$message;
	mysql_close();

if($_POST['delete']) {
require("connect.php");
mysql_query("DELETE FROM mail WHERE id = '$messageid'")or die(mysql_error());
mysql_close();
echo "<meta http-equiv='refresh' content='0;url=index.php?page=inbox'";
}
?>
<form method='POST'>
<input type='submit' name='delete' value='Delete' />
</form>

Link to comment
https://forums.phpfreaks.com/topic/236252-how-to-jquery-inbox-system/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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