PHP MySQL problem

Thread Solved

Join Date: Aug 2007
Posts: 9
Reputation: jeffro25 is an unknown quantity at this point 
Solved Threads: 0
jeffro25 jeffro25 is offline Offline
Newbie Poster

PHP MySQL problem

 
0
  #1
Aug 20th, 2007
Hey guys. Got a quick question. I am having a problem with a message board that I am creating. I have created the log in and registration page and the sessions needed to use the site nad it all works fine, but when the user posts a message I can't get the unique user name to appear for the message that user posts. I can get it to appear as long as the users session is still valid, but once the user logs out, the session is terminated and the users name is gone from the message board. Please help?
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,483
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 515
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: PHP MySQL problem

 
0
  #2
Aug 20th, 2007
Are you not storing the user id with the post? If you are then you just need to display the name associated with that id. The name (id) associated with a post should not have any dependency on whether a user is logged in.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 9
Reputation: jeffro25 is an unknown quantity at this point 
Solved Threads: 0
jeffro25 jeffro25 is offline Offline
Newbie Poster

Re: PHP MySQL problem

 
0
  #3
Aug 20th, 2007
Well, I am trying to use the login name as the post name for the message. I can set the $_session['MM_Username'] to it and it works until they log out. I can make it show up, but the user would have to put their user name in again with the message and thats what I am trying to avoid.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,483
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 515
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: PHP MySQL problem

 
0
  #4
Aug 20th, 2007
If the login name is the id for the user in the database, then that's fine to keep it in the session while they are logged in. You will still need to write that value to the database with the post though. The page that displays posts should retrieve the name of the poster along with the post from the database.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 9
Reputation: jeffro25 is an unknown quantity at this point 
Solved Threads: 0
jeffro25 jeffro25 is offline Offline
Newbie Poster

Re: PHP MySQL problem

 
0
  #5
Aug 20th, 2007
Thats where I think I am giong wrong. I've tried to do that, but it just doesn't work. Any suggestions on the line of code that i could use? I've tried setting the $loginuser name and session variables to the user id in the database. Obviously not the right thing to do.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,483
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 515
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: PHP MySQL problem

 
0
  #6
Aug 20th, 2007
Originally Posted by jeffro25 View Post
I've tried setting the $loginuser name and session variables to the user id in the database. Obviously not the right thing to do.
Actually, I would store both the user name and the id in the session. Whatever statement that saves the post just needs to include the id. The query that shows posts just needs to display the name along side the comment, so pull all that info in a single query. If you are confused by that, post your code and we can figure out how to change it.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 9
Reputation: jeffro25 is an unknown quantity at this point 
Solved Threads: 0
jeffro25 jeffro25 is offline Offline
Newbie Poster

Re: PHP MySQL problem

 
0
  #7
Aug 20th, 2007
Originally Posted by Ezzaral View Post
Actually, I would store both the user name and the id in the session. Whatever statement that saves the post just needs to include the id. The query that shows posts just needs to display the name along side the comment, so pull all that info in a single query. If you are confused by that, post your code and we can figure out how to change it.

Aw man....I get it...Thanks...I am about to head out of work for the day...We'll see how it goes tonight and I'll let you know tomorrow...Thanks for all your help!
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 9
Reputation: jeffro25 is an unknown quantity at this point 
Solved Threads: 0
jeffro25 jeffro25 is offline Offline
Newbie Poster

Re: PHP MySQL problem

 
0
  #8
Aug 21st, 2007
Still having problems with this...any ideas anyone?
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,483
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 515
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: PHP MySQL problem

 
0
  #9
Aug 21st, 2007
Originally Posted by jeffro25 View Post
Still having problems with this...any ideas anyone?
Post the relevant code. Without that we can only speculate and offer generic suggestions.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 9
Reputation: jeffro25 is an unknown quantity at this point 
Solved Threads: 0
jeffro25 jeffro25 is offline Offline
Newbie Poster

Re: PHP MySQL problem

 
0
  #10
Aug 21st, 2007
<?php require_once('Connections/riders.php'); ?>
<?php
if (!isset($_SESSION)) {
session_start();
}


$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
$logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
$_SESSION['MM_Username'] = NULL;
$_SESSION['MM_UserGroup'] = NULL;
$_SESSION['PrevUrl'] = NULL;
unset($_SESSION['MM_Username']);
unset($_SESSION['MM_UserGroup']);
unset($_SESSION['PrevUrl']);

$logoutGoTo = "index.php";
if ($logoutGoTo) {
header("Location: $logoutGoTo");
exit;
}
}
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO messages (message) VALUES (%s)",
GetSQLValueString($_POST['textarea'], "text"));

mysql_select_db($database_riders, $riders);
$Result1 = mysql_query($insertSQL, $riders) or die(mysql_error());

$insertGoTo = "messagepost.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Bruces Rider's Social Network. Plan rides, meet new people, or just bike talk.</title>
<style type="text/css">
<!--
body {
background-color: #000000;
}
.style9 {
font-size: 48px;
color: #FFFFFF;
}
.mystyle {
font-family: Arial, Helvetica, sans-serif;
color: #FFFFFF;
font-size: medium;
font-weight: bold;
}
.style11 {color: #FFFFFF}
-->
</style></head>

<body>
<table width="834" height="477" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="241" rowspan="2" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="241" height="192" valign="top"><img src="images/all-stores-bitmap.jpg" width="241" height="192" /></td>
</tr>
<tr>
<td height="92" valign="top"><table width="100%" height="105" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="241" height="22" valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>
</tr>
<tr>
<td height="49">&nbsp;</td>
</tr>
<tr>
<td height="34" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="241" height="34" valign="top" class="mystyle"><a href="<?php echo $logoutAction ?>" class="style11">Log out</a></td>
</tr>
</table> </td>
</tr>
</table> </td>
</tr>
</table></td>
<td width="593" height="57" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="589" height="49" valign="top"><div align="center"><span class="style9">Welcome to Bruces Riders!</span></div></td>
</tr>
</table>
<td width="593" height="156">&nbsp;</td>
</tr>
<tr>
<td width="593" height="113" valign="top" class="mystyle"><?php echo $_SESSION['MM_Username']; ?> ,please feel free to post a message.
<form action="<?php echo $editFormAction; ?>" id="form1" name="form1" method="POST">
<br />
<label>
<textarea name="textarea" id="textarea" cols="45" rows="5">Type message here.</textarea>
</label>
<p>
<label>
<input type="submit" name="button" id="button" value="Submit" />
</label>
</p>


<input type="hidden" name="MM_insert" value="form1" />
</form> </td>
</tr>
</table></td>
</tr>
</table>
</td>
</tr>
<tr>
<td height="19" colspan="2">&nbsp;</td>
</tr>
</table>
</body>
</html>

This is the page that actually inserts the record into the database.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC