I'm dizzy trying to figure out what I should do, I will treasure whoever can help me!
When a user comes to the site they are automatically in their own $_SESSION, they are greeted by their username, it looks professional really nice... If the person is not a member they are redirected... I luv it!
I am using this script:
<?
include 'db.php';
// get the variables from home page
$password = $_SESSION['password'];
$email_address = $_SESSION['email_address'];
$sql_check = mysql_query("SELECT username FROM members WHERE password='$password' AND
email_address='$email_address'");
$username = mysql_fetch_array($sql_check, MYSQL_BOTH); //MYSQL_BOTH;
$sql_check_num = mysql_num_rows($sql_check);
if($sql_check_num == 0){
echo ("");
} else {
echo ucfirst($username['username']);
}
// Define post fields into simple variables
$email_address = $_SESSION['email_address'];
$password = $_SESSION['password'];
/* Let's strip some slashes in case the user entered
any escaped characters. */
$email_address = stripslashes($email_address);
$password = stripslashes($password);
/* Do some error checking on the form posted fields */
if((!$email_address) || (!$password)){
echo '<STRONG><br><br>Enter required fields as indicated below
<br>If you are a member!</STRONG><a href="login_form.php"><u> Login Here</u></a>
<br><STRONG>To become a member!</STRONG><a href="join_form.php"><u> Join Here</u>
</a><br><br />';
if(!$email_address){
echo "<font color='#000000'>Email address is a required field.</font><br />";
}
if(!$password){
echo "<font color='#000000'>Password is a required field.</font><br />";
}
exit(); // if the error checking has failed, we'll exit the script!
}
?>
Now I want to let my users message each other. I have created a second table just for the messages, it includes the user_id= the to username and from=who sent the message and message=the message.
I must keep the user in their session of course and this way I have their username, Now how do I use the select to verify the user and at the same time.... select that users messages by their username to the other table... But! on that 2nd table their username is under user_id...
And I cannot use username on both tables because on the message page that has the form in the input name= .... it does not allow it , I get an error if I try to use username.
I am trying to get the correct php script to work with mysql, I am trying to use: SELECT, JOIN OR UNION AND WHERE AS ONE... Is this possible?
I am trying something like this, but it's not working, can you see how I can script it to work?
<?php
include 'db.php';
// get the variables from home page
$email_address = $_SESSION['email_address'];
$password = $_SESSION['password'];
$userame = $_SESSION['username'];
$user_id = $_SESSION['user_id'];
$query = "SELECT messages.user_id, members.username ".
"FROM messages, members".
"WHERE members.username = members.email_address
AND members.username = members.password
AND messages.user_id = members.username";
$result = mysql_query($query) or die(mysql_error());
$sql_check_num = mysql_num_rows($sql_check);
if($sql_check_num == 0){
// Print out the contents of each row into a table
while($row = mysql_fetch_array($result)){
echo $row['username']. " - ". $row['user_id'];
echo "<br />";
}
?>
I need help! Thanks kindly , puddin