Jump to content

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'] = "Jamie@jaynet.home";
$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'] = "Jamie@jaynet.home";
$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

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.