extra optie tot mijn inlog scripts

Status
Niet open voor verdere reacties.

ciske de rat

Verenigingslid
Lid geworden
10 jun 2003
Berichten
964
ik ben nu al een dag aan het zoeken naar goed uitleg of video
om een private messnger script kunnen maken en toe te voegen aan mijn web site
ik heb een script gevonden
dacht hier gebruik van te kunnen maken
door naar de databasen te kijken komen ik hoefde alleen een row bij mijn users toe te voegen en een create table te maken
denk makkelijk om script toe te passen maar schijnt toch weer niet te kunnen op een een of andere manier heb ik geen error door scriipt iets aan te passen
wat ik al vreemd vond
kun kan ik berichten maken alleen iedereen kan dat zien waneer ik de pagina read_pm.php?id= 5 open krijg ik niks te zien
helaas heeft iemand nog een goed handleding om zo iet op te zetten of weet te maken
 
Je meot niet zoeken naar video's, omdat daar vaak slecht uitgelegd wordt wat ze doen. Je moet juist WETEN wat ze doen, en waarom ze bepaalde structuren en functies gebruiken, en dat komt in tutorials wel naar voren. Howel ze neit voor elk iets een tutorials hebben, omdat verwacht wordt dat je weet hoe PHP in elkaar steekt, en dat het vrijwel basiskennis is.

Maargoed.... wat heb je nu al aan code.?? Zonder dit kunnen we geen advies geven.
 
Laatst bewerkt:
aan code

aan code heb ik

database= inlog
tables countries , dialing_code, pm_inbox, pm_outbox, site_settings,users,

om de pm_inbox,pm_outbox, users
gaat het

volgende heb ik na gekeken

PHP:
-- 
-- Table structure for table `pm`
-- 

CREATE TABLE `pm` (
  `id` bigint(20) NOT NULL,
  `id2` int(11) NOT NULL,
  `title` varchar(256) NOT NULL,
  `user1` bigint(20) NOT NULL,
  `user2` bigint(20) NOT NULL,
  `message` text NOT NULL,
  `timestamp` int(10) NOT NULL,
  `user1read` varchar(3) NOT NULL,
  `user2read` varchar(3) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

-- 
-- Table structure for table `users`
-- 

CREATE TABLE `users` (
  `id` bigint(20) NOT NULL,
  `username` varchar(255) NOT NULL,
  `password` varchar(255) NOT NULL,
  `email` varchar(255) NOT NULL,
  `avatar` text NOT NULL,
  `signup_date` int(10) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
bij users staat veel meer in mijn tabele dat hier is aan gegeven aan gezien ik hem werkend wil hebben in mijn script

pagina list_pm.php
PHP:
<?PHP
require_once('../lib/connections/db.php');
include('../lib/functions/functions.php');
include('../lib/functions/ps_pagination.php');

checkLogin('2');

$message="";
if(isset($_GET['message'])){
	$message = strip_tags($_GET['message']);
	}
	
$error="";
if(isset($_GET['error'])){
	$error = strip_tags($_GET['error']);
	}
	
$getuser = getUserRecords($_SESSION['user_id']);

?>
!DOCTYPE html> 
<html>
<!--gedeelte 1-->
<head>
  <title> WhatsAppgroep</title>
  <meta name="description" content="whatappgroep" />
  <meta name="keywords" content="whatsapp, groep,Whatappgroep" />
  <meta http-equiv="content-type" content="text/html; charset=windows-1252" />
  <link rel="stylesheet" type="text/css" href="css/style1.css" />
  <!-- modernizr enables HTML5 elements and feature detects -->
  <script type="text/javascript" src="js/modernizr-1.5.min.js"></script>
</head>
<!--close gedeelte 1-->
<!--gedeelte 2-->



<?php
//We check if the user is logged
if(isset($_SESSION['username']))
{
//We list his messages in a table
//Two queries are executes, one for the unread messages and another for read messages
$req1 = mysql_query('select m1.id, m1.title, m1.timestamp, count(m2.id) as reps, users.id as userid, users.username from pm as m1, pm as m2,users where ((m1.user1="'.$_SESSION['userid'].'" and m1.user1read="no" and users.id=m1.user2) or (m1.user2="'.$_SESSION['userid'].'" and m1.user2read="no" and users.id=m1.user1)) and m1.id2="1" and m2.id=m1.id group by m1.id order by m1.id desc');
$req2 = mysql_query('select m1.id, m1.title, m1.timestamp, count(m2.id) as reps, users.id as userid, users.username from pm as m1, pm as m2,users where ((m1.user1="'.$_SESSION['userid'].'" and m1.user1read="yes" and users.id=m1.user2) or (m1.user2="'.$_SESSION['userid'].'" and m1.user2read="yes" and users.id=m1.user1)) and m1.id2="1" and m2.id=m1.id group by m1.id order by m1.id desc');
?>
This is the list of your messages:<br />
<a href="new_pm.php" class="link_new_pm">New PM</a><br />
<h3>Unread Messages(<?php echo intval(mysql_num_rows($req1)); ?>):</h3>
<table>
        <tr>
        <th class="title_cell">Title</th>
        <th>Nb. Replies</th>
        <th>Participant</th>
        <th>Date of creation</th>
    </tr>
<?php
//We display the list of unread messages
while($dn1 = mysql_fetch_array($req1))
{
?>
        <tr>
        <td class="left"><a href="read_pm.php?id=<?php echo $dn1['id']; ?>"><?php echo htmlentities($dn1['title'], ENT_QUOTES, 'UTF-8'); ?></a></td>
        <td><?php echo $dn1['reps']-1; ?></td>
        <td><a href="profile.php?id=<?php echo $dn1['userid']; ?>"><?php echo htmlentities($dn1['username'], ENT_QUOTES, 'UTF-8'); ?></a></td>
        <td><?php echo date('Y/m/d H:i:s' ,$dn1['timestamp']); ?></td>
    </tr>
<?php
}
//If there is no unread message we notice it
if(intval(mysql_num_rows($req1))==0)
{
?>
        <tr>
        <td colspan="4" class="center">You have no unread message.</td>
    </tr>
<?php
}
?>
</table>
<br />
<h3>Read Messages(<?php echo intval(mysql_num_rows($req2)); ?>):</h3>
<table>
        <tr>
        <th class="title_cell">Title</th>
        <th>Nb. Replies</th>
        <th>Participant</th>
        <th>Date or creation</th>
    </tr>
<?php
//We display the list of read messages
while($dn2 = mysql_fetch_array($req2))
{
?>
        <tr>
        <td class="left"><a href="read_pm.php?id=<?php echo $dn2['id']; ?>"><?php echo htmlentities($dn2['title'], ENT_QUOTES, 'UTF-8'); ?></a></td>
        <td><?php echo $dn2['reps']-1; ?></td>
        <td><a href="profile.php?id=<?php echo $dn2['userid']; ?>"><?php echo htmlentities($dn2['username'], ENT_QUOTES, 'UTF-8'); ?></a></td>
        <td><?php echo date('Y/m/d H:i:s' ,$dn2['timestamp']); ?></td>
    </tr>
<?php
}
//If there is no read message we notice it
if(intval(mysql_num_rows($req2))==0)
{
?>
        <tr>
        <td colspan="4" class="center">You have no read message.</td>
    </tr>
<?php
}
?>
</table>
<?php
}
else
{
        echo 'You must be logged to access this page.';
}
?>
                </div>
                <div class="foot"><a href="<?php echo $url_home; ?>">Go Home</a> - <a href="http://www.webestools.com/">Webestools</a></div>
ik echt niet wat ik anders moet doen heeft denk ik met mijn beveiling van eigen inlog script te maken

read_pm.php hier zitten de meeste problemen in
PHP:
<?PHP
require_once('../lib/connections/db.php');
include('../lib/functions/functions.php');
include('../lib/functions/ps_pagination.php');

checkLogin('2');

$message="";
if(isset($_GET['message'])){
	$message = strip_tags($_GET['message']);
	}
	
$error="";
if(isset($_GET['error'])){
	$error = strip_tags($_GET['error']);
	}
	
$getuser = getUserRecords($_SESSION['user_id']);

?><!DOCTYPE html> 
<html>
<!--gedeelte 1-->
<head>
  <title> WhatsAppgroep</title>
  <meta name="description" content="whatappgroep" />
  <meta name="keywords" content="whatsapp, groep,Whatappgroep" />
  <meta http-equiv="content-type" content="text/html; charset=windows-1252" />
  <link rel="stylesheet" type="text/css" href="css/style1.css" />
  <!-- modernizr enables HTML5 elements and feature detects -->
  <script type="text/javascript" src="js/modernizr-1.5.min.js"></script>
</head>
<!--close gedeelte 1-->
<!--gedeelte 2-->

<body>
<?php
//We check if the user is logged
if(isset($_SESSION['username']))
{
//We check if the ID of the discussion is defined
if(isset($_GET['id']))
{
$id = intval($_GET['id']);
//We get the title and the narators of the discussion
$req1 = mysql_query('select title, user1, user2 from pm where id="'.$id.'" and id2="1"');
$dn1 = mysql_fetch_array($req1);
//We check if the discussion exists
if(mysql_num_rows($req1)==1)
{
//We check if the user have the right to read this discussion
if($dn1['user1']==$_SESSION['userid'] or $dn1['user2']==$_SESSION['userid'])
{
//The discussion will be placed in read messages
if($dn1['user1']==$_SESSION['userid'])
{
        mysql_query('update pm set user1read="yes" where id="'.$id.'" and id2="1"');
        $user_partic = 2;
}
else
{
        mysql_query('update pm set user2read="yes" where id="'.$id.'" and id2="1"');
        $user_partic = 1;
}
//We get the list of the messages
$req2 = mysql_query('select pm.timestamp, pm.message, users.id as userid, users.username, users.avatar from pm, users where pm.id="'.$id.'" and users.id=pm.user1 order by pm.id2');
//We check if the form has been sent
if(isset($_POST['message']) and $_POST['message']!='')
{
        $message = $_POST['message'];
        //We remove slashes depending on the configuration
        if(get_magic_quotes_gpc())
        {
                $message = stripslashes($message);
        }
        //We protect the variables
        $message = mysql_real_escape_string(nl2br(htmlentities($message, ENT_QUOTES, 'UTF-8')));
        //We send the message and we change the status of the discussion to unread for the recipient
        if(mysql_query('insert into pm (id, id2, title, user1, user2, message, timestamp, user1read, user2read)values("'.$id.'", "'.(intval(mysql_num_rows($req2))+1).'", "", "'.$_SESSION['userid'].'", "", "'.$message.'", "'.time().'", "", "")') and mysql_query('update pm set user'.$user_partic.'read="yes" where id="'.$id.'" and id2="1"'))
        {
?>
<div class="message">Your message has successfully been sent.<br />
<a href="read_pm.php?id=<?php echo $id; ?>">Go to the discussion</a></div>
<?php
        }
        else
        {
?>
<div class="message">An error occurred while sending the message.<br />
<a href="read_pm.php?id=<?php echo $id; ?>">Go to the discussion</a></div>
<?php
        }
}
else
{
//We display the messages
?>
<div class="content">
<h1><?php echo $dn1['title']; ?></h1>
<table class="messages_table">
        <tr>
        <th class="author">User</th>
        <th>Message</th>
    </tr>
<?php
while($dn2 = mysql_fetch_array($req2))
{
?>
        <tr>
        <td class="author center"><?php
if($dn2['avatar']!='')
{
        echo '<img src="'.htmlentities($dn2['avatar']).'" alt="Image Perso" style="max-width:100px;max-height:100px;" />';
}
?><br /><a href="profile.php?id=<?php echo $dn2['userid']; ?>"><?php echo $dn2['username']; ?></a></td>
        <td class="left"><div class="date">Sent: <?php echo date('m/d/Y H:i:s' ,$dn2['timestamp']); ?></div>
        <?php echo $dn2['message']; ?></td>
    </tr>
<?php
}
//We display the reply form
?>
</table><br />
<h2>Reply</h2>
<div class="center">
    <form action="read_pm.php?id=<?php echo $id; ?>" method="post">
        <label for="message" class="center">Message</label><br />
        <textarea cols="40" rows="5" name="message" id="message"></textarea><br />
        <input type="submit" value="Send" />
    </form>
</div>
</div>
<?php
}
}
else
{
        echo '<div class="message">You dont have the rights to access this page.</div>';
}
}
else
{
        echo '<div class="message">This discussion does not exists.</div>';
}
}
else
{
        echo '<div class="message">The discussion ID is not defined.</div>';
}
}
else
{
        echo '<div class="message">You must be logged to access this page.</div>';
}
?>
                <div class="foot"><a href="list_pm.php">Go to my Personal messages</a> - <a href="http://www.webestools.com/">Webestools</a></div>
        </body>

dit is het standaard script bijna aalleen met mijn connceties database
ik heb gelijk fouten dat hij niks kan vinden
wanneer ik de regels zo aan pas
PHP:
//We check if the user is logged
if(isset($_SESSION['users_username']))
krijg ik wat te zien ik kan zenden alleen zie ik dat als ik terug naar index ja dar ik de mail die verstuurd als gelezen
log ik met pietje in zie ik zelfde log ik in als jantje exact zelfde
wil ik de mail openen dan krijg ik volgende
de link http://whatsappgroep.moffia.nl/users/read_pm.php?id=1 alleen een blanco pagina terwijl er van alles hoor te staan
in de database
PHP:
 Volledige teksten	
id
id2
title
user1
user2
message
timestamp
user1read
user2read

Wijzigen Wijzigen
 Kopiëren Kopiëren
 Verwijderen Verwijderen
1
1
strond
0
5
fffkggffgjdf dsffl k 'dflkdge ;
1431071907
yes
no
 
Niet rottig bedoeld, maar gebruik eens interpuncties. Ik kan weinig van je verhaal begrijpen.
Een demo kan ook wel helpen anders om te snappen wat er nou precies gebeurt.
 
Laatst bewerkt:
Blanko page: zet error_reporting en display_errors aan.
Bij voorkeur op een centrale plek in de config ofzo, zodat het over de hele site geldt.
 
dit staat in mijn

PHP:
<?PHP
$localhost = 'localhost'; //name of server. Usually localhost
$database = 'XXX_XXX'; //database name.
$username = 'XXX_xxx'; //database username.
$password = 'bennietgek'; //database password.

// connect to db  
$conn = mysql_connect($localhost, $username, $password) or die('Error connecting to mysql');   
$db = mysql_select_db($database,$conn) or die('Unable to select database!');    

?>
 
Zet in die config dus error_reporting op E_ALL en display_errors aan. Bij voorkeur bovenaaan.

Verder zie ik dat je je password in dit systeem onbeveiligd opslaat. Een grote NO GO!!!!!!!!!
Je leden lopen GROOT gevaar!!!!!!!!!!!

Gebruik password_verify, en password_hash!
 
Laatst bewerkt:
Beste is gewoon from scratch te beginnen, en geen scripts te kopieeren en te plakken.
 
daarom ik gaat ff hondje doen kind zo bij de moeder brengen dan gaat systeem ook eens goed in elkaar zetten op mijn nas
 
Goed idee, laat tussendoor eens wat code zien, zodat mensen er wat over kunnen opmerken. Daar leer je van.
Succes! :)
 
volgende probleem net nieuw script

volgende probleem zijn maar paar kleine probleempjes denk ik

readme

optie 1 gedaan, optie 2, gedaan optie 3 gedaan, optie 4 daar heb standaardwaarde aan mee geven 0 , optie 5 table name is users , optie6 weet ik niet post zo wel foto mee,
optie7 gedaan op tie 8 werkt niet


PHP:
1. Make sure you have a database, if you do not you need to create one.

2. Edit the DB.php file with the information for your database.

3. Run the create_messages_table.sql file on your database.

4. Add pm_count to your users table as an int with a default value of 0, if you 
	do not have a users table or login system thing, you need to get one or make one.

5. If the table for your user information is not named users, you need to edit 
	the script pages, to the correct name of your user information table.

6. Make sure that during login, you make a sessioned variable named username, with 
	the user's username in the variable. If your sessioned username variable is 
	not named username, you need to edit the script pages to the correct session 
	variable for the username.

7. Upload the files and login.

8. If the inbox works, make sure all the other pages work as well, if they don't then e-mail me.
pmcount.png


compose.php
PHP:
<?php
session_start();
$user = $_SESSION['username'];
    
    include 'db.php';
    
    //This checks to see if a user is logged in or not by seeing if the sessioned username varialble exists.
	//You could change this check to however you want to validate your members, this is just how I did it.
    if(!$user)
        {
        echo "<br><p>Blah blah you arent logged in and stuff, you should do that or something</p><br>";
        }
        
    else
        {
        //Query the database to see how many messages the logged in user has, then do a little math
		//Find the percentage that your inbox is full (message count divided by 50)
		//50 messages maximum, you can change that
		$sql = mysql_query ("SELECT pm_count FROM users WHERE username='$user'");
		$row = mysql_fetch_array ($sql);
		$pm_count = $row['pm_count'];
		
		//This is the math to figure out the percentage.
		//The message could divided by 50 then multiplied by 100 so we dont have a number less than 1
		$percent = $pm_count/'50';
		$percent = $percent * '100';
        ?>
        <br>
        <center>
        <b><p><a href="inbox.php">Inbox</a> | <a href="compose.php">Compose</a> | <a href="sent.php">Sentbox</a></b>
        <b><p><?php echo "$pm_count"." of 50 Total  |  "."$percent"."% full"; ?></p></b>
        </center>
        <br>
        <?php
        //So here we get the variable submitted through the form to this page
        $reciever = $_POST['username'];
        $subject = $_POST['subject'];
        $message = $_POST['message'];
        $error = '0';
        
        //If they are all blank we jsut say to compose a message
        if(!$reciever AND !$subject AND !$message)
            {
            ?>
            <p><b>Please compose a message.</b></p>
            <br>
            <?php
            }
        
        //Since this form was partially filled out we need to return an error message
        else
            {
            if (!$reciever)
                {
                $error = 'You must enter a reciever to your message';
                }
            
            if (!$subject)
                {
                $error = 'You must enter a subject';
                }
            
            if (!$message)
                {
                $error = 'You must enter a message';
                }
            
            //If the variable error is not set to zero, we have a problem and should show the error message
            if($error != '0')
                {
                echo "<p>$error</p><br>";
                }
            
            //There are no errors so far which means the form is completely filled out    
            else
                {
                //Are the trying to send a message to a real user or to something they just made up?
                $user_check = mysql_query("SELECT username FROM users WHERE username='$reciever'");
                $user_check = mysql_num_rows($user_check);
                
                //The user is real and not made up if this is true
                if($user_check > '0')
                    {
                    //There might already be a sessioned time variable, if so we need to get it for the flood check
                    $time = $_SESSION['time'];
                    
                    //If there is a time variable already, set it to the varialbe $old_time
                    if($time > '0')
                        {
                        $old_time = $time;
                        }
                    
                    //Here we get the minutes and seconds on the server time using the date function, and set that to the $time variable
                    //Now we find the difference between this time ($time) and the time that the page was submitted ($old_time)
                    $time = date('is');
                    $difference = $time - $old_time;
                    
                    $_SESSION['time'] = $time;
                    
                    //If the two times have a difference greater or equal to 15, which is 15 seconds, they can submit the message, this is for flood protection
                    if($difference >= '15')
                        {
                        //Get their private message count
                        $sql = mysql_query ("SELECT pm_count FROM users WHERE username='$reciever'");
                        $row = mysql_fetch_array ($sql);
                        $pm_count = $row['pm_count'];
                        
                        //You cant have more than 50 private messages, if they try sending a message to a user with a full inbox return an error message
                        if(pm_count == '50')
                            {
                            $error = 'The user you are trying to send a message to has 50 private messages, sorry but we cant send your message untill that user deletes some of their messages.';
                            }
                            
                        else
                            {    
                            //And now we stick the message in the database with all the correct information
                            mysql_query("INSERT INTO messages (reciever, sender, subject, message) VALUES('$reciever', '$user', '$subject', '$message')") or die (mysql_error());
							//Add 1 to the pm count, update the reciever with the new pm count
							$pm_count++;
							mysql_query("UPDATE users SET pm_count='$pm_count' WHERE username='$reciever'");
                            }
                            
                        //Let the user know everything went ok.
                        echo "<p><b>You have successfully sent a private message!</b></p><br>";
                        }
                    
                    //Since they are trying to send messages faster than every 15 seconds, give them an error message    
                    else
                        {
                        $error = 'You must wait 15 seconds before sending another private message';
                        }
                    }
                
                //If they mis spelled or, made up a username, then give an error message telling them its wrong.
                else
                    {
                    $error = 'That username does not exist, please try again. Remember to check your spelling, and don\'t make stuff up at random.';
                    }
                }
            }
            
        //Since we may have set the error variable to something while trying to send the messae, we need another error check
        if($error != '0')
            {
            echo "<p>$error</p><br>";
            }
            
        else
            {
            //Here's the form for the input
            ?>
            <form name="send" method="post" action="compose.php">
            <table width="80%">
              <tr>
                <td width="150px" align="left" valign="top"><p>Username</p></td>
                <td width="" align="left" valign="top"><input name="username" type="text" id="username" value="<?php echo "$reciever"; ?>"></td>
              </tr>
              
              <tr>
                <td width="150px" align="left" valign="top"><p>Subject</p></td>
                <td width="" align="left" valign="top"><input name="subject" type="text" id="subject" value="<?php echo "$subject"; ?>"></td>
              </tr>
              
              <tr>
                <td width="150px" align="left" valign="top"><p>Message Body</p></td>
                <td width="" align="left" valign="top"><textarea name="message" type="text" id="message" value="" cols="50" rows="10"></textarea></td>
              </tr>
                  
              <tr>  
                <td></td>
                <td><input type="submit" name="Submit" value="Send Message"></td>
              </tr>
            </table>
            </center>
            </form>
            <?php
            }
        }    
    ?>

delete.php
PHP:
<?php
session_start();
header("Location:inbox.php");

$user = $_SESSION['username'];

include 'db.php';

//We do not have a user check on this page, because it seems silly to, you just send data to this page then it directs you right back to inbox

//We need to get the total number of private messages the user has
$sql = mysql_query ("SELECT pm_count FROM users WHERE username='$user'");
$row = mysql_fetch_array ($sql);
$pm_count = $row['pm_count'];
            
//A foreach loop for each pm in the array, get the values and set it as $pm_id because they were the ones selected for deletion
foreach($_POST['pms'] as $num => $pm_id)
	{
	//Delete the PM from the database
	mysql_query("DELETE FROM messages WHERE id='$pm_id' AND reciever='$user'");
	
	//Subtract a private message from the counter! YAY!
	$pm_count = $pm_count - '1';
	
	//Now update the users message count with the new value
	mysql_query("UPDATE users SET pm_count='$pm_count' WHERE username='$user'");
	}
?>


inbox.php
PHP:
<?php
session_start();
$user = $_SESSION['username'];
	
include 'db.php';
		
//This checks to see if a user is logged in or not by seeing if the sessioned username varialble exists.
//You could change this check to however you want to validate your members, this is just how I did it.
if(!$user)
	{
	echo "<br><p>Blah blah you arent logged in and stuff, you should do that or something</p><br>";
	}

else
	{
	//Query the database to see how many messages the logged in user has, then do a little math
	//Find the percentage that your inbox is full (message count divided by 50)
	//50 messages maximum, you can change that
	$sql = mysql_query ("SELECT pm_count FROM users WHERE username='$user'");
	$row = mysql_fetch_array ($sql);
	$pm_count = $row['pm_count'];
	
	//This is the math to figure out the percentage.
	//The message could divided by 50 then multiplied by 100 so we dont have a number less than 1
	$percent = $pm_count/'50';
	$percent = $percent * '100';
	
	//Next we come out of PHP and show some HTML, the inbox fullness, links to the other message system pages, the messages, etc.
	?>
	<br>
	<center>
	<b><p><a href="inbox.php">Inbox</a> | <a href="compose.php">Compose</a> | <a href="sent.php">Sentbox</a></b>
	<b><p><?php echo "$pm_count"." of 50 Total  |  "."$percent"."% full"; ?></p></b>
	</center>
	<br>
	<?php
	//This stuff and the while loop will query the database, see if you have messages or not, and display them if you do
	$query = "SELECT id, sender, subject, message FROM messages WHERE reciever='$user'";
	$sqlinbox = mysql_query($query);
	
	//We have a mysql error, we should probably let somone know about the error, so we should print the error
	if(!$sqlinbox)
		{
		?>
		<p><?php print '$query: '.$query.mysql_error();?></p>
		<?php
		}
	
	//There are no rows found for the user that is logged in, so that either means they have no messages or something broke, lets assume them they have no messages
	elseif (!mysql_num_rows($sqlinbox) )
		{
		?>
		<center><p><b>You have no messages to display</b></p></center>
		<?php
		}
	
	//There are no errors, and they do have messages, lets query the database and get the information after we make a table to put the information into
	else
		{
		//Ok, Lets center this whole table Im going to make just because I like it like that
		//Then we create a table 80% the total width, with 3 columns, The subject is 75% of the whole table, the sender is 120 pixels (should be plenty) and the select checkboxes only get 25 pixels
		?>
		<center>
		<form name="send" method="post" action="delete.php">
		<table width="80%">
		<tr>
		  <td width="75%" valign="top"><p><b><u>Subject</u></b></p></td>
		  <td width="120px" valign="top"><p><b><u>Sender</u></b></p></td>  
		  <td width="25px" valign="top"><p><b><u>Select</u></b></p></td>
		</tr>
		<?php
		//Since everything is good so far and we earlier did a query to get all the message information we need to display the information. 
		//This while loop goes through the array outputting all of the message information
		while($inbox = mysql_fetch_array($sqlinbox))
			{
			//These are the variables we get from the array as it is going through the messages, we have the id of the private message, we have the person who sent the message, we have the subject of the message, and yeah thats it
			$pm_id = $inbox['id'];
			$sender = $inbox['sender'];
			$subject = $inbox['subject'];
			
			//So lets show the subject and make that a link to the view message page, we will send the message id through the URL to the view message page so the message can be displayed
			//And also let the person see who sent it to them, if you want you can make that some sort of a link to view more stuff about the user, but Im not doing that here, I did it for my game though, similar to the viewmsg.php page but a different page, and with the senders id
			//And finally the checkboxes that are all stuck into an array and if they are selected we stick the private message id into the array
			//I will only let my users have a maximum of 50 messages, remeber that ok? Because that's the value I will later in another page
			//Here is finally the html output for the message data, the while loop keeps going untill it runs out of messages
			?>
			<tr>
			  <td width="75%" valign="top"><p><a href="viewmsg.php?msg_id=<?php echo $pm_id; ?>"><?php echo $subject; ?></a></p></td>
			  <td width="120px" valign="top"><p><?php echo $sender; ?></p></td>
			  <td width="25px" valign="top"><input name="pms[]" type="checkbox" value="<?php echo $pm_id; ?>"></td>
			</tr>
			<?php
			//This ends the while loop
			}
		//Here is a submit button for the form that sends the delete page the message ids in an array
		?>
		<tr>  
		<td colspan="3"><input type="submit" name="Submit" value="Delete Selected"></td>
		<td></td>
		<td></td>
		</tr>
		</table>
		</center>
		<?php
		//So this ends the else to see if it is all ok and having messages or not
		}
	
	//This ends that first thing that checks if you are logged in or not
	}
?>

sent.php
PHP:
<?php
session_start();
$user = $_SESSION['username'];
    
include 'db.php';
    
//This checks to see if a user is logged in or not by seeing if the sessioned username varialble exists.
//You could change this check to however you want to validate your members, this is just how I did it.
if(!$user)
	{
	echo "<br><p>Blah blah you arent logged in and stuff, you should do that or something</p><br>";
	}

else
	{
	//Query the database to see how many messages the logged in user has, then do a little math
	//Find the percentage that your inbox is full (message count divided by 50)
	//50 messages maximum, you can change that
	$sql = mysql_query ("SELECT pm_count FROM users WHERE username='$user'");
	$row = mysql_fetch_array ($sql);
	$pm_count = $row['pm_count'];
	
	//This is the math to figure out the percentage.
	//The message could divided by 50 then multiplied by 100 so we dont have a number less than 1
	$percent = $pm_count/'50';
	$percent = $percent * '100';
	
	//Next we come out of PHP and show some HTML, the inbox fullness, the messages we have sent that werent recieved or deleted yet
	?>
        <br>
        <center>
        <b><p><a href="inbox.php">Inbox</a> | <a href="compose.php">Compose</a> | <a href="sent.php">Sentbox</a></b>
        <b><p><?php echo "$pm_count"." of 50 Total  |  "."$percent"."% full"; ?></p></b>
        </center>
        <br>
        
        <?php
        //Get all message that are sent by the logged in user, and that have the recieved field set to zero, meaning they have not been recieved, once read the view message page sets the recieved field for the message to 1
        $query = "SELECT * FROM messages WHERE sender='$user' AND recieved='0'";
        $sqlinbox = mysql_query($query);
        
        //If there is a MySQL error we need to display the error because something has gone horribly wrong on the server.
        if(!$sqlinbox)
            {
            ?>
            <p><?php print '$query: '.$query.mysql_error();?></p>
            <?php
            }
        
        //If all messages sent by the user were recieved or deleted, then jsut say that there are no messages not recieved  
        elseif (!mysql_num_rows($sqlinbox) )
            {
            ?>
            <p><b>You have no un-recieved messages to display</b></p>
            <?php
            }
        
        //If there are messages that have not been recieved yet we need to display those messages to the user
        else
            {
            //Lets make a table for the messages to go in, to keep things organised and such
            ?>
            <table width="80%" border="0">
              <tr>
                  <td width="" valign="top"><p><b><u>Subject</u></b></p></td>
                  <td width="120px" valign="top"><p><b><u>Sender</u></b></p></td>  
              </tr>
            <?php
            //This is a while loop that goes through the array while there are still things in it, getting the subject and reciever and displaying them
            while($inbox = mysql_fetch_array($sqlinbox))
                {
                $reciever = $inbox['reciever'];
                $subject = $inbox['subject'];
                ?>
                <tr>
                  <td width="" valign="top"><p><?php echo "$subject"; ?></p></td>
                  <td width="120px" valign="top"><p><?php echo "$reciever"; ?></p></td>  
                </tr>
                <?php
                }
            echo "</table>";
            }
        }    
    ?>

viewmsg.php
PHP:
<?php
session_start();
$user = $_SESSION['username'];
    
    include 'db.php';
    
    //This checks to see if a user is logged in or not by seeing if the sessioned username varialble exists.
	//You could change this check to however you want to validate your members, this is just how I did it.
    if(!$user)
        {
        echo "<br><p>Blah blah you arent logged in and stuff, you should do that or something</p><br>";
        }
        
    else
        {
        //We need to grab the msg_id variable from the URL.
        $msg_id = $_REQUEST['msg_id'];
        
        //Get all of the information about the message with the id number sent through the URL
        $view_msg = mysql_query("SELECT * FROM messages WHERE id = '$msg_id'");
        $msg = mysql_fetch_array($view_msg);
        
        $reciever = $msg['reciever'];
        $sender = $msg['sender'];
        $subject = $msg['subject'];
        $message = $msg['message'];
        
        //If the person who is supposed to recieve the message is the currently logged in user everything is good
        if($reciever == $user)
            {
            //The message was recieved, so lets update the message in the database so it wont show up in the sent page any more
            mysql_query("UPDATE messages SET recieved='1' WHERE id = '$msg_id'");
            
            //Query the database to see how many messages the logged in user has, then do a little math
			//Find the percentage that your inbox is full (message count divided by 50)
			//50 messages maximum, you can change that
			$sql = mysql_query ("SELECT pm_count FROM users WHERE username='$user'");
			$row = mysql_fetch_array ($sql);
			$pm_count = $row['pm_count'];
			
			//This is the math to figure out the percentage.
			//The message could divided by 50 then multiplied by 100 so we dont have a number less than 1
			$percent = $pm_count/'50';
			$percent = $percent * '100';
            
            //Now we will display the little navigation thing, the fullness of the inbox, then display message information stuff, like who its from, the subject, and the body
            ?>
            <br>
            <center>
            <b><p><a href="inbox.php">Inbox</a> | <a href="compose.php">Compose</a> | <a href="sent.php">Sentbox</a></b>
            <b><p><?php echo "$pm_count"." of 50 Total  |  "."$percent"."% full"; ?></p></b>
            </center>
            <br>
            
            <table width="80%">
              <tr>
                <td width="120px"><p>From:</p></td>
                <td width=""><p><a href = "<?php echo "../user/profile.php?user_name=$sender"; ?>"><?php echo $sender; ?></a></p></td>
              </tr>
              
              <tr>
                <td width="120px"><p>Subject:</p></td>
                <td width=""><p><?php echo $subject; ?></p></td>
              </tr>
              
              <tr>    
                <td width="120px"><p>Message Body:</p></td>
                <td width=""><p><?php echo $message; ?></p></td>
              </tr>
            </table>
            </center>
            <?php
            }
        //Everything is not good, someone tried to look at somone else's private message
        else
            {
            ?>
            <p>It appears you are trying to view someone else's private message. Please view your own private messages, or go away.</p>
            <?php
            }
        }
    ?>


create_messages_table.txt
PHP:
-- 
-- Table structure for table `messages`
-- 

CREATE TABLE `messages` (
  `id` int(11) NOT NULL auto_increment,
  `reciever` varchar(25) NOT NULL default '',
  `sender` varchar(25) NOT NULL default '',
  `subject` text NOT NULL,
  `message` longtext NOT NULL,
  `recieved` enum('0','1') NOT NULL default '0',
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

-- 
-- Dumping data for table `messages`
--

alles volgens mijn bijna alles zo precies gedaan als moet
nu stuit ik op alle pagina op probleem
zo als het hie staat zal script nooit werker want schijnt fout te zitten
wanneer ik over al de tekst ver ander in
PHP:
<?php
session_start();
$user = $_SESSION['user_id'];
	
include '../lib/connections/db.php';

ko ik in het systeem
wanneer pagina inbox ben werk mijn dreamweaver wat op retgel 32 </b> en regel 103 </center zie geen delete knop staan niks
wanneer ik naar pagina compose.php gaat is gedeelte zenden van de pb en type een gebruiker is en title en een vehaaltje
wordt het verzonden als ik in de database kijk
versturen.png

om je ff een iut te leggen
admin heeft id 1
conosci heeft id 2
demo heeft id 3
in table users echter door dat de database groot is zal ik hier gen af beelding van maken
maar in row pm_count staat

bij pm_count
admin 1
conosci 2
demo 4


heeft iemand een enige idee hoe ik dit kan oplossen om dit script werkend te krijgen
zo aan te passen voor dat het werkt
 
Wat is kort samengevat nou je probleem?
 
kortom $user=$_sesssion['user_id']
en ik krijg de link niet naar de berichten om de berichten i te kijken bij inbox regel 88 heel dat onder plaatje zie ik niks van
 
Waarom nou de waarde van je variabelen dupliceren?? Je kan toch direct $inbox['id'] gebruiken?
En als die leeg is, controleer eens wat een print_r($inbox); doet.
 
Nadat die array gedefinieerd is uiteraard. Logisch kijken, en je komt er zelf acht...
trial and error!
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan