Jump to content


Photo

session variables


  • Please log in to reply
3 replies to this topic

#1 mattennant

mattennant
  • Members
  • PipPipPip
  • Advanced Member
  • 42 posts

Posted 26 March 2005 - 02:36 PM

hello
i'm trying to create a page where a user enters a name and password into the database. After inserting the users name is passed as a session variable to a thankyou page. I've got no problems passing a session variable from a standard form (i.e not an insert record) but when i try and retrieve the session variable after inserting these user details nothing appears.
here's hoping someone has the answer.
thanks
mat

#2 mattennant

mattennant
  • Members
  • PipPipPip
  • Advanced Member
  • 42 posts

Posted 29 March 2005 - 03:18 PM

I realise now that not sending any code is a bit of a mistake, the problem still remains that when i add seesion start to the top of the page i get the following error

Warning: Cannot modify header information - headers already sent by (output started at /home/fhlinux195/m/matthewtennant.com/user/htdocs/newscomment.php:3) in /home/fhlinux195/m/matthewtennant.com/user/htdocs/newscomment.php on line 61

a username does get added to my database via a hidden field as required

is there a problem with session variable when iserting fields in dreamweaver?

here comes the reams of code

line 61 is

header(sprintf("Location: %s", $insertGoTo));

thanks

<?php
session_start(); ?>
<?php require_once('Connections/mattyboy.php'); ?>
<?php
$colname_Recordset1 = "1";
if (isset($_GET['recordID'])) {
$colname_Recordset1 = (get_magic_quotes_gpc()) ? $_GET['recordID'] : addslashes($_GET['recordID']);
}
mysql_select_db($database_mattyboy, $mattyboy);
$query_Recordset1 = sprintf("SELECT * FROM studentvillagenews WHERE number = %s", $colname_Recordset1);
$Recordset1 = mysql_query($query_Recordset1, $mattyboy) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<?php require_once('Connections/mattyboy.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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 studentvillagenewscomment (numcat, comment, username) VALUES (%s, %s, %s)",
GetSQLValueString($_POST['numcat'], "int"),
GetSQLValueString($_POST['comment'], "text"),
GetSQLValueString($_POST['username'], "text"));

mysql_select_db($database_mattyboy, $mattyboy);
$Result1 = mysql_query($insertSQL, $mattyboy) or die(mysql_error());

$insertGoTo = "news.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR...ml4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>

<body>
<p>&nbsp;</p>

<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
<table align="center">
<tr valign="baseline">
<td nowrap align="right" valign="top">Comment:</td>
<td><textarea name="comment" cols="50" rows="5"></textarea>
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right" valign="top">&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">&nbsp;</td>
<td><input type="submit" value="Insert record"></td>
</tr>
</table>
<input type="hidden" name="numcat" value="<?php echo $row_Recordset1['number']; ?>">
<input type="hidden" name="MM_insert" value="form1">
<input name="username" type="hidden" id="username" value="<?php echo $_SESSION['surname']; ?>">
</form>
<p>&nbsp;</p>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>

#3 mananthpai

mananthpai
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 19 April 2005 - 07:54 AM

Hi there you have to put the header's before any output to the browsers even space should not be there in ur code
so you have to write <?php session_start()?>
in the very first line of ur code page and there should not be any sapce before this line
try this out this might fix ur problem

#4 mattennant

mattennant
  • Members
  • PipPipPip
  • Advanced Member
  • 42 posts

Posted 29 April 2005 - 10:44 PM

thanks so much, that did the trick - cheers




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users