Jump to content

Archived

This topic is now archived and is closed to further replies.

mattennant

session variables

Recommended Posts

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

Share this post


Link to post
Share on other sites

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/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<title>Untitled Document</title>

</head>

 

<body>

<p> </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"> </td>

<td> </td>

</tr>

<tr valign="baseline">

<td nowrap align="right"> </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> </p>

</body>

</html>

<?php

mysql_free_result($Recordset1);

?>

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.