i'm trying to put my php code that connects to my MySQL database directly in my HTML page, but something goes wrong when i try to see the page.. how can i solve the error "Fatal error: Maximum execution time of 30 seconds exceeded in /membri/bestparty/IOS/IOS/eventi.php on line 41"
if i try to remove one variable for example $festa[$i] the error persists.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="HandheldFriendly" content="True">
<meta http-equiv="cleartype" content="on">
<link rel="stylesheet" type="text/css" href="css/stile.css">
<meta name="viewport" content="width=320, initial-scale=0.7, user-scalable=no">
<script src="JS/jquery-1.11.1.js.js"></script> <!--PER EVENTI-->
<script src="JS/func.js"></script> <!--PER EVENTI-->
<title>BParty</title>
</head>
<body>
<?
$DBhost = "localhost";
$DBuser = "bestparty";
$DBpass = "";
$DBName = "my_bestparty";
$table = "Dati";
mysql_connect($DBhost,$DBuser,$DBpass) or die("Impossibile collegarsi al server");
#mysql_select_db("$DBName") or die("Impossibile connettersi al database $DBName");
$sqlquery = "SELECT * FROM `Dati` ORDER BY Data DESC";
$result = mysql_query($sqlquery);
$number = mysql_num_rows($result);
$i = 0;
while ($i < 20) {
$festa[$i] = mysql_result($result,$i,"festa");
$luogo[$i] = mysql_result($result,$i,"luogo");
$idfesta[$i] = mysql_result($result,$i,"ID");
$data[$i] = mysql_result($result,$i,"data");
$foto[$i] = mysql_result($result,$i,"organizzatore");
}
?>
<div id="navigation">
<table width="100%">
<tr valign="middle">
<td valign="middle" width="25%" align="center">
<
</td>
<td valign="middle" width="50%" align="center">
BPARTY
</td>
<td width="25%" align="center">
>
</td>
</tr>
</table>
</div>
<div id="evntprg">
EVENTI IN PROGRAMMA
</div>
<div id="container" style="overflow:scroll;">
<? echo'
<!--INIZIO DIV EVENTO-->
<a href="http://www.bparty.org/IOS/IOS/pagevento.php?var=$idfesta[$i]">
<div style="width:90%; display:block; margin:0 auto;
padding-top:10px; margin-top:10px; padding-left:10px;
background-color:#FFF; padding-bottom:10px;
border-left:solid 8px #4D7C4F;">
<table width="100%" style=\'table-layout:fixed\'>
<tr valign="middle">
<td valign="middle" align="center" class="evntfoto"
style="background-image:url($foto[$i]);
background-position:center;
background-size: cover;">
</td>
<td valign="top" align="left" id="evnttxt">
<font color="#0066FF" size="+1"> <b> $festa[$i] </b></font> <br>
echo "$data[$i]" <br>
<font color="#585858"> $luogo[$i] </font> <br>
</td>
</tr>
</table>
</div></a>
<!--FINE DIV EVENTO-->
';
?>
</div>
</div>
</body>
</html>
--EDIT--
Ok, i solved this, but now..
why the html page shows me the variable as "$festa[$i]"
and not for example "Lorem ipsum" ?
<?
$DBhost = "localhost";
$DBuser = "bestparty";
$DBpass = "";
$DBName = "my_bestparty";
$table = "Database";
mysql_connect($DBhost,$DBuser,$DBpass) or die("Impossibile collegarsi al server");
#mysql_select_db("$DBName") or die("Impossibile connettersi al database $DBName");
$sqlquery = "SELECT * FROM `Database` ORDER BY data DESC";
$result = mysql_query($sqlquery);
$number = mysql_num_rows($result);
$i = 0;
while ($i < 20) {
$festa[$i] = mysql_result($result,$i,"festa");
$luogo[$i] = mysql_result($result,$i,"luogo");
$idfesta[$i] = mysql_result($result,$i,"ID");
$data[$i] = mysql_result($result,$i,"data");
$linkfoto[$i] = mysql_result($result,$i,"organizzatore");
echo'
<!--INIZIO DIV EVENTO-->
<a href="http://www.bparty.org/IOS/IOS/pagevento.php?var=$idfesta[$i]">
<div style="width:90%; display:block; margin:0 auto;
padding-top:10px; margin-top:10px; padding-left:10px;
background-color:#FFF; padding-bottom:10px;
border-left:solid 8px #4D7C4F;">
<table width="100%" style=\'table-layout:fixed\'>
<tr valign="middle">
<td valign="middle" align="center" class="evntfoto"
style="background-image:url($foto[$i]);
background-position:center;
background-size: cover;">
</td>
<td valign="top" align="left" id="evnttxt">
<font color="#0066FF" size="+1"> <b> $festa[$i] </b></font> <br>
echo "$data[$i]" <br>
<font color="#585858"> $luogo[$i] </font> <br>
</td>
</tr>
</table>
</div>
</a>
<!--FINE DIV EVENTO-->
';
$i++;
}
You are not incrementing $i inside your loop. Consider using a for loop instead. See also the PHP documentation on for loops.
Ok, i solved this, but now.. why the html page shows me the variable as "$festa[$i]" and not for example "Lorem ipsum" ?
You should use double quotes instead of single if you want a variable in the string to get printed. But in your case you'd have to escape all double quotes in your string this way \". The better way is instead of doing that, just to concatenate the string like this:
echo '...<b>' . $festa[$i] . '</b>...';
Do that with all variables you're echoing.
Related
I have a table with horizontal scrolling, but I dont like the scrollbar, so I want to change it to a dot.
I tried using flickity but I have some problems.
Code:
<head>
<script src="https://unpkg.com/flickity#2/dist/flickity.pkgd.min.js"></script>
<link rel="stylesheet" href="https://unpkg.com/flickity#2/dist/flickity.min.css">
<link rel="stylesheet"
href=
"https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<body>
<style>
.scrollme {
overflow-x: auto;
}
::-webkit-scrollbar {
width: 2px;
height:5px;
}
}
</style>
<div class="container" >
<?php
require 'db.php';
$sql = "SELECT * FROM clelist order by clelist_id DESC";
$result = mysqli_query($db, $sql );
echo "<div class='carousel scrollme' style='' data-flickity="" data-js='carousel'>
<table class='table table-bordered text-center table-responsive '>
<tr class='table-active '>
<th class='text-center align-middle carousel-cell' style=' white-space:nowrap;' > num </th>
<th class='text-center align-middle carousel-cell 'style=' white-space:nowrap;' > car_num</th>
<!--more.....-->
</tr>";
while ($row = mysqli_fetch_array($result)) {
$tmp=explode(":",$row['cle_date']);
echo '
<tbody id="searchTable">
<tr>
<td class="text-center align-middle carousel-cell" >
'.$row["DlistNO"].'<br>'.$row["cle_no"].'
</td>
<td class="text-center align-middle carousel-cell" >
'.$row["cle_date"].'<br>
'.$row["c_cle_car_no_head"].'<br>
'.$row["c_cle_car_no_tail"].'
</td>
<!--more.....-->
';
?>
<tr>
<?php
}
?></tbody>
</table></div>
</div>
</body>
</html>
Output:
Does this answer your question: https://tympanus.net/codrops/2014/01/21/dot-navigation-styles/
Also, you can check out different types of scroll dots here
I created a table where users are discharged from the database. Each user has a row and next to it is a button for deleting a user from the database. The problem is that I do not know how to do to really removed the particular user from the database when I click on a specific button. I have no idea how to do it.
<!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\" lang=\"pl-PL\">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Rezultat zapytania</title>
<style>
#container {
max-width: 1000px;
}
</style>
</head>
<body>
<div id="container">
<table width="1000" align="center" border="1" bordercolor="#d5d5d5" cellpadding="0" cellspacing="0">
<tr>
<?php
require_once "connect.php";
$baza = #new mysqli($host, $db_user, $db_password, $db_name); //Połączenie z bazą danych
$sql = "SELECT id, user, pass, email FROM users";
$result = $baza->query($sql);
$ile = mysqli_num_rows($result);
echo "znaleziono: ".$ile."<br /><br />";
if ($ile>=1)
{
echo<<<END
<td width="50" align="center" bgcolor="e5e5e5"></td>
<td width="50" align="center" bgcolor="e5e5e5">IDUsera</td>
<td width="20" align="center" bgcolor="e5e5e5">NazwaUsera</td>
<td width="20" align="center" bgcolor="e5e5e5">HasloUsera</td>
<td width="20" align="center" bgcolor="e5e5e5">EmailUsera</td>
</tr><tr>
END;
}
for ($i = 1; $i <= $ile; $i++)
{
$row = mysqli_fetch_assoc($result);
$a1 = $row['id'];
$a2 = $row['user'];
$a3 = $row['pass'];
$a4 = $row['email'];
echo<<<END
<td width="50" align="center"><a class="button_red" href="delete_user.php">Delete</a></td>
<td width="50" align="center">$a1</td>
<td width="100" align="center">$a2</td>
<td width="100" align="center">$a3</td>
<td width="100" align="center">$a4</td>
</tr><tr>
END;
}
?>
</tr></table>
</div>
</body>
</html>
// create a <td> tag in <tr>
<td>DEL USER</td>
/* del.php */
$user_id = $_GET['user_id'];
// you can add a sql injection filter
$sql = 'DELETE FROM table WHERE user_id = {$user_id}';
$result = $baza->query($sql);
I'm going nuts to try to understand why the script below (let's call it script1 is passing session variable $_SESSION['emptystcode'] to bulkstOLD.php but not the other two: $_SESSION['dlstrest'] and $_SESSION['dllist']. I have session_start(); on the first command line of the called script.
All this script1 does is to $_GET the Restaurant and List names and display a form where the user can fill in a CODE field and submit it.
To makes things worse, I've created another script (a simplified version of this caller script) which just set the session variables and calls the same bulkstOLD.php and it works ok. I wonder if this has something to do with the $_GET. Any help would be much appreciated.. Thanks!!
Here is the code:
<?php
session_start();
include ('logged.php');
require_once ('functions.php');
$acisversion = $_SESSION['acisversion'];
reset_all();
$cyear = date(Y);
$cmonth = date(M);
$cday = date(d);
$configs = include('config.php');
$_SESSION["module"] = 'st';
$_SESSION['favstlists_ref'] = 0;
$strest = $dlstrest = $_GET['dlstrest'];
$favstlist = $dllist = $_GET['dllist'];
$restname = 'restname_'.$strest;
$stlistrest = $configs[$restname];
?>
<!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=iso-8859-1"/>
<title>ACIS - Edit Lists</title>
<script type="text/javascript" src="jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="stmenu.js"></script>
<style type="text/css">
#import url(acis.css);
</style>
<script type="text/javascript" src="js.js"></script>
</head>
<body>
<div id="content">
<?php
$_SESSION['stcodesub'] = $stcodesub = $stcode = ($_POST["stcodein"]);
dbfile_init() ;
$_SESSION['stcode'] = $stcode;
if(isset($_POST["editSave"]))
{
connect_db ();
if (!empty($stcode))
{
check_code_for_st_list();
$emptystcode = 0;
}
else
{
$emptystcode = 1;
}
$_SESSION['dlstrest'] = $dlstrest;
$_SESSION['dllist'] = $dllist;
$_SESSION['emptystcode'] = $emptystcode;
if ((!$emptystcode and $codestok) or $emptystcode)
{
echo '<META HTTP-EQUIV="Refresh" Content="0; URL=bulkstOLD.php">';
exit;
}
}
?>
<table width="100%" border="0" align="center">
<tr>
<td width="223" align="left"></td>
<td width="111" align="right"></td>
</tr>
</table>
</style>
<form method="post" id="editLists" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<table width="739" border="0" align="center" cellspacing="0" bgcolor="#171717">
<tr>
<td colspan="3"
style="color:#00CC00;
text-align: left;
padding: 0;
background: #2e2e2e url(images/nav_bar.jpg) repeat-x;
font-size: 0.9em;
color: white;
height:16px;"><script type="text/javascript" src="mainmenu.js"></script></td>
</tr>
<tr>
<td width="502"><h2 style="color:red;"> Atualizar Listas Favoritas de Pratos</h2></style></td>
<td width="231" colspan="2" align="right"><?php echo $configs[footer];?></td>
</tr>
<tr>
<td colspan="3" align="right" ><table width="100%" border="0" align="center">
<tr>
<td align="center">Restaurante:</td>
<td width="84" align="center" valign="bottom">Adicionar Código</td>
<td width="350" align="center">Lista a ser atualizada:</td>
<td width="150" align="left" valign="bottom"><span class="error"><?php echo $favErr;?></span></td>
</tr>
<tr>
<td width="135" align="center"><b><?php echo $stlistrest; ?></b></td>
<td align="center">
<?php
echo $stcodeline;
?>
</td>
<td align="center"><b><?php echo $dllist; ?></b></td>
<td align="right"><input type="submit" name="editSave" style="background-color: #009900; color: #FFFFFF;" value="Submeter" /></td>
</tr>
</table></td>
</tr>
</table>
</form>
<?php
$_SESSION["module"] = 'st';
?>
</div>
</body>
</html>
The only possible explanation for your problem is that you might have not written <?php session_start();?> in the very beginning, before any HTML tags(even doctype). Write it on top of every relevant php document.
Look if all your files are saved as UTF-8 without BOM, not just UTF-8.
This BOM dissables sessions.
And look if all your files are called as they are in the same subdomain.
www.domain.com/file1.php,
ww2.domain.com/file2.php,
domain.com/file3.php
... with diferent subdomains should not work.
I'm trying to update two fields in an individual record. However, when I click the "Update" button and the changes are submitted nothing is posted to the assigned_to=$_POST['assigned'], the completed='_POST['completedTime'] or the id='$_POST['ticket']. I think when I click "Update" it is looking at every field named "assigned"/"completedTime"/ and "ticket". How can I ensure only one record is selected?
<?php require_once('../con.php'); ?>
<?php
//query DB
$query = "SELECT * FROM table";
$results = mysql_query($query, $con) or die (mysql_error() . mysql_error($con));
$row = mysql_fetch_assoc($results);
$totalRows = mysql_num_rows($results);
//Update db
if (isset($_POST['update']))
{
$update = "UPDATE table SET assigned_to=$_POST['assigned'], completed='$_POST['completedTime'] WHERE id='$_POST['ticket']'";
mysql_query($update, $con);
if (!mysql_query($update, $con))
{
die('Error: ' . mysql_error($con));
}
}
?>
<!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></title>
<style type="text/css">
body,td,th {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
}
h1,h2,h3,h4,h5,h6 {
font-family: Arial, Helvetica, sans-serif;
}
h1 {
font-size: 18px;
}
h2 {
font-size: 14px;
}
</style>
</head>
<body>
<h1>Report</h1>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" accept-charset="iso-8859-1">
<hr size="1" noshade="noshade" />
<table border="1" cellpadding="3" cellspacing="0" class="small">
<tr>
<td><strong>TicketNum</strong></td>
<td><strong>User</strong></td>
<td><strong>Category</strong></td>
<td><strong>Description</strong></td>
<th>Comments</th>
<td><strong>Date</strong></td>
<td><strong>AssignedTo</strong></td>
<td><strong>CompletedDate</strong></td>
</tr>
<?php do { ?>
<tr bgcolor="<?php
$colorarray=array('#FFFFFF','#D9ECFF');
$colorarraysize=count($colorarray);
if ($BRB_rowcounter++%1 == 0){
if ($colorarrayindex<($colorarraysize-1)){
$colorarrayindex++;
}else{
$colorarrayindex=0;
}
}
echo "$colorarray[$colorarrayindex]"; ?>">
<td valign="top" nowrap="nowrap"><?php echo $row['id']; ?></td>
<td valign="top" nowrap="nowrap"><?php echo $row['username']; ?></td>
<td valign="top" nowrap="nowrap"><?php echo $row['category']; ?></td>
<td valign="top" nowrap="nowrap"><?php echo $row['title']; ?></td>
<td valign="top"><?php echo $row['issue_details']; ?></td>
<td valign="top" nowrap="nowrap"><?php echo $row['timestamp']; ?></td>
<td valign="top" nowrap="nowrap"><input type="text" name="assigned" value ='<?php echo $row['assigned_to']; ?>'></td>
<td valign="top" nowrap="nowrap"><input type="text" name="completedTime" value ='<?php echo $row['completed']; ?>'></td>
<td><input type="hidden" name="ticket" value ='<?php echo $row['id']; ?>'></td>
<td><input type="submit" name="update" value="Update"></td>
</tr>
<?php } while ($row = mysql_fetch_assoc($results)); ?>
</table>
</form>
</body>
</html>
<?php
mysql_free_result($update);
mysql_free_result($results);
?>
Try it:
<?php
require_once('../con.php');
//Update db
if (isset($_POST['update']))
{
$update = "UPDATE table SET assigned_to='{$_POST['assigned']}', completed='{$_POST['completedTime']}' WHERE id='{$_POST['ticket']}'";
$result = mysql_query($update, $con) or die ('Error' . mysql_error($con));
}
//query DB
$query = "SELECT * FROM table";
$results = mysql_query($query, $con) or die (mysql_error() . mysql_error($con));
$totalRows = mysql_num_rows($results);
?>
<!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></title>
<style type="text/css">
body,td,th {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
}
h1,h2,h3,h4,h5,h6 {
font-family: Arial, Helvetica, sans-serif;
}
h1 {
font-size: 18px;
}
h2 {
font-size: 14px;
}
</style>
</head>
<body>
<h1>Report</h1>
<hr size="1" noshade="noshade" />
<table border="1" cellpadding="3" cellspacing="0" class="small">
<tr>
<td><strong>TicketNum</strong></td>
<td><strong>User</strong></td>
<td><strong>Category</strong></td>
<td><strong>Description</strong></td>
<th>Comments</th>
<td><strong>Date</strong></td>
<td><strong>AssignedTo</strong></td>
<td><strong>CompletedDate</strong></td>
</tr>
<?php
while ($row = mysql_fetch_assoc($results)) {
$colorarray = array("#FFFFFF","#D9ECFF");
$colorarraysize = count($colorarray);
if ($BRB_rowcounter++%1 == 0){
if ($colorarrayindex<($colorarraysize-1)){
$colorarrayindex++;
}else{
$colorarrayindex=0;
}
}
$content .= <<< END
<form action="" method="POST" accept-charset="iso-8859-1">
<tr bgcolor="{$colorarray[$colorarrayindex]}">
<td valign="top" nowrap="nowrap">{$row['id']}</td>
<td valign="top" nowrap="nowrap">{$row['username']}</td>
<td valign="top" nowrap="nowrap">{$row['category']}</td>
<td valign="top" nowrap="nowrap">{$row['title']}</td>
<td valign="top">{$row['issue_details']}</td>
<td valign="top" nowrap="nowrap">{$row['timestamp']}</td>
<td valign="top" nowrap="nowrap"><input type="text" name="assigned" value="{$row['assigned_to']}"></td>
<td valign="top" nowrap="nowrap"><input type="text" name="completedTime" value="{$row['completed']}"></td>
<td><input type="submit" name="update" value="Update"></td>
</tr>
<input type="hidden" name="ticket" value="{$row['id']}">
</form>
END;
}
echo $content;
mysql_free_result($results);
?>
</table>
Your string interpolation syntax is incorrect. It should be:
$update = "UPDATE table SET assigned_to='{$_POST['assigned']}', completed='{$_POST['completedTime']}' WHERE id='{$_POST['ticket']}'";
You need to put { } around an array reference if the index contains quotes. You can also leave out the quotes:
$update = "UPDATE table SET assigned_to='$_POST[assigned]', completed='$_POST[completedTime] WHERE id='$_POST[ticket]'";
You also had some missing quotes and dollar signs, which I've fixed here.
See the PHP documentation for details of string syntax.
However, this is very poor style, since it's subject to SQL injection. You should preferable use an API that supports prepared queries (PDO, mysqli); if not, assign the $_POST parameters to variables and call mysql_real_escape_string() to sanitize them.
I just can't get my variables to carry over to the next page. The variable assignment works fine on the initial page (tested), but the value goes null when going to the next. Plz Help!
Page 1:
<?PHP session_start(); ?>
<HTML>
<HEAD>
<META NAME='robots' CONTENT='noindex,nofollow'>
<TITLE>Master Chief's Gamestore</TITLE>
<STYLE type="text/css">
BODY {
color: #ffffff;
background: url('~/halo-reach.jpg');
background-repeat: no-repeat;
background-position: top;
background-color: black;
}
</STYLE>
</HEAD>
<body vLink='#3366CC' link='#3366CC' alink='#3366CC'>
<br/><br/><br/><br/><br/>
<table width='100%' height='80%'>
<tr>
<td align='center' valign='middle'>
<table width="50%" cellspacing="0" cellpadding="25" border="0">
<form method="post">
<tr bgcolor="#666633">
<th id="header" align="left" colspan="3">
<DIV align="center">
<font face="Verdana, Arial, Helvetica" color="white" size="3">
Master Chief's Gamestore </font>
</DIV>
</th>
</tr>
<tr bgcolor="#A3A385">
<td width="100%" valign="middle" colspan="2">
<font face="Verdana, Arial, Helvetica" size="2">
<div align="center"><br/><br/>
Username: 
<input type="text" name="username"> 
Password: 
<input type="password" name="password"><br/>
<br/><input type="submit" name="act" value="Login"><br/>
<input type="submit" name="act" value="Register"><br/>
<input type="submit" name="act" value="Main"><br/> <br/><br/>
</div>
</font>
</td>
</tr>
<?PHP
if ($_POST['act'] == "Login") {
mysql_connect("~", "~", "~") or die("unable to connect to server");
mysql_select_db("~") or die("unable to select database");
$user = $_POST['username'];
$pass = $_POST['password'];
$query = "select * from users where user like '%" . $user . "%' and pass like '%" . $pass . "%';";
$result = mysql_query($query);
$rows = mysql_numrows($result);
if ($rows == 0 || strlen($user) == 0) {
echo "<br />Login Failure";
} else {
$_SESSION['user'] = mysql_result($result, 0, "user");
$_SESSION['id'] = mysql_result($result, 0, "P_Id");
header('Location: ~/success.php');
}
}
if ($_POST['act'] == "Register") {
header('Location: ~/register.php');
}
if ($_POST['act'] == "Main") {
header('Location: ~/index.php');
}
?>
<div align="center">
<tr bgcolor="#666633">
<td align="left">
Logged in as:
<?PHP
$user = $_SESSION['user'];
if (!$user) {
$user = 'Guest';
}
echo $user;
?>
</td>
<td align="right">
Password: 
<input type="password" name="srcpw">
<input type="submit" name="dspphp" value="Display PHP">
</td>
</tr>
</div>
</form>
</table>
</td>
</tr>
</table>
</body>
</html>
Page 2:
<?PHP session_start(); ?>
<HTML>
<HEAD>
<META NAME='robots' CONTENT='noindex,nofollow'>
<TITLE>Master Chief's Gamestore</TITLE>
<STYLE type="text/css">
BODY {
color: #ffffff;
background: url('~/halo-reach.jpg');
background-repeat: no-repeat;
background-position: top;
background-color: black;
}
</STYLE>
</HEAD>
<body vLink='#3366CC' link='#3366CC' alink='#3366CC'>
<br/><br/><br/><br/><br/>
<table width='100%' height='80%'>
<tr>
<td align='center' valign='middle'>
<table width="30%" cellspacing="0" cellpadding="25" border="0">
<form method="post">
<tr bgcolor="#666633">
<th id="header" align="left" colspan="3">
<DIV align="center">
<font face="Verdana, Arial, Helvetica" color="white" size="3">
Master Chief's Gamestore </font>
</DIV>
</th>
</tr>
<tr bgcolor="#A3A385">
<td width="100%" valign="middle" colspan="2">
<font face="Verdana, Arial, Helvetica" size="2">
<div align="center">
<br/><br/>Success<br/><br/>
<input type='submit' name='main' value='Main'>
<?PHP
if ($_POST['main'] == "Main") {
header('Location: http://~/index.php');
}
if ($_POST['act'] == "Display Code") {
if ($_POST['pw'] == "pass") {
highlight_file("success.php");
}
}
?>
</div>
</font>
</td>
</tr>
<div align="center">
<tr bgcolor="#666633">
<td align="left">
Logged in as:
<?PHP
$user = $_SESSION['user'];
if (!$user)
$user = 'Guest';
echo $user;
?>
</td>
<td align="right">
Password: 
<input type="password" name="pw">
<input type="submit" name="dspphp" value="Display PHP">
</td>
</tr>
</div>
</form>
</table>
</td>
</tr>
</table>
</body>
</html>
EDIT: I've tried this sample code and it does NOT work.
Page 1:
<?php
session_start();
if (isset($_GET['link'])) {
$_session['myvariable'] = 'Hello World';
header('Location: http://' . $_SERVER['SERVER_NAME'] . dirname($_SERVER['REQUEST_URI']) . '/page2.php');
exit;
}
?>
Click Here
Page 2:
<?php
session_start();
print 'Here is page two, and my session variable: ';
print $_session['myvariable'];
exit;
?>
But as I posted below, I have used sessions in other pages successfully on the same server. Soo frustrating....
Thanks for all the posts btw!
Make sure cookies are enabled so the second page actually re-creates the session of the first page instead of creating a new, empty one. Check out http://www.php.net/manual/en/session.idpassing.php for details.
EDIT
Another possible cause for sessions not working as expected, especially if it only affects certain pages, is that you have accidental whitespace or other output before your first 'session_start() error
It looks like you are just redirecting the user to the second page without posting anything. You would want to set hidden variables and actually submit your form to the second page. Re-directing will lose all the post variables.
If you want to send variables to the second page with a redirect, you can use session variables or a GET variable passed in with the URL to the second page.
Try using
$_SESSION['myvariable'] = 'Hello World';
in upper case