This question already has answers here:
Reference - What does this error mean in PHP?
(38 answers)
Closed 8 years ago.
I have to make one system where the system requires the process of adding new information. The process flow is the process of adding the new information carried by the employee where all the information, name and id of staff will insert in mysql database. When I tried the process of that, I found staff_id and staff_name was empty in database mysql.
This is my addStaff.php
<?php
include("authenticationStaff.php");
include ("dbase.php");
$query= "SELECT * FROM staff WHERE staff_name ='".$_SESSION['SESS_STAFF_NAME']."'";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
$id = $row["id"];
$staff_id=$row["staff_id"];
#mysql_free_result($result);
?>
<html>
<head>
<script>
function Validate()
{
if (document.addStaff.project_name.value == '')
{
alert('Please Insert Project Name!');
document.addStaff.project_name.focus();
return false;
}
if (document.addStaff.project_id.value == '')
{
alert('Please Insert Project ID !');
document.addStaff.project_id.focus();
return false;
}
if (document.addStaff.location.value == '')
{
alert('Please Insert Location!');
document.addStaff.location.focus();
return false;
}
if (document.addStaff.cost.value == '')
{
alert('Please Insert Cost!');
document.addStaff.cost.focus();
return false;
}
if (document.addStaff.pic.value == '')
{
alert('Please Insert Person In Charge!');
document.addStaff..pic.focus();
return false;
}
if (document.addStaff.detail.value == '')
{
alert('Please Insert Detail about the Project!');
document.addStaff.detail.focus();
return false;
}
}
</script>
</head>
<body>
<table width="869" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="645" height="50" align="left" valign="middle"><strong>Welcome , You log in as <?php echo $_SESSION['SESS_STAFF_NAME'];?> </strong></td>
<td width="224" align="right" valign="middle"><strong>Log Out</strong></td>
</tr>
</table>
<?php
$idURL = $_GET['id'];
$query ="SELECT *
FROM staff s
JOIN inter1 i
ON (s.staff_name=i.staff_name)";
$result = mysql_query($query, $conn) or die("Could not execute query");
$row = mysql_fetch_array($result, MYSQL_BOTH); // using numeric index or array index
$staff_id = $row['staff_id'];
$project_name = $row['project_name'];
$location = $row['location'];
$detail = $row['detail'];
$pic = $row['pic'];
$staff_name = $row['staff_name'];
$project_id = $row['project_id'];
#mysql_free_result ($result);
?>
<center>
<form action="addStaff_process.php?id=<?php echo $staff_id; ?>" method="post" enctype="multipart/form-data" name="add_process" id="add_process" onSubmit="return Validate()" >
<table border="1" width="70%" cellspacing="1" cellpadding="6" >
<tr align="center" bgcolor="">
<td align="left" style="padding:10px 10px 10px 10px;" >PROJECT NAME :</td>
<td align="left" style="padding:10px 10px 10px 10px;" ><textarea name="project_name" cols="50" rows="2" id="project_name"></textarea></td>
</tr>
<tr align="center" bgcolor="">
<td align="left" style="padding:10px 10px 10px 10px;" >PROJECT ID:</td>
<td align="left" style="padding:10px 10px 10px 10px;" ><textarea name="project_id" cols="50" rows="2" id="project_id"></textarea></td>
</tr>
<tr align="center" bgcolor="">
<td align="left" style="padding:10px 10px 10px 10px;" >LOCATION :</td>
<td align="left" style="padding:10px 10px 10px 10px;" ><textarea name="location" cols="50" rows="2" id="location"></textarea></td>
</tr>
<tr align="center" bgcolor="">
<td align="left" style="padding:10px 10px 10px 10px;" > COST :</td>
<td align="left" style="padding:10px 10px 10px 10px;" ><textarea name="cost" cols="50" rows="2" id="cost"></textarea></td>
</tr>
<tr align="center" bgcolor="" >
<td align="left" style="padding:10px 10px 10px 10px;" >PERSON IN CHARGE :</td>
<td align="left" style="padding:10px 10px 10px 10px;" ><textarea name="pic" cols="50" rows="3" id="pic"></textarea></td>
</tr>
<tr>
<td align="left" style="padding:10px 10px 10px 10px;">DETAIL ABOUT THE PROJECT:</td>
<td align="left" style="padding:10px 10px 10px 10px;" ><textarea name="detail" cols="50" rows="4" id="detail"></textarea></td>
</tr>
</table>
<p> </p>
<p>
<input class="form-submit" type="submit" name="submit" value="SUBMIT" onClick="return Validate()"/>
<input type = "reset" value = "RESET" />
</p>
</form>
</center>
</body>
</html>
And this is my addStaff_process.php
<?php
include("authenticationStaff.php");
include ("dbase.php");
extract( $_POST );
$idURL = $_GET['id'];
$project_name = $_POST['project_name'];
$location = $_POST['location'];
$cost= $_POST['cost'];
$pic= $_POST['pic'];
$detail = $_POST['detail'];
$project_id = $_POST['project_id'];
$staff_id = $_POST['staff_id'];
$staff_name = $_SESSION['SESS_STAFF_NAME'];
$result ="INSERT INTO inter1 (project_name,location,cost,pic,detail,project_id)
VALUES ('$project_name','$location','$cost','$pic','$detail','$project_id')";
$query = mysql_query ($result, $conn);
if(mysql_num_rows($query)){
echo "<script type='text/javascript'> window.location='pageStaff.php'</script>";
}
else{
$query1 = "UPDATE inter1 SET staff_name = '$staff_name',staff_id = '$staff_id' WHERE staff_name=$idURL";
$result1 = mysql_query ($query1, $conn);
if($result1){
echo "<script type='text/javascript'> window.location='pageStaff.php'</script>";
}
}
?>
Can someone see where I am going wrong?if you need any more info then please let me know. thanks.
You need to use session_start(); at the start of every page that accesses the session values.
Related
After importing a csv file, I'm trying to import the data with an insert statement, which is sending around 250 rows for one table.
The inserting, and code is working very well, but I had to print the insert query and the insert just worked till the row number 100.
PHP screen, which I import csv file data to the screen:
if(#$_FILES[file][type] == 'text/csv' || #$_FILES[file][type] == 'text/comma-separated-values' || #$_FILES[file][type] == 'application/vnd.ms-excel'){
if($_POST['FUNCAO'] == 'FORM_IMPORT')
{
error_reporting(E_ALL);
##### UPLOAD FILE
$uploaddir = 'gap_files/';
#$filename="gap_files/".$_FILES[file][name];
#$uploadfile = $filename;
$count = 0;
$id_linha = 0;
$itens_po = '';
$pos_to_import = '';
if (!#move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile))
{
print "<pre>";
print_r($_FILES);
print "$php_errormsg</pre>";
}
if(#$_FILES[file][name])
{
print '
<html>
<head>
<title>PO</title>
<link rel="stylesheet" type="text/css" href="../_includes/css/padrao.css" >
<script language="JavaScript" type="text/javascript" src="../_includes/js/padrao.js"></script>
<script language="JavaScript" type="text/javascript" src="../_includes/js/po.js"></script>
<script language="JavaScript" type="text/javascript" src="../_includes/js/label.js"></script>
</head>
<body>
<div id="div_report" style="background-color:#2B2B2B; position:fixed; top:0px; width:200%; height:200%; display:none; opacity:0.35; filter:alpha(opacity=35);"> </div>
<div id="div_link_color" style="display:none; position:fixed; margin-left: -300px; margin-top: -240px; left:50%; top:50%; width:600px; height:280px; background-color:#525252; text-align:center; z-index: 1000; text-align:center; border-radius: 0.4em; ">
<center>
<table cellpadding="3" cellspacing="0">
<tr>
<td colspan="3" class="REPORT_EDIT_TITLE" colspan="3" align="center" id="title_box_comment"></td>
</tr>
<tr>
<td colspan="3">
<iframe style="width:587px; height:230px; background-color:#EAF0FA; text-align:center; text-align:center; border-radius: 0.4em; overflow:auto; border:none;" id="frame_link_color" name="frame_link_color"></iframe>
</td>
</tr>
<tr>
<td colspan="3" align="center"><input type="button" name="comments" id="pre_production_comm" onclick="close_link_color();" value="Close" class="button" style="width:60px; height:30px;"></td>
</tr>
</table>
</center>
</div>
<div width="100%" id="FRAMESBOTTON">
<table cellpadding="1" cellspacing="0">
<tr>
<td class="botton-apple"><img src="../img/user.png" /> <b>Information</b> </td>
<td class="botton-apple" onclick="seleciona_div_po(3)"><img src="../img/help.png" /> <b>Help</b> </td>
<td class="botton-apple" onclick="seleciona_div_po(9)"><img src="../img/application.png" /> <b>Import Label</b> </td>
</tr>
</table>
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td class="titlestyle" colspan="6" align="center"><b>Labels to import</b></td>
</tr>
</table>
</div>
';
$po = '';
$line=1;
$po_show = '';
$itens_po = '';
$factory_ids = '';
$wrong_price = '';
$import_error = 0;
$invoice_port = '';
$invoice_number = '';
$number_of_invoices = 0;
$invoice_gross_weight = '';
$invoice_total_cartons = '';
$total_pairs_invoice = 0;
$total_amount_invoice = 0;
$total_amount_discount_invoice = 0;
$tr_check_po = '';
$filename="gap_files/".#$_FILES[file][name];
$handle = fopen("$filename", "r");
$actual_po = '';
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
{
foreach($data as $varname => $value)
{
if($value){
$data[$varname]=mysql_real_escape_string($value);
}
else{
$data[$varname]="NULL";
}
}
$check_if_inserted_invoice = mysql_query("select * from po_label where po_label.po = '".$data[3]."'");
if(mysql_num_rows($check_if_inserted_invoice) == 0){
if($line != 0){
$count++;
$itens_po .= '
<input type="hidden" name="iten_'.$count.'" value="'.$line.';'.$data[3].';'.$data[26].';'.$data[15].';'.$data[4].';'.$data[8].';'.$data[0].';'.$data[23].';'.$data[1].';"/>
<tr style="background-color:#ECEBEB;" onmouseover="ButtonRegSet(this,1)" onmouseout="ButtonRegSet(this)">
<td class="fontrecord" align="center"><input type="hidden" name="carton_number_'.$line.'" value="'.$line.'" readonly>'.$line.'</td>
<td class="fontrecord" align="center"><input type="hidden" name="po_'.$line.'" value="'.$data[3].'" readonly>'.$data[3].'</td>
<td class="fontrecord" align="center"><input type="hidden" name="carton_'.$line.'" value="'.$data[26].'" readonly>'.$data[26].'</td>
<td class="fontrecord" align="center"><input type="hidden" name="EANCode_'.$line.'" value="'.$data[15].'" readonly>'.$data[15].'</td>
<td class="fontrecord" align="center"><input type="hidden" name="size_'.$line.'" value="'.$data[4].'" readonly>'.$data[4].'</td>
<td class="fontrecord" align="center"><input type="hidden" name="pairs_'.$line.'" value="'.$data[8].'" readonly>'.$data[8].'</td>
<td class="fontrecord" align="center"><input type="hidden" name="customer_style_'.$line.'" value="'.$data[0].'" readonly>'.$data[0].'</td>
<td class="fontrecord" align="center"><input type="hidden" name="material_'.$line.'" value="'.$data[23].'" readonly>'.$data[23].'</td>
<td class="fontrecord" align="center"><input type="hidden" name="colors_'.$line.'" value="'.$data[1].'" readonly>'.$data[1].'</td>
</tr>';
}
$line++;
}
}
fclose($handle);
}
$number_of_invoices++;
print '
<form method="post" action="../_registers/po_import_label.php">
<input type="hidden" maxlength="30" name="FUNCAO" value="insert_import_po" readonly>
<input type="hidden" maxlength="30" name="itens_form" value="'.$line.'" readonly>
<center>
</br>
<table class="round_sub_information_title_close" width="90%">
<tr>
<td colspan="8" class="round_sub_information_title_close" style="background-color:#FFFFFF;">
<div id="id_itens_invoices_'.$number_of_invoices.'" style="display:block;">
<center>
<table cellpadding="0" cellspacing="1" style="min-width:99%; width:99.8%;">
<tr class="line_grid">
<td class="fontrecord" align="center">Carton Number</td>
<td class="fontrecord" align="center">PO</td>
<td class="fontrecord" align="center">Carton Code</td>
<td class="fontrecord" align="center">Case Code</td>
<td class="fontrecord" align="center">Size</td>
<td class="fontrecord" align="center">Quantity</td>
<td class="fontrecord" align="center">Style</td>
<td class="fontrecord" align="center">Material</td>
<td class="fontrecord" align="center">Color</td>
</tr>
'.$itens_po.'
</table>
</center>
</div>
</td>
</tr>
<tr>';
print '
<tr><td class="round_sub_information_title_close" style="background-color:#FFFFFF;"><input type="submit" value="Save"/></td></tr>';
print '</tr>
</table>
</center>
</form>';
}
}
File: "../_registers/po_import_label.php"
<?php
session_start();
if(!$_SESSION["uid"]){
die(header("location: ../login.php"));
}
include('../_library/config.php');
include('../_library/opendb.php');
include("../_library/functions.php");
$s = "insert into po_label (carton,
carton_number,
po,
size,
pairs,
colors,
material,
customer_style,
EANCode) values";
for($i=1;$i<$_POST['itens_form'];$i++)
{
$s .="('".$_POST['carton_'.$i]."',
'".$_POST['carton_number_'.$i]."',
'".$_POST['po_'.$i]."',
'".$_POST['size_'.$i]."',
'".$_POST['pairs_'.$i]."',
'".$_POST['colors_'.$i]."',
'".$_POST['material_'.$i]."',
'".$_POST['customer_style_'.$i]."',
'".$_POST['EANCode_'.$i]."'),";
}
$s = rtrim($s,",");
print $s;
return mysql_query($s) ? 'INSERTED.' : 'ERROR: '.mysql_error();
include '../library/closedb.php';
?>
After import to the screen, I call the insert function to send the data to the database, it is when I got the error.
insert into po_label (carton, carton_number, po, size, pairs, colors, material, customer_style, EANCode) values (...),('10355000000098','98','0355CC0001','7',' 6','CAMEL','SOFT NUBUCK','CC-CRYSTALL','191644000270'),('10355000000099','99','0355CC0001','7',' 6','CAMEL','SOFT NUBUCK','CC-CRYSTALL','191644000270'),('10355000000100','100','0355CC0001','7',' 6','','SOFT NUBUCK','CC-CRYSTALL','191644000270'),('','','','','','','','',''),('','','','','','','','',''),('','','','','','','','',''),('','','','','','','','',''),(...)
Adding an observation: Before I updated the files in my official system, I tried and test it in the Wamp server, where everything works well.
If i have only 100 rows, the insert works well
If i have more than 100 rows, you can check in the bottom that after the row 100 the insert becomes empty
1) Please confirm whether all values coming without spaces by following function
print_r()
2) Use the trim() function to every single data passed in insert query
INSERT INTO TBL_NAME VALUES(
'".trim($value[0])."',
'".trim($value[1]))";
May it will help
I think you should improve your below code with given
// Your code
for($i=1;$i<$_POST['itens_form'];$i++)
{
$s .="('".$_POST['carton_'.$i]."',
'".$_POST['carton_number_'.$i]."',
'".$_POST['po_'.$i]."',
'".$_POST['size_'.$i]."',
'".$_POST['pairs_'.$i]."',
'".$_POST['colors_'.$i]."',
'".$_POST['material_'.$i]."',
'".$_POST['customer_style_'.$i]."',
'".$_POST['EANCode_'.$i]."'),";
}
for($i=1;$i<$_POST['itens_form'];$i++)
{
// Remove POST for columns in which you have allowed null in data table
if($_POST['carton_'.$i] != '' && $_POST['carton_number_'.$i] != '' && $_POST['po_'.$i] != '' && $_POST['size_'.$i] != '' && $_POST['pairs_'.$i] != '' && $_POST['colors_'.$i] != '' && $_POST['material_'.$i] != '' && $_POST['customer_style_'.$i] != '' && $_POST['EANCode_'.$i] != '')
{
$s .="('".$_POST['carton_'.$i]."',
'".$_POST['carton_number_'.$i]."',
'".$_POST['po_'.$i]."',
'".$_POST['size_'.$i]."',
'".$_POST['pairs_'.$i]."',
'".$_POST['colors_'.$i]."',
'".$_POST['material_'.$i]."',
'".$_POST['customer_style_'.$i]."',
'".$_POST['EANCode_'.$i]."'),";
}
}
UPDATE
As per the given comment, you should increase the length of URI. Please check below Increase your URI limit in your apache server.
but the best way to insert bulk data is mysqldump please see below answer for more information regarding mysqldump using PHP Answer
The code provided is while-loop, which work, part of the loop is to update database and to return the updated info back to loop that work too. The problem I am having is if the return result is more than one it should not loop that result only echo it once.
I have tried other ways of doing this, but nothing giving me the result I need, I have the amount of knowledge I have on PHP. If someone could please help me, there help would be greatly appreciated.
<?php
//////////////////////// non-spouse kid start ///////////////////////
$nonspouseKidSql=("SELECT * FROM familyTree WHERE memberEmail='$login_mem' AND familyRelationship='son' AND familySide='other' OR memberEmail='$login_mem' AND familyRelationship='daughter' AND familySide='other' OR fam
ilyEmail='$login_mem' AND familyRelationship='father' AND familySide='other' OR familyEmail='$login_mem' AND familyRelationship='mother' AND familySide='other'");
$nonspouseKidQuery=mysql_query($nonspouseKidSql)or die ("error 1 Sorry we have a mysql error!");
$num_rowsNonspouseKid=mysql_num_rows($nonspouseKidQuery);
if ($num_rowsNonspouseKid < 1){echo '';}
else{
while($getnonspouseKidRow=mysql_fetch_array($nonspouseKidQuery)){
$getnonspouseKidEmail = $getnonspouseKidRow['familyEmail'];
$getNSPEmail = $getnonspouseKidRow['memberEmail'];
$nonspouseKid_relationship = $getnonspouseKidRow['familyRelationship'];
if($getNSPEmail == $login_mem){$nonspouseKidEmail = $getnonspouseKidEmail;}elseif($getnonspouseKidEmail == $login_mem){$nonspouseKidEmail = $getNSPEmail;}
$sql=("SELECT * FROM members WHERE email='$nonspouseKidEmail'");
$query=mysql_query($sql)or die ("error 1 Sorry we have a mysql error!");
$num_rows=mysql_num_rows($query);
while($row=mysql_fetch_array($query)){
$familyNonspouseKid_id = $row["id"];
$familyNonspouseKid_firstName = $row["firstName"];
$familyNonspouseKid_lastName = $row["lastName"];
$familyNonspouseKid_email= $row["email"];
$familyNonspouseKid_profile_pic = $row["profile_pic"];
$familyNonspouseKid_status = $row["status"];
$familyNonspouseKid_gender = $row["gender"];
if($nonspouseKid_relationship=="son"){$familyNonspouseKid_relationship ='son';}elseif($nonspouseKid_relationship=="daughter"){$familyNonspouseKid_relationship ='daughter';}
$member_familyPicNonspouseSon='/home/users/web/b2072/moo.poryniticom/profilePic/'.$familyNonspouseKid_id.'/'.$familyNonspouseKid_profile_pic.'';
if($familyNonspouseKid_profile_pic!==""){
$member_familyPicNonspouseSon='<div id="connection_nonSpouseKid" class="connection_nonSpouseKid"></div><div id="memFamilyPic_nonSpouseKid" class="memFamilyPic_nonSpouseKid"><a href="headstoneViewMember.php?userName='.
$familyNonspouseKid_email.'" id="'.$familyNonspouseKid_id.'" class="display_familyInfo"><img src="/profilePic/'.$familyNonspouseKid_id.'/'.$familyNonspouseKid_profile_pic.'" style="padding: 1px 1px 1px 1px;"
class="memFamilyPic_border" width="60" height="60" border="0" alt="" /></a><div id="familyDisplayDiv'.$familyNonspouseKid_id.'" class="familyDisplayDiv" style="display:none">
<table width="100%">
<tr>
<td align="left" valign="middle"><span style=" font-size: 16px; color:#999999 ;">Your '.$familyNonspouseKid_relationship.'</span></td>
</tr>
<tr>
<td align="left" valign="middle"><span style=" font-size: 16px; color:#999999 ;">'.$familyNonspouseKid_firstName.' '.$familyNonspouseKid_lastName.'</span></td>
</tr>
</table>
</div>
</div>';
}else{
$member_familyPicNonspouseSon='<div id="connection_non-spouseKid" class="connection_nonSpouseKid"></div><div id="memFamilyPic_nonSpouseKid" class="memFamilyPic_nonSpouseKid"><a href="headstoneViewMember.php?userName='.
$familyNonspouseKid_email.'" id="'.$familyNonspouseKid_id.'" class="display_familyInfo"><img src="/profilePic/default/default_profilePic.png"style="padding: 1px 1px 1px 1px;" class="memFamilyPic_border" width="60"
height="60" border="0" alt=""/></a>
<div id="familyDisplayDiv'.$familyNonspouseKid_id.'" class="familyDisplayDiv" style="display:none">
<table width="100%">
<tr>
<td align="left" valign="middle"><span style=" font-size: 16px; color:#999999 ;">Your '.$familyNonspouseKid_relationship.'</span></td>
</tr>
<tr>
<td align="left" valign="middle"><span style=" font-size: 16px; color:#999999 ;">'.$familyNonspouseKid_firstName.' '.$familyNonspouseKid_lastName.'</span></td>
</tr>
</table>
</div>
</div>';
}
$member_familyPicNonspouseDaughter='/home/users/web/b2072/moo.poryniticom/profilePic/'.$familyNonspouseKid_id.'/'.$familyNonspouseKid_profile_pic.'';
if($familyNonspouseKid_profile_pic!==""){
$member_familyPicNonspouseDaughter='<div id="connection_nonSpouseKid" class="connection_nonSpouseKid"></div><div id="memFamilyPic_nonSpouseKid" class="memFamilyPic_nonSpouseKid"><a
href="headstoneViewMember.php?userName='.
$familyNonspouseKid_email.'" id="'.$familyNonspouseKid_id.'" class="display_familyInfo"><img src="/profilePic/'.$familyNonspouseKid_id.'/'.$familyNonspouseKid_profile_pic.'" style="padding: 1px 1px 1px 1px;"
class="memFamilyPic_border" width="60" height="60" border="0" alt="" /></a>
<div id="familyDisplayDiv'.$familyNonspouseKid_id.'" class="familyDisplayDiv" style="display:none">
<table width="100%">
<tr>
<td align="left" valign="middle"><span style=" font-size: 16px; color:#999999 ;">Your '.$familyNonspouseKid_relationship.'</span></td>
</tr>
<tr>
<td align="left" valign="middle"><span style=" font-size: 16px; color:#999999 ;">'.$familyNonspouseKid_firstName.' '.$familyNonspouseKid_lastName.'</span></td>
</tr>
</table>
</div>
</div>';
}else{
$member_familyPicNonspouseDaughter='<div id="connection_nonSpouseKid" class="connection_nonSpouseKid"></div><div id="memFamilyPic_nonSpouseKid" class="memFamilyPic_nonSpouseKid"><a
href="headstoneViewMember.php?userName='.
$familyNonspouseKid_email.'" id="'.$familyNonspouseKid_id.'" class="display_familyInfo"><img src="/profilePic/default/default_profilePic.png"style="padding: 1px 1px 1px 1px;" class="memFamilyPic_border" width="60"
height="60" border="0" alt=""/></a>
<div id="familyDisplayDiv'.$familyNonspouseKid_id.'" class="familyDisplayDiv" style="display:none">
<table width="100%">
<tr>
<td align="left" valign="middle"><span style=" font-size: 16px; color:#999999 ;">Your '.$familyNonspouseKid_relationship.'</span></td>
</tr>
<tr>
<td align="left" valign="middle"><span style=" font-size: 16px; color:#999999 ;">'.$familyNonspouseKid_firstName.' '.$familyNonspouseKid_lastName.'</span></td>
</tr>
</table>
</div>
</div>';
}
if($familyNonspouseKid_relationship =='son'){echo $member_familyPicNonspouseSon;}else{echo $member_familyPicNonspouseDaughter;}
}
?>
<?php
//////// non-spouse kid end //////////////////////////////
?>
<?php
//////////////// child parent not spouse start ////////
?>
<div id="connection_childParent" class="connection_childParent"></div>
<div id="memFamilyPic_childParent" class="memFamilyPic_childParent">
<?php
$getGender = $mem["gender"];
if($getGender=='male'){$parentGender='Mother';}else{$parentGender='Father';}
$parentNameSql=mysql_query("SELECT * FROM familyTree WHERE memberEmail='$nonspouseKidEmail' AND familyRelationship='mother' OR memberEmail='$nonspouseKidEmail' AND familyRelationship='father'")or die ("Sorry can't
get parent name!");
$parentNameRow=mysql_fetch_array($parentNameSql);
$parentName = $parentNameRow['familySide'];
$childParentSql=mysql_query("SELECT * FROM familyTree WHERE memberEmail='$login_mem' AND familyRelationship='childmother' AND child_Id='$familyNonspouseKid_id' OR memberEmail='$login_mem' AND
familyRelationship='childfather' AND child_Id='$familyNonspouseKid_id'")or die ("Sorry can't get child parent!");
$childParentRow=mysql_fetch_array($childParentSql);
if($childParentRow < 1){echo '<p id="'.$familyNonspouseKid_id.'" class="mysql_returnNonspouseKid" align="center" style="color: #999; font-size:13px;">Child '.$parentGender.'</p>';
}else if($childParentRow > 2){
$childParentEmail = $childParentRow['familyEmail'];
$familyChildParent_relationship = $childParentRow["familyRelationship"];
$childParent=("SELECT * FROM members WHERE email='$childParentEmail'");
$query=mysql_query($childParent)or die ("error 1 Sorry we have a mysql error!");
$num_rows=mysql_num_rows($query);
if($childParentRow > 2){
while($row=mysql_fetch_array($query)){
$familyChildParent_id = $row["id"];
$familyChildParent_firstName = $row["firstName"];
$familyChildParent_lastName=$row["lastName"];
$familyChildParent_email=$row["email"];
$familyChildParent_profile_pic = $row["profile_pic"];
$familyChildParent_status=$row["status"];
$member_familyPicChildParent='/home/users/web/b2072/moo.poryniticom/profilePic/'.$familyChildParent_id.'/'.$familyChildParent_profile_pic.'';
if($familyChildParent_profile_pic!==""){
$member_familyPicChildParent='<a href="headstoneViewMember.php?userName='.$familyChildParent_email.'" id="'.$familyChildParent_id.'" class="display_familyInfo"><img src="/profilePic/'.$familyChildParent_id.'/'.
$familyChildParent_profile_pic.'" style="padding: 1px 1px 1px 1px;" id="memFamilyPic_border'.$familyChildParent_id.'" class="memFamilyPic_border" width="60" height="60" border="0" alt="" /></a>';
}else{
$member_familyPicChildParent='<a href="headstoneViewMember.php?userName='.$familyChildParent_email.'" id="'.$familyChildParent_id.'" class="display_familyInfo"><img
src="/profilePic/default/default_profilePic.png"style="padding: 1px 1px 1px 1px;" id="memFamilyPic_border'.$familyChildParent_id.'" class="memFamilyPic_border" width="60" height="60" border="0" alt=""/></a>';
}
}
if($familyChildParent_relationship =='childmother' or $familyChildParent_relationship =='childfather'){echo $member_familyPicChildParent;}
}}else{}
?>
<div id="familyDisplayDiv<?php echo $familyChildParent_id; ?>" class="familyDisplayDiv" style="display:none">
<table width="100%">
<tr>
<td align="left" valign="middle"><span style=" font-size: 16px; color:#999999 ;">Your <?php echo $familyChildParent_relationship; ?></span></td>
</tr>
<tr>
<td align="left" valign="middle"><span style=" font-size: 16px; color:#999999 ;"><?php echo $familyChildParent_firstName; ?> <?php echo $familyChildParent_lastName; ?></span></td>
</tr>
</table>
</div>
</div>
<?php
}}
///////////////// child parent not spouse end //////////////
?>
DB MAP:
Carriers "table1": carriername, carrierid, ect... Post data
carrierinfo "table2": carriername, id, contact, ect... carrier list
I am using mysql_query from table2 for my carriername drop down. Using this I am able to post a carrier name to table1. I am trying to use the same drop down to post the related id from the selcected carriername. So in short I need to have one drop down that displays only the Carrier names but querys both carriername & id from table2. When the form is posted I need to post to the carriername & carrierid to table1. Below is the drop down I am using. Please let me know how I can connect the dots and add what is needed. If its possible.
<?php
if (isset($_POST["submit"]) && $_POST["submit"] == "Submit")
{
for ($count = 1; $count <= 9; $count++)
{
$fields[$count] = "";
if (isset($_POST["field" . $count . ""]))
{
$fields[$count] = trim($_POST["field" . $count . ""]);
//echo $fields[$count] . "<br />";
}
}
$con = mysql_connect("", "", "");
mysql_select_db("", $con);
$carrierid = mysql_real_escape_string($_POST['carrierid']);
$fromzip = mysql_real_escape_string($_POST['fromzip']);
$tozip = mysql_real_escape_string($_POST['tozip']);
$typeofequipment = mysql_real_escape_string($_POST['typeofequipment']);
$weight = mysql_real_escape_string($_POST['weight']);
$length = mysql_real_escape_string($_POST['length']);
$paymentamount = mysql_real_escape_string($_POST['paymentamount']);
$contactperson = mysql_real_escape_string($_POST['contactperson']);
$loadtype = mysql_real_escape_string($_POST['loadtype']);
$date = mysql_real_escape_string($_POST['date']);
$insert = "INSERT INTO Carriers (`carriername` ,`carrierid`, `fromzip` ,`tozip` ,`typeofequipment` ,`weight` ,`length` ,`paymentamount` ,`contactperson` ,`loadtype` ,`date`)
SELECT carriername ,'$carrierid' ,'$fromzip' ,'$tozip' ,'$typeofequipment' ,'$weight' ,'$length' ,'$paymentamount' ,'$contactperson' ,'$loadtype', NOW()) FROM carrierinfo WHERE id = '$carrierid'";
mysql_query($insert) or die(mysql_error());
$select = "SELECT `carriername` ,`fromzip` ,`tozip` ,`typeofequipment` ,`weight` ,`length` ,`paymentamount` ,`contactperson` ,`loadtype` FROM `Carriers` ORDER BY `date` DESC;";
$result = mysql_query($select) or die(mysql_error());
}
?>
<style ="text-align: center; margin-left: auto; margin-right: auto;"></style>
</head>
<body>
<input type="button" onclick="window.location.href='search.php';" value="Search Board" /><div
style="border: 2px solid rgb(0, 0, 0); margin: 16px 20px 20px; width: 400px; background-color: rgb(236, 233, 216); text-align: center; float: left;">
<form action="" method="post";">
<div
style="margin: 8px auto auto; width: 300px; font-family: arial; text-align: left;"><br>
<table style="font-weight: normal; width: 100%; font-size: 12px;"
border="1" bordercolor="#929087" cellpadding="6" cellspacing="0">
<table
style="font-weight: normal; width: 100%; text-align: right; font-size: 12px;"
border="1" bordercolor="#929087" cellpadding="6" cellspacing="0">
<tbody>
<tr>
<td style="width: 10%;">Carrier:</td><td>
<?php
$con = mysql_connect("", "", "");
mysql_select_db("", $con);
$query=("SELECT * FROM carrierinfo");
$result=mysql_query($query) or die ("Unable to Make the Query:" . mysql_error() );
echo "<select name='carrierid'>";
while($row=mysql_fetch_array($result)){
echo "<OPTION VALUE='".$row['id']."'>".$row['carriername']."</OPTION>";
}
echo "</select>";
?>
</td>
</tr>
<tr>
<td style="width: 10%;">Load Type:</td><td>
<select name="loadtype">
<option></option>
<option value="TL">Truck Load</option>
<option value="Partial">Partial</option>
</select>
</td>
</tr>
<tr>
<td style="width: 35%;">Pick Zip:</td><td> <input id="fromzip" name="fromzip" maxlength="50"
style="width: 100%;" type="text">
</tr>
<tr>
<td style="width: 35%;">Drop Zip:</td><td> <input id="tozip" name="tozip" maxlength="50"
style="width: 100%;" type="text">
</tr>
<tr>
<td style="width: 35%;">Weight:</td><td> <input id="weight" name="weight" maxlength="50"
style="width: 100%;" type="text">
</tr>
<tr>
<td style="width: 35%;">Length:</td><td> <input id="length" name="length" maxlength="50"
style="width: 100%;" type="text">
</tr>
<tr>
<td style="width: 10%;">Equip:</td><td>
<select name="typeofequipment">
<option></option>
<option value="AUTO">Auto Carrier</option>
<option value="DD">Double Drop</option>
<option value="F">Flatbed</option>
<option value="LB">Lowboy</option>
<option value="Rail">Rail</option>
<option value="Ref">Reefer</option>
<option value="RGN">Removable Goose Neck</option>
<option value="SD">Step Deck</option>
<option value="TANK">Tanker (Food, liquid, etc.)</option>
<option value="V">Van</option>
</select>
</td>
</tr>
<tr>
<td style="width: 35%;">Contact:</td><td> <input id="contactperson" name="contactperson" maxlength="50"
style="width: 100%;" type="text">
</tr>
<tr>
<td style="width: 35%;">Rate:</td><td> <input id="paymentamount" name="paymentamount" maxlength="50"
style="width: 100%;" type="text">
</tr>
</tbody>
</table>
<p style="text-align: center;"><input name="submit" value="Submit"
class="submit" type="submit"><input type="button" onclick="window.location.href='newcarrier.php';" value="Add Carrier" /></p>
</div>
</form>
</div>
<p style="margin-bottom: -20px;"> </p>
</body>
Use a join:
SELECT t1.carrierid, t2.carriername, t2.id
FROM table1 t1 JOIN table2 t2 USING (carriername)
Joining tables should be one of the first things you learn when studying SQL.
UPDATE:
Never mind the above, your original query to populate the dropdown was correct. When you populate the select, you should do:
echo "<select name='carrierid'>";
while($row=mysql_fetch_array($result)){
echo "<OPTION VALUE='".$row['id']."'>".$row['carriername']."</OPTION>";
}
echo "</select>";
When posting the data, get rid of this line:
$carriername = mysql_real_escape_string($_POST['carriername']);
and change the insert query to:
$insert = "INSERT INTO Loads (`carriername` ,`carrierid`, `fromzip` ,`tozip` ,`typeofequipment` ,`weight` ,`length` ,`paymentamount` ,`contactperson` ,`loadtype` ,`date`)
SELECT carriername ,'$carrierid' ,'$fromzip' ,'$tozip' ,'$typeofequipment' ,'$weight' ,'$length' ,'$paymentamount' ,'$contactperson' ,'$loadtype', NOW())
FROM Carriers
WHERE id = '$carrierid'";
The change to the form makes it display the carrier name, but return the ID in the post data. Then the new INSERT query uses that ID to get the carrier name from table 2 and combine that with all the other post data when inserting into table 1.
I am creating an application like that of Facebook photo albums having comments.
I have a webpage, which shows the pics inside an album, when a pic is clicked, a lightbox opens up, and the caption and comments on the pic will be shown. Here's the pictures.php code
<?php
session_start();
ob_start;
include('connection.php');
?>
<html>
<head>
<title>Photos</title>
<style type="text/css">
.wraptocenter
{
width: 200px;
height: 150px;
overflow: hidden;
}
.wraptocenter img
{
vertical-align: top;
}
.black_overlay
{
display: none;
position: fixed;
top: 0%;
left: 0%;
width: 100.7%;
height: 100%;
background-color: black;
z-index: 1001;
-moz-opacity: 0.8;
opacity: .80;
filter: alpha(opacity=80);
}
.white_imagebox
{
display: none;
position: fixed;
top: 5%;
left: 6%;
width: 900px;
height: 500px;
padding: 0px;
border: 0px solid #a6c25c;
background-color: white;
z-index: 1002;
overflow: visible;
}
</style>
<script type="text/javascript" src="AJAX/AjaxInsertPicComment.js"></script>
<script>
function showpic(image_path,image_id,album_id,pic_caption)
{
document.getElementById('AlbumDiv').style.display = "block";
document.getElementById('fade').style.display = "block";
document.getElementById('image').src = image_path; // this line added
img = new Image();
img.src = image_path;
document.getElementById('t_albumid').value = album_id;
document.getElementById('t_imageid').value = image_id;
document.getElementById('t_albid').value = album_id;
document.getElementById('t_picid').value = image_id;
document.getElementById('albumid').value = album_id;
document.getElementById('imageid').value = image_id;
document.getElementById('t_imagepath').value = image_path;
document.getElementById('caption_holder').value = pic_caption;
if(img.width > 500 && img.height > 450)
{
if(img.width > img.height)
{
document.getElementById('image').style.width = "500px";
document.getElementById('image').style.height = 'auto';
delete img;
return false;
}
else
{
document.getElementById('image').style.height = "450px";
document.getElementById('image').style.width = 'auto';
delete img;
return false;
}
}
else if(img.height > 450 && img.width < 500)
{
document.getElementById('image').style.height = "450px";
delete img;
return false;
}
else if(img.height < 450 && img.width > 500)
{
if(img.width > img.height)
{
document.getElementById('image').style.width = "500px";
document.getElementById('image').style.height = 'auto';
delete img;
return false;
}
else
{
document.getElementById('image').style.height = "450px";
document.getElementById('image').style.width = 'auto';
delete img;
return false;
}
}
else if(img.width < 500 && img.height < 450)
{
if(img.width > img.height)
{
document.getElementById('image').style.width = "500px";
document.getElementById('image').style.height = 'auto';
delete img;
return false;
}
else
{
document.getElementById('image').style.height = "450px";
document.getElementById('image').style.width = 'auto';
delete img;
return false;
}
}
delete img;
alert("humm");
return false;
}
</script>
</head>
<body>
<div id="photo_holder">
<table width="1000px" cellpadding="0" cellspacing="0" border="0" align="center">
<tr>
<td width="50px" align="center"/>
<td align="center" colspan="2" background="Images/header_menu.png" style="padding-right:2px;">
<?php include('header.php');?>
</td>
<td width="50px" align="center"/>
</tr>
<tr>
<td width="50px" align="center" ></td>
<td width="600px" align="center">
<?php
$album_id=$_REQUEST['txt_albumid'];
echo $album_id;
/* how many columns */
$column_number='3';
/* html table start */
?>
<div id="photo_container" align="center" width="600px">
<table border="1px" cellspacing="5" cellpadding="0" align="left">
<?php
$sql="SELECT * FROM candidate_pics WHERE album_id='$album_id'";
$result=mysql_query($sql,$con);
// $row=mysql_fetch_array($result);
$recordcounter=1; /* counts the records while they are in loop */
while($row=mysql_fetch_array($result))
{
/* decide if there will be new Table row (<TR>) or not ... left of division by column number is the key */
if($recordcounter%$column_number==1)
{
echo "<tr>";
}
?>
<td align="center" width="200px">
<div class="wraptocenter" align="center">
<?php $_SESSION['pic_id']=$row[pic_id];?>
<a href="javascript:void(0)"
onClick="showpic('<?php echo $row[pic_path];?>','<?php echo $row[pic_id];?>',
'<?php echo $row[album_id];?>','<?php echo $row[pic_caption];?>')";>
<img src="<?php echo $row[pic_path];?>"/></a>
</div>
</td>
<?php
/* decide if there will be end of table row */
if($recordcounter%$column_number==0)
{
echo "</tr>";
}
$recordcounter++; /* increment the counter */
}
if(($recordcounter%$column_number)!=1){ echo "</tr>"; }
?>
</table>
</div>
</td>
<td width="300px" align="center" >
<div id="photo_uploader">
<form method="post" action="photo_upload.php" enctype="multipart/form-data">
<table width="300px" align="center" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center" width="100px">Upload Pic::</td>
<td align="center" width="200px">
<input type="file" name="file" id="file" style="width: 200px;"/>
</td>
</tr>
<tr>
<td align="center" width="100px"/>
<td align="center" width="200px">
<input type="submit" name="submit_pic" id="submit_pic" value="Click to upload" style="width: 200px;"/>
<input name="txt_albumid" type="hidden" value="<?php echo $album_id;?>"/>
</td>
</tr>
</table>
</form>
</div>
</td>
<td width="50px" align="center" ></td>
</tr>
</table>
</div>
<div id="AlbumDiv" class="white_imagebox">
<table align="center" cellpadding="0" cellspacing="0" border="0" width="900px">
<tr>
<td colspan="2" height="25px">
<div id="close">
<a href="javascript:void(0)"
onclick="document.getElementById('AlbumDiv').style.display =
'none';document.getElementById('fade').style.display='none'">
<img src="images/close-icon.png" style="border-style: none; border-color: inherit;
border-width: 0px; height: 17px; width: 16px;" align="right" /></a>
</div>
</td>
</tr>
<tr>
<td width="600px" align="center">
<table width="600px" cellpadding="0" cellspacing="0" border="0">
<tr>
<td width="50px" align="center"/>
<td align="center" width="500px">
<div id="image_holder" style="width: 500px; height: 450px;
background-color:#666666;">
<input type="image" id="image" name="image"/>
</div>
</td>
<td width="50px" align="center"/>
</tr>
<tr>
<td/>
<td>
<input type="text" id="caption_holder" name="caption_holder"
style="width:500px;"/>
</td>
<td/>
</tr>
</table>
</td>
<td width="300px" align="center">
<table width="300px" cellpadding="0" cellspacing="0" border="0" align="top">
<tr>
<td align="center" width="100px">
<form method="post" action="photo_delete.php">
<input type="submit" name="delete" id="delete" value="Delete"
class="button" style="width: 100px;"/>
<input type="hidden" name="t_imageid" id="t_imageid"/>
<input type="hidden" name="t_imagepath" id="t_imagepath"/>
<input type="hidden" name="t_albumid" id="t_albumid"/>
</form>
</td>
<td align="center" width="100px">
<form>
<input type="button" name="edit" id="edit" value="Edit" class="button"
style="width: 100px;"
onclick="document.getElementById('pic_caption').style.visibility = 'visible';
document.getElementById('enter_caption').style.visibility = 'visible';"/>
</form>
</td>
<td align="center" width="100px">
<form method="post" action="">
<input type="submit" name="cover_pic" id="cover_pic" value="Set CoverPic" class="button"
style="width: 100px;"/>
<input type="hidden" name="t_albumname" id="t_albumname"/>
<input type="hidden" name="t_imagename" id="t_imagename"/>
</form>
</td>
</tr>
<tr>
<td height="100px" colspan="3">
<form method="post" action="photo_edit.php">
<input type="text" name="pic_caption" id="pic_caption" style="visibility:hidden;"/>
<input type="submit" name="enter_caption" id="enter_caption" style="visibility:hidden;"/>
<input type="hidden" name="t_picid" id="t_picid"/>
<input type="hidden" name="t_albid" id="t_albid"/>
</form>
</td>
</tr>
<tr>
<td height="300px" colspan="3">
<div id="" style="overflow-y:scroll; height:300px;">
<table width="282px" cellpadding="0" cellspacing="0" border="0"
align="center">
<tr>
<td>
<?php
echo $_SESSION[pic_id];?>
<div id="message_report">
</div>
</td>
</tr>
<tr>
<td>
<form method="post" action=
"javascript:get(document.getElementById('pic_comment_form'));" name=
"pic_comment_form" id="pic_comment_form">
<table width="280px" cellpadding="0" cellspacing="0" border="0"
align="center" >
<tr>
<td width="100px">
<input type="text" name="comment" id="comment" style="width:100px"/>
</td>
<td width="80px"/>
<td width="100px">
<input type="submit" name="comment_enter" id="comment_enter" style="width:100px"/>
</td>
<tr>
<td>
<input type="hidden" name="albumid" id="albumid"/></td>
<td>
<input type="hidden" name="imageid" id="imageid"/></td>
<td>
<input type="hidden" name="user" id="user"
value="<?php echo $_SESSION[logged_user];?>"/></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
<div id="fade" class="black_overlay">
</div>
</body>
</html>
The code
<a href="javascript:void(0)"
onClick="showpic('<?php echo $row[pic_path];?>','<?php echo $row[pic_id];?>',
'<?php echo $row[album_id];?>','<?php echo $row[pic_caption];?>')";>
<img src="<?php echo $row[pic_path];?>"/></a>
pass the album_id, pic_id to the javascript functions which is then passed to the objects in the lightbox such as id="t_albumid", id="t_imageid"
I need to write a SQL query in the lightbox like this:
SELECT * FROM candidate_pics_comment WHERE pic_id='$VariableHavingPicId
but for this I must use the variable in the JavaScript image_id and pass it again to the lightbox div in the JavaScript. The code:
document.getElementById('t_imageid').value = image_id;
assigns the object, the value as image_id, but how can we assign the image_id to a php variable so that I can use it in the sql query?
I mean in the JavaScript can it be something like this:
function showpic(image_path,image_id,album_id,pic_caption)
{
<?php
$var = //assign the value image_id;?>
// rest of the code here;
}
I know it's not possible, but is there some trick to achieve this?
Moreover as I was experimenting, I did something like this:
function showpic(image_path,image_id,album_id,pic_caption)
{
<?php
$_SESSION[pic_id]="hmmm";?>
//rest codes;
}
Then when I used echo $_SESSION[pic_id] in php script, it displayed hmmm
So I was thinking can it be done something like this?
function showpic(image_path,image_id,album_id,pic_caption)
{
<?php
$_SESSION[pic_id]=//assign image_id to session variable;?>
//rest codes;
}
Besides I used AJAX application, but I saw that AJAX returns the response to the objects innerHTML, how ca it be stored in a php variable?
Update
My question is that, I am passing values from this
<a href="javascript:void(0)"
onClick="showpic('<?php echo $row[pic_path];?>','<?php echo $row[pic_id];?>',
'<?php echo $row[album_id];?>','<?php echo $row[pic_caption];?>')";>
<img src="<?php echo $row[pic_path];?>"/></a>
to the JavaScript fiunction
function showpic(image_path,image_id,album_id,pic_caption)
Now how can I assign image_id to a PHP variable which I can use in the div AlbumDiv which is used for the lightbox. If that not possible how can a session variable be assign the value of image_id, is it possible inside the JavaScript function?
ajax is the only option to get something from JavaScript to PHP.
If you are using jQuery then take a look at the docs here
Otherwise I recommend you use a Library like jQuery or jQuery itself
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