943,929 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 2428
  • PHP RSS
You are currently viewing page 1 of this multi-page discussion thread
Aug 20th, 2007
0

PHP MySQL problem

Expand Post »
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?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jeffro25 is offline Offline
9 posts
since Aug 2007
Aug 20th, 2007
0

Re: PHP MySQL problem

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.
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 839
Posting Genius
Ezzaral is offline Offline
6,761 posts
since May 2007
Aug 20th, 2007
0

Re: PHP MySQL problem

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jeffro25 is offline Offline
9 posts
since Aug 2007
Aug 20th, 2007
0

Re: PHP MySQL problem

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.
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 839
Posting Genius
Ezzaral is offline Offline
6,761 posts
since May 2007
Aug 20th, 2007
0

Re: PHP MySQL problem

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jeffro25 is offline Offline
9 posts
since Aug 2007
Aug 20th, 2007
0

Re: PHP MySQL problem

Click to Expand / Collapse  Quote originally posted by jeffro25 ...
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.
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 839
Posting Genius
Ezzaral is offline Offline
6,761 posts
since May 2007
Aug 20th, 2007
0

Re: PHP MySQL problem

Click to Expand / Collapse  Quote originally posted by Ezzaral ...
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!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jeffro25 is offline Offline
9 posts
since Aug 2007
Aug 21st, 2007
0

Re: PHP MySQL problem

Still having problems with this...any ideas anyone?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jeffro25 is offline Offline
9 posts
since Aug 2007
Aug 21st, 2007
0

Re: PHP MySQL problem

Click to Expand / Collapse  Quote originally posted by jeffro25 ...
Still having problems with this...any ideas anyone?
Post the relevant code. Without that we can only speculate and offer generic suggestions.
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 839
Posting Genius
Ezzaral is offline Offline
6,761 posts
since May 2007
Aug 21st, 2007
0

Re: PHP MySQL problem

<?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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jeffro25 is offline Offline
9 posts
since Aug 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: tips & tricks of web development
Next Thread in PHP Forum Timeline: storing multiple email address problem





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC