I wanted to use php to get the value of a combo box, and I am using post method...
can anyone tell me how.
<html>
<head>
<title>Virtual Library</title>
<link href="css/login.css" rel="stylesheet"/>
<link href="css/style.css" rel="stylesheet"/>
<script type="text/javascript" src="scripts/ajax_search.js"></script>
</head>
<body>
<div id="wrapper">
<div id="header" align="center">
<ul align="center">
<li><span>Home</span></li>
<li><span>Top 100 Downloads</span></li>
<li><span>Upload</span></li>
<?php if(isset($_SESSION['login_user']))
{
$uname = $_SESSION['login_user'];
echo "<li><a href='profile.php'><span>$uname</span></a></li>";
echo "<li><a href='logout.php'><span>LogOut</span></a></li>";
}
else{
echo "<li><a href='login.php'><span>Member Login</span></a></li>";
echo "<li><a href='register.php'><span>Register</span></a></li>";
}
?>
<li><span>RSS <img src="images/rss.gif" id="rss"></span></li>
</ul>
</div>
<?php if(isset($_SESSION['login_user']))
{
echo "<div class='frmdiv'>
<form action='upload_file.php' method='post' enctype='multipart/form-data'>
<table width='38%' border='0' align='center' cellpadding='0' cellspacing='0'>
<tr>
<td colspan='2'><div align='center'><font size='2' face='verdana'>Upload File</font></div></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan='2'><hr></td>
</tr>
<tr>
<td height='26'><font size='2' face='verdana'>FileName</font></td>
<td><font size='2' face='verdana'>
<input type='file' name='file' ></font>
</td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td></td>
<td><select name='media_type' >
<option value='' selected>Select a media type...</option>
<option value='pdf'>PDF</option>
<option value='chm'>CHM</option>
<option value='epub'>EPUB</option>
<option value='html'>HTML</option>
<option value='djvu'>DJVU</option>
</select></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td><font size='2' face='verdana'>
<input type='submit' name='Submit' value='Upload'></font>
</td>
</tr>
<tr>
<td colspan='2'><hr></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</table>
</form>
<div align='center'>";
}
else{
echo "<script type='text/javascript'>";
echo "alert('You Must Be Logged In To Upload');";
echo "location='login.php'";
echo "</script";
}
?>
</div>
</body>
</html>
this is the combo box.
Try:
if(isset($_POST['media_type']){
$value = $_POST['media_type'];
}
Update: Since that doesn't work for you, check to see if you are getting any post variables:
foreach ($_POST as $var => $value) {
echo "$var = $value<br>n";
}
Related
Is this the right way to update a specific column for one row in mysqli_array_fetch? It doesn't work for me.
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>الرد على التذكرة</title>
<style>
.table, tr, td {border: 1px solid black; text-align:center}
.contents { position:static}
p1 {font-size:15px; font-weight:bolder}
.inputresponse {resize:none}
</style>
</head>
<body class="body">
<div class="contents" align="right">
<?php
include 'config.php';
$sql = "SELECT * FROM contact ORDER BY id";
$con->set_charset('utf8');
$users = mysqli_query($con,$sql);
?>
<table class="table">
<?php
while($row = mysqli_fetch_array($users)) {
?>
<form id="<?php echo $row[id] ?>" method="post" name="respone" action="addresponse.php">
<tr>
<td> <p1> الإسم </p1> </td>
<tr>
<td> <?php echo $row[name] ?> </td>
</tr>
<tr>
<td> <p1> رقم التذكرة</p1> </td>
</tr>
<tr>
<td> <?php echo $row[ticketnumber] ?> </td>
</tr>
<tr>
<td> <p1> الإيميل</p1> </td>
</tr>
<tr>
<td> <?php echo $row[email] ?> </td>
</tr>
<tr>
<td> <p1> الموضوع </p1> </td>
</tr>
<tr>
<td> <?php echo $row[subject] ?> </td>
</tr>
<tr>
<td> <p1> الرد </p1> </td>
</tr>
<tr>
<td> <textarea name="response" rows="5" dir="rtl" class="inputresponse"> </textarea> </td>
</tr>
<tr>
<td> <input type="submit" value="إرسال" name="send"> </td>
</tr>
<tr>
<td>
<?php
if(isset($_POST['send'])){
$repsonse = $_POST['response'];
$result = ("UPDATE contact SET response ='$response' WHERE id= $row[id]");
$rst = mysqli_query($con,$result);
if($rst){
echo "تم الإرسال";
} else {
echo " لم يتم الإرسال";
}
}
}
?>
</form>
</table>
</div>
</body>
</html>
after editing, I think I did it in wrong again
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>الرد على التذكرة</title>
<style>
.table, tr, td {border: 1px solid black; text-align:center}
.contents { position:static}
p1 {font-size:15px; font-weight:bolder}
.inputresponse {resize:none}
.inputid {text-align:center; font-size:10px}
</style>
</head>
<body class="body">
<div class="contents" align="right">
<?php
include 'config.php';
$sql = "SELECT * FROM contact ORDER BY id";
$con->set_charset('utf8');
$users = mysqli_query($con,$sql);
?>
<table class="table">
<?php
while($row = mysqli_fetch_array($users)) {
?>
<form id="<?php echo $row['id'] ?>" method="post" name="respone" action="addresponse.php">
<tr>
<td> <input value="<?php echo $row['id'] ?>" name="id" class="inputid" readonly> </td>
<tr>
<tr>
<td> <p1> الإسم </p1> </td>
<tr>
<td> <?php echo $row['name'] ?> </td>
</tr>
<tr>
<td> <p1> رقم التذكرة</p1> </td>
</tr>
<tr>
<td> <?php echo $row['ticketnumber'] ?> </td>
</tr>
<tr>
<td> <p1> الإيميل</p1> </td>
</tr>
<tr>
<td> <?php echo $row['email'] ?> </td>
</tr>
<tr>
<td> <p1> الموضوع </p1> </td>
</tr>
<tr>
<td> <?php echo $row['subject'] ?> </td>
</tr>
<tr>
<td> <p1> الرد </p1> </td>
</tr>
<tr>
<td> <textarea name="response" rows="5" dir="rtl" class="inputresponse"> </textarea> </td>
</tr>
<tr>
<td> <input type="submit" value="إرسال" name="send"> </td>
</tr>
<tr>
<td>
<?php
if(isset($_POST['send'])){
$response = $_POST['response'];
$result = ("UPDATE contact SET response ='$response' WHERE id= $row[id]");
$rst = mysqli_query($con,$result);
if($rst){
echo "تم الإرسال";
} else {
echo " لم يتم الإرسال";
}
}
}
?>
</form>
</table>
</div>
</body>
</html>
Your HTML formatting is strange but I think this should accomplish what you want.
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>الرد على التذكرة</title>
<style>
.table, tr, td {
border: 1px solid black;
text-align:center
}
.contents {
position:static
}
p1 {
font-size:15px;
font-weight:bolder
}
.inputresponse {
resize:none
}
.inputid {
text-align:center;
font-size:10px
}
</style>
</head>
<body class="body">
<div class="contents" align="right">
<?php
include 'config.php';
$sql = "SELECT * FROM contact ORDER BY id";
$con->set_charset('utf8');
$users = mysqli_query($con,$sql);
?>
<table class="table">
<?php
while($row = mysqli_fetch_array($users)) {
?>
<form id="<?php echo $row['id'] ?>" method="post" name="respone" action="addresponse.php">
<tr>
<td><input value="<?php echo $row['id'] ?>" name="id" class="inputid" type="hidden"></td>
<tr>
<tr>
<td><p1> الإسم </p1></td>
<tr>
<td><?php echo $row['name'] ?></td>
</tr>
<tr>
<td><p1> رقم التذكرة</p1></td>
</tr>
<tr>
<td><?php echo $row['ticketnumber'] ?></td>
</tr>
<tr>
<td><p1> الإيميل</p1></td>
</tr>
<tr>
<td><?php echo $row['email'] ?></td>
</tr>
<tr>
<td><p1> الموضوع </p1></td>
</tr>
<tr>
<td><?php echo $row['subject'] ?></td>
</tr>
<tr>
<td><p1> الرد </p1></td>
</tr>
<tr>
<td><textarea name="response" rows="5" dir="rtl" class="inputresponse"> </textarea></td>
</tr>
<tr>
<td><input type="submit" value="إرسال" name="send"></td>
</tr>
</form>
<?php
}
?>
</table>
<?php
if(isset($_POST['send'])){
$response = $_POST['response'];
$result = "UPDATE contact SET response = ? WHERE id= ?";
$rst = mysqli_prepare($con,$result);
mysqli_stmt_bind_param($rst, 'si', $response, $_POST['id']);
mysqli_stmt_execute($rst);
if($rst){
echo "تم الإرسال";
} else {
echo " لم يتم الإرسال";
echo mysqli_stmt_error($rst);
}
}
?>
</div>
</body>
</html>
Changes/potential improvements:
Using prepared statements in place of inline values.
Moved update outside of while loop since it is irrelevant.
Moved closing form tag inside the while loop. As is you were making multiple forms but every one was a child of the first because it never closed.
The p1s look like they might be headings? If so they should be outside of the loop.
If you want to display a message next to the row that was updated you could move the whole update process before the page process. Assign it to a variable the status to a variable then in the outputting when you are on that record output the message as well.
Your table rows seem to be closing incorrectly.
I am having a problem with getting the calculation to post anything but 0. all other post has the correct info from the form but the calculation is not working. all the data that comes from the inputs and the calculation of the total pallets works. It is just the total price.
The whole form:
if(!checkAdmin()) {
header("Location: login.php");
exit();
}
$page_limit = 10;
// filter GET values
foreach($_GET as $key => $value) {
$get[$key] = filter($value);
}
foreach($_POST as $key => $value) {
$post[$key] = filter($value);
}
$rs_all = mysql_query("select count(*) as total_all from users") or die(mysql_error());
list($all) = mysql_fetch_row($rs_all);
?>
<?php
$rs_pickup = mysql_query("select count(*) as total_all from pickups") or die(mysql_error());
list($pickup) = mysql_fetch_row($rs_pickup);
?>
<?php
$sql="SELECT companyid, company FROM company ";
$result=mysql_query($sql) or die(mysql_error());
$options="";
while ($row=mysql_fetch_array($result)) {
$id=$row["companyid"];
$thing=$row["company"];
$options.="<OPTION VALUE=\"$id\">".$thing.'</option>';
}
?>
<?php
?>
<?php
$err = array();
if($_POST['doPickup'] == 'Enter Pickup')
if(empty($err)) {
$companyid = $_POST['companyid'];
$sql_grd = "SELECT companyid, grade_a_pu, grade_b_pu, grade_c_pu, ns_pu, custom_pu FROM company WHERE companyid = $companyid";
$result_grd=mysql_query($sql_grd) or die(mysql_error());
while ($row_grd=mysql_fetch_array($result_grd))
{
$price_a = $row_grd["grade_a_pu"];
$price_b = $row_grd["grade_b_pu"];
$price_c = $row_grd["grade_c_pu"];
$price_ns = $row_grd["ns_pu"];
$price_cus = $row_grd["custom_pu"];
}
$total_credit = (($_POST['grade_a_pal']*$price_a)+($_POST['grade_b_pal']*$price_b)+($_POST['grade_c_pal']*$price_c)+($_POST['ns_pal']*$price_ns)+($_POST['cus_pal']*$price_cus));
$sql_insert = "INSERT into `pickups`
(`companyid`,`pu_date`,`trail_num`,`grade_a_pal`,`grade_b_pal`,`grade_c_pal`,`ns_pal`,`cus_pal`,`pal_pu`,`credit`)
VALUES ('$_POST[companyid]','$_POST[pu_date]','$_POST[trail_num]','$_POST[grade_a_pal]','$_POST[grade_b_pal]','$_POST[grade_c_pal]','$_POST[ns_pal]','$_POST[cus_pal]','$_POST[pal_pu]','$total_credit')";
mysql_query($sql_insert,$link) or die("Insertion Failed:" . mysql_error());
}
?>
<html>
<head>
<title>USMI Pallets, Inc. :: Pickup Entry Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="styles.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"> </script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
<script type="text/javascript">
$(document).ready( function() {
$("#datepicker").datepicker({
dateFormat: 'yy-mm-dd',
changeMonth: true,
changeYear: true
});
});
</script>
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<?php include("header.php"); ?>
<tr>
<td colspan="3" height="23" valign="top" style="background-color:#A42914 ">
</td>
</tr>
<?php include("admin_menu.php"); ?>
<td width="800" valign="top" style="padding: 10px;">
<table width="100%" border="0" cellpadding="5" cellspacing="0" class="myaccount">
<tr>
<td>Total Pickups: <?php echo $pickup;?></td>
</tr>
</table>
<p><?php
if(!empty($msg)) {
echo $msg[0];
}
?></p>
<table width="80%" border="0" align="center" cellpadding="10" cellspacing="0" style="background-color: #E4F8FA;padding: 2px 5px;border: 1px solid #CAE4FF;" >
<tr>
<td><form name="form1" method="get" action="pickup_ent.php">
<p align="center">Search Account:
<SELECT NAME=companyid id="q">
<OPTION VALUE=0>Choose
<?=$options?>
</SELECT>
<br>
</p>
<p align="center">
<input name="doSearch" type="submit" id="doSearch2" value="Search">
</p>
</form></td>
</tr>
</table>
<p>
<?php if ($get['doSearch'] == 'Search') {
$sql = "SELECT * FROM pickups WHERE companyid = '$_REQUEST[companyid]' ORDER BY pu_date DESC";
$rs_total = mysql_query($sql) or die(mysql_error());
$total = mysql_num_rows($rs_total);
if (!isset($_GET['page']) )
{ $start=0; } else
{ $start = ($_GET['page'] - 1) * $page_limit; }
$rs_results = mysql_query($sql . " limit $start,$page_limit") or die(mysql_error());
$total_pages = ceil($total/$page_limit);
?>
<?php
// outputting the pages
if ($total > $page_limit)
{
echo "<div><strong>Pages:</strong> ";
$i = 0;
while ($i < $page_limit)
{
$page_no = $i+1;
$qstr = ereg_replace("&page=[0-9]+","",$_SERVER['QUERY_STRING']);
echo "$page_no ";
$i++;
}
echo "</div>";
} ?>
<form name "searchform" action="pickup_ent.php" method="post">
<table width="100%" border="0" align="center" cellpadding="2" cellspacing="0">
<tr bgcolor="#E6F3F9">
<td class="myheader">ID</td>
<td class="myheader">Company #</td>
<td class="myheader">Date</td>
<td class="myheader">Trailer Number</td>
<td class="myheader">Grade A</td>
<td class="myheader">Grade B</td>
<td class="myheader">Grade C</td>
<td class="myheader">Non-Std</td>
<td class="myheader">Custom</td>
<td class="myheader">Total Pickup</td>
<td class="myheader">Total Credit</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<?php while ($rrows = mysql_fetch_array($rs_results)) {?>
<tr>
<td> <div align="center"><?php echo $rrows['pickup_id']; ?></div> </td>
<td> <div align="center"><?php echo $rrows['companyid']; ?></div></td>
<td> <div align="center"><?php echo $rrows['pu_date']; ?></div></td>
<td> <div align="center"><?php echo $rrows['trail_num'];?></div></td>
<td> <div align="center"><?php echo $rrows['grade_a_pal'];?></div></td>
<td> <div align="center"><?php echo $rrows['grade_b_pal'];?></div></td>
<td> <div align="center"><?php echo $rrows['grade_c_pal'];?></div></td>
<td> <div align="center"><?php echo $rrows['ns_pal'];?></div></td>
<td> <div align="center"><?php echo $rrows['cus_pal'];?></div></td>
<td> <div align="center"><?php echo $rrows['pal_pu'];?></div></td>
<td> <div align="center">$<?php echo $rrows['credit'];?></div></td>
<td width="10%">Edit Delete</td>
</tr>
<tr>
<?php } ?>
</table>
<p><br>
</form>
<?php } ?>
</p>
<h2><font color="#FF0000">Pickup Entry
Page</font></h2>
<p> </p>
<form name "pickupform" action="pickup_ent.php" method="post">
<table width="80%" border="0" align="center" cellpadding="10" cellspacing="0" style="background-color: #E4F8FA;padding: 2px 5px;border: 1px solid #CAE4FF;" >
<tr>
<td>
Account:
<SELECT NAME=companyid>
<OPTION VALUE=0>Choose
<?=$options?>
</SELECT> </td>
</tr>
<tr>
<td>Date: <input name="pu_date" type="text" id="datepicker" /></td>
</tr>
<tr>
<td>Trailer #:<select name="trail_num" id="trail_num">
<option selected value=""></option>
<option value="1986-1">1986-1</option>
<option value="1986-2">1986-2</option>
<option value="1986-3">1986-3</option>
<option value="1986-4">1986-4</option>
<option value="1986-5">1986-5</option>
<option value="1986-6">1986-6</option>
<option value="1986-7">1986-7</option>
<option value="1986-8">1986-8</option>
<option value="1986-9">1986-9</option>
<option value="1986-10">1986-10</option>
<option value="1986-11">1986-10</option>
<option value="1986-12">1986-12</option>
</select></td>
</tr>
<tr>
<td>Grade A Pallets: <input id="grade_a_pal" name="grade_a_pal" type="text" size="8"> </td>
</tr>
<tr>
<td>Grade B Pallets: <input id="grade_b_pal" name="grade_b_pal" type="text" size="8"> </td>
</tr>
<tr>
<td>Grade C Pallets: <input id="grade_c_pal" name="grade_c_pal" type="text" size="8"> </td>
</tr>
<tr>
<td>Non-Standard Pallets: <input id="ns_pal" name="ns_pal" type="text" size="8"></td>
</tr>
<tr>
<td>Custom Pallets: <input id="cus_pal" name="cus_pal" type="text" size="8"></td>
</tr>
<tr>
<tr>
<td>Total Pallets Picked Up:
<input id="pal_pu" name="pal_pu" type="text" size="8" readonly></td>
</tr>
<td><input name="doPickup" type="submit" id="doPickup" value="Enter Pickup"></p>
</td>
</tr>
</table>
<script>
$(document).ready(function() {
//this calculates values automatically
sum();
$("#grade_a_pal, #grade_b_pal, #grade_c_pal, #cus_pal").on("keydown keyup", function() {
sum();
});
});
function sum() {
var grade_a_pal = document.getElementById('grade_a_pal').value;
var grade_b_pal = document.getElementById('grade_b_pal').value;
var grade_c_pal = document.getElementById('grade_c_pal').value;
var ns_pal = document.getElementById('ns_pal').value;
var cus_pal = document.getElementById('cus_pal').value;
var result = parseInt(grade_a_pal) + parseInt(grade_b_pal) + parseInt(grade_c_pal) + parseInt(ns_pal) + parseInt(cus_pal);
if (!isNaN(result)) {
document.getElementById('pal_pu').value = result;
}
}
</script>
</form>
<p> </p>
<p> </p>
<p> </p></td>
<td width="12%"> </td>
</tr>
<tr>
<td colspan="3" height="43" valign="top" style="background-color:#A42914 ">
<table width="766" style="height:100% " border="0" cellspacing="0" cellpadding="0">
<tr>
<td valign="top" class="myfooter">
<div style="margin:12px 0px 0px 31px; ">
© 2012 USMI Pallets, Inc. All rights reserved
</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
It appears you are using $_post (lower case) instead of $_POST (uppercase) for your pallets vars.
Try outputting a print_r($_POST) to see what you are getting in your $_POST array. It could just be you are referencing the wrong vars.
Hye there, can i ask some question. I want to update data in my database i using a id that had been set in my database. The data can be update, but i want in the update page. Information in database been view first than i can delete and change for the new input. The coding right here. Can you give me idea how to do it.
<?php
require "cn.php";
$query=mysql_query("select*from medicine");
$num=1;
?>
<!DOCTYPE HTML>
<head>
<style>
body
{
background:url("pharmacy.jpg");
background-size:2000px 1100px;
background-repeat:no repeat;
padding-top:40px;
}
</style>
<title>View Stock</title>
</head>
<table align="center" width="800" border="5" bgcolor="white" bordercolor="red">
<tr>
<td><div align="center"><a href="mainpage.php" >HOME</div></a></td>
<td><div align="center">STOCK</div></td>
<td><div align="center">REPORT</div></td>
<td><div align="center">UPDATE INFORMATION</div></td>
</tr>
</table>
<br>
<br>
<br>
<br>
<div align="middle">
<table border="5" bgcolor="white" bordercolor="red">
<tr align="middle">
<td>No</td>
<td>Code</td>
<td>Medicine</td>
<td>Stock</td>
<td>Price</td>
<td colspan="2">action</td>
</tr>
<?php
while($fetch=mysql_fetch_object($query))
{
?>
<tr>
<td><?php echo $num;?></td>
<td> <?php echo $fetch->code;?></td>
<td><?php echo $fetch->medicine;?></td>
<td><?php echo $fetch->stock;?></td>
<td><?php echo $fetch->price;?></td>
<td>update</td>
<td>delete</td>
</tr>
<?php
$num++;
}
?>
</div>
</table>
</html>
Update.php coding
<?php
if(isset($_GET['id']))
$id=$_GET['id'];
?>
<!DOCTYPE HTML>
<head>
<title>Update stock</title>
<style>
body
{
background:url("pharmacy.jpg");
background-size:2000px 1100px;
background-repeat:no repeat;
padding-top:40px;
}
</style>
</head>
<form Action="updateh.php" method="post">
<table align="center" width="800" border="5" bgcolor="white" bordercolor="red">
<div align="center"><h2>Enter New Update</h2></div>
<tr>
<td align="center" colspan=4>Name</td>
</tr>
<br>
<div align="right">
<font color="white">Back to Stock Update</font><br>
</div>
<tr>
<td><div align="center">Code</div></td>
<td><div align="center">Medicine</div></td>
<td><div align="center">Stock</div></td>
<td><div align="center">Price(RM)</div></td>
</tr>
<tr>
<td><div align="middle"><input type="textbox" name="code" required></div></td>
<td><div align="middle"><input type="textbox" name="medicine" required></div></td>
<td><div align="middle"><input type="textbox" name="stock" required></div></td>
<td><div align="middle"><input type="textbox" name="price" required></div></td>
</tr>
<tr>
<td align="middle" colspan=4><input type="submit" value="update">
<input type="hidden" name="id" value="<?php echo $id;?>">
</td>
</tr>
</table>
</Form>
</html>
updateh.php coding
<?php
session_start();
require "cn.php";
$id=$_POST['id'];
$code=$_POST['code'];
$medicine=$_POST['medicine'];
$stock=$_POST['stock'];
$price=$_POST['price'];
mysql_query("update medicine set code='$code', medicine='$medicine', stock='$stock',
price='$price' where id='$id'");
echo header("location: sucess2.php");
?>
if(isset($_POST['submit'])) {
$code= $_POST['code'];
$medicine= $_POST['medicine'];
$stock= $_POST['stock'];
$price= $_POST['price'];
$sql= mysql_query(UPDATE `your_table` SET `code`,`medicine`,`stock`,`price`) VALUES ('$code','$medicine','stock','$price') WHERE `id`='$id';
}
Use this and then read and use mysqli instead of mysql
I have a fwrite writing each business' page but i want it so that it only shows the html of the page when you go to the url with a valid session so i wrote
fwrite($fp,"
However when it writes the page it writes this . The isset statement is gone from the if statement.
<?php
$recid = $_POST['recid'];
$username = $_POST['name'];
$email = $_POST['email'];
$ownername = $_POST['ownername'];
include ("connection.php");
$result = $db->query("UPDATE users SET verified='y' WHERE recid='$recid'");
$doctype = "<!DOCTYPE html>";
$htmlOpen = "<html>";
$head = "<head> <meta http-equiv='Content-Type' content='text/html; charset=ISO-8859-1'>
<script src='http://code.jquery.com/jquery-1.9.1.min.js'> </script>
<script src='http://code.jquery.com/ui/1.10.2/jquery-ui.js'> </script>
<script src='Scripts/dropdown.js'> </script>
<link rel='stylesheet' href='CSS/businesspages.css'>
<link rel='stylesheet' href='http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css'>
<script src='Scripts/postdata.js'> </script>
</head>";
$bodyOpen = "<body>";
$header = "<div id='header'> </div>";
$wcImage = "<img src='wc.png' id='wc'>";
$accountTable = "<table id='accountinfo'>
<tr> <td id='accountinfotd1'> </td> </tr>
<tr> <td id='accountinfotd2'>{$username}</td> </tr>
<tr> <td id='accountinfotd3'>{$ownername}</td> </tr>
</table>";
$linksTable = "<table id='links'>
<tr> <td> <input type='text' id='post' placeholder='Post' name='post'> </td> </tr>
<tr> <td> <img src='images/profile.jpg' id='profile'> </td> </tr>
<tr> <td> <div id='profileDiv'>
<table>
<tr>
<td> <input type='password' id='changePSW' name='changePSW' placeholder='Change Password' tabindex=2> </td>
<td> <input type='password' id='verifyPSW' name='verifyPSW' placeholder='Verify Password' tabindex=3> </td>
<td> <input type='image' id='changePSWBtn' src='images/changeBtn.jpg' name='changePSWBtn'> </td>
</tr>
<tr>
<td> <input type='text' id='changeLA' name='changeLA' placeholder='Latitude' tabindex=6> </td>
<td> <input type='text' id='changeLO' name='verifyPSW' placeholder='Longatude' tabindex=7> </td>
<td> <input type='image' id='changeLLBtn' src='images/changeBtn.jpg' name='changeLLBtn'> </td>
</tr>
</table>
</div> </td> </tr>
<tr> <td> <img src='images/legal.jpg' id='legal'> </td> </tr>
<tr> <td> <div id='legalDiv'>
<a href='Legal_Documents/termsofuseweb.pdf' target='_blank'> Web Terms Of Use </a> </br>
<a href='Legal_Documents/termsofuseios.pdf' target='_blank'> iOS Terms Of Use </a> </br>
<a href='Legal_Documents/enduserlisenceagreement.pdf' target='_blank'> End Of User Licensee </a>
</div> </td> </tr>
<tr> <td> <img src='images/help.jpg' id='help'> </td> </tr>
<tr> <td> <div id='helpDiv'>
<p> If you need help you can contact Phil Pilon or Matt Muehlemann info#wolfeboroconnection.com </p>
</div> </td> </tr>
</table>";
$bodyClose = "</body>";
$htmlClose = "</html>";
$isset = "{$_SESSION['id']}";
$filename = str_replace(" ","_", trim($username) );
mkdir("Business_Pages/" . $filename."/");
if( $fp = fopen("Business_Pages/" . $filename . "/" . $filename . ".php", "w") )
{
fwrite($fp,"<?php session_start();");
fwrite($fp, "if(isset({$_SESSION['id']})) { ?");
fwrite($fp, $doctype.$htmlOpen.$head.$bodyOpen.$header.$wcImage.$accountTable.$linksTable.$bodyClose.$htmlClose);
fwrite($fp,"<?php } else { echo \"User not logged in\";} ?>");
fclose($fp);
}
This is the page it fwrites
<?php session_start();if() { ?><!DOCTYPE html>
<html><head> <meta http-equiv='Content-Type' content='text/html; charset=ISO-8859-1'>
<script src='http://code.jquery.com/jquery-1.9.1.min.js'> </script>
<script src='http://code.jquery.com/ui/1.10.2/jquery-ui.js'> </script>
<script src='Scripts/dropdown.js'> </script>
<link rel='stylesheet' href='CSS/businesspages.css'>
<link rel='stylesheet' href='http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css'>
<script src='Scripts/postdata.js'> </script>
</head>
<body>
<div id='header'> </div><img src='wc.png' id='wc'><table id='accountinfo'>
<tr> <td id='accountinfotd1'> </td> </tr>
<tr> <td id='accountinfotd2'>test </td> </tr>
<tr> <td id='accountinfotd3'></td> </tr>
</table><table id='links'>
<tr> <td> <input type='text' id='post' placeholder='Post' name='post'> </td> </tr>
<tr> <td> <img src='images/profile.jpg' id='profile'> </td> </tr>
<tr> <td> <div id='profileDiv'>
<table>
<tr>
<td> <input type='password' id='changePSW' name='changePSW' placeholder='Change Password' tabindex=2> </td>
<td> <input type='password' id='verifyPSW' name='verifyPSW' placeholder='Verify Password' tabindex=3> </td>
<td> <input type='image' id='changePSWBtn' src='images/changeBtn.jpg' name='changePSWBtn'> </td>
</tr>
<tr>
<td> <input type='text' id='changeLA' name='changeLA' placeholder='Latitude' tabindex=6> </td>
<td> <input type='text' id='changeLO' name='verifyPSW' placeholder='Longatude' tabindex=7> </td>
<td> <input type='image' id='changeLLBtn' src='images/changeBtn.jpg' name='changeLLBtn'> </td>
</tr>
</table>
</div> </td> </tr>
<tr> <td> <img src='images/legal.jpg' id='legal'> </td> </tr>
<tr> <td> <div id='legalDiv'>
<a href='Legal_Documents/termsofuseweb.pdf' target='_blank'> Web Terms Of Use </a> </br>
<a href='Legal_Documents/termsofuseios.pdf' target='_blank'> iOS Terms Of Use </a> </br>
<a href='Legal_Documents/enduserlisenceagreement.pdf' target='_blank'> End Of User Licensee </a>
</div> </td> </tr>
<tr> <td> <img src='images/help.jpg' id='help'> </td> </tr>
<tr> <td> <div id='helpDiv'>
<p> If you need help you can contact Phil Pilon or Matt Muehlemann info#wolfeboroconnection.com </p>
</div> </td> </tr>
</table></body></html><?php } else { echo "User not logged in";} ?>
The reason is because you are using the following line:
fwrite($fp, "if(isset({$_SESSION['id']})) { ?");
Because you are using double quotes it means that the session value {$_SESSION['id']} will be parsed by PHP, before being written to the file via fwrite. If you change your quotes to single quotes you wont have this problem, as PHP will leave single quoted strings alone — i.e. not parse them for variables:
fwrite($fp, 'if(isset($_SESSION["id"])) { ?');
You should also remove the surrounding curly braces on the session var, unless you want your php to be erroneous when it is reparsed.
This is all assuming that the outcome you want in the file is:
if(isset($_SESSION["id"])) { ?
can anybody tell me what is wrong with this code, i am getting the following error
Notice: Undefined index: media_type in C:\wamp\www\VirtualLibrary\upload_file.php on line 10
Notice: Undefined index: file in C:\wamp\www\VirtualLibrary\upload_file.php on line 14
Notice: Undefined index: file in C:\wamp\www\VirtualLibrary\upload_file.php on line 20
Notice: Undefined index: file in C:\wamp\www\VirtualLibrary\upload_file.php on line 22
here is my code
<html>
<head>
<title>Virtual Library</title>
<link href="css/login.css" rel="stylesheet"/>
<link href="css/style.css" rel="stylesheet"/>
<script type="text/javascript" src="scripts/ajax_search.js"></script>
</head>
<body>
<div id="wrapper">
<div id="header" align="center">
<ul align="center">
<li><span>Home</span></li>
<li><span>Top 100 Downloads</span></li>
<?php if(isset($_SESSION['login_user']))
{
$uname = $_SESSION['login_user'];
echo "<li><a href='upload.php'><span>Upload</span></a></li>";
}?>
<?php if(isset($_SESSION['login_user']))
{
$uname = $_SESSION['login_user'];
echo "<li><a href='profile.php'><span>$uname</span></a></li>";
echo "<li><a href='logout.php'><span>LogOut</span></a></li>";
}
else{
echo "<li><a href='login.php'><span>Member Login</span></a></li>";
echo "<li><a href='register.php'><span>Register</span></a></li>";
}
?>
<li><span>RSS <img src="images/rss.gif" id="rss"></span></li>
</ul>
</div>
<div class='frmdiv'>
<form action='upload_file.php' method='post' enctype='multipart/form-data'>
<table width='38%' border='0' align='center' cellpadding='0' cellspacing='0'>
<tr>
<td colspan='2'><div align='center'><font size='2' face='verdana'>Upload File</font></div></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan='2'><hr></td>
</tr>
<tr>
<td height='26'><font size='2' face='verdana'>FileName </font></td>
<td><font size='2' face='verdana'>
<input type='file' name='file' ></font>
</td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td></td>
<td><select name='media_type' >
<option value='' selected>Select a media type...</option>
<option value='pdf'>PDF</option>
<option value='chm'>CHM</option>
<option value='epub'>EPUB</option>
<option value='html'>HTML</option>
<option value='djvu'>DJVU</option>
</select></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td><font size='2' face='verdana'>
<input type='submit' name='Submit' value='Upload'></font>
</td>
</tr>
<tr>
<td colspan='2'><hr></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</table>
</form>
<div align='center'>
}
</div>
</body>
</html>
and here is the upload_file.php
<?php
require('include/connection.php');
session_start();
?>
<?php
foreach ($_POST as $var => $value) {
echo "$var = $value<br>n";
}
$meditype = $_POST['media_type'];
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
if (file_exists($meditype . "/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"], $meditype . "/" . $_FILES["file"]["name"]);
}
}
?>
You are not checking to see if the post data exists. Use isset to do that. Ex
if (isset($_POST['media_type'])) {
// Media type field was posted
}
Please do not create separate questions for the same underlying issue: Getting the value of a combo-box using post method