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"])) { ?
Related
I generating a QR CODE with url as data content, but when i try to print a page where the qr is generated, the qr does not seem to appear yet other content displays. Here is my snippet
<?php
require_once("qrcode.php");
//---------------------------------------------------------
$qr = new QRCode();
// ƒGƒ‰[’ù³ƒŒƒxƒ‹‚ðÝ’è
// QR_ERROR_CORRECT_LEVEL_L : 7%
// QR_ERROR_CORRECT_LEVEL_M : 15%
// QR_ERROR_CORRECT_LEVEL_Q : 25%
// QR_ERROR_CORRECT_LEVEL_H : 30%
$qr->setErrorCorrectLevel(QR_ERROR_CORRECT_LEVEL_L);
$qr->setTypeNumber(4);
$qr->addData("http:/".$_SERVER['REQUEST_URI']."");
$qr->make();
//---------------------------------------------------------
?>
and below is the other content on the page
<div class="invoice-box" id="invoice-box">
<table cellpadding="0" cellspacing="0">
<tr class="top">
<td colspan="2">
<table>
<tr>
<td class="title">
<img src="images/logo.png" style="width:100%; max-width:200px; height:95px;">
</td>
<td>
Invoice #: <?php print $invoice_details->sub_code ?><br>
Created: <?php print date('Y/M/d', strtotime($invoice_details->paid_date)) ?><br>
Due: February 1, 2015
</td>
</tr>
</table>
</td>
</tr>
<tr class="information">
<td colspan="2">
<table>
<tr>
<td>
<br>
<br>
</td>
<td>
<?php print $invoice_details->org ?><br>
<?php print $invoice_details->lname ?> <?php print $invoice_details->fname ?><br>
<?php print $invoice_details->email ?>
</td>
<td>
<?php $qr->printHTML(); ?>
</td>
</tr>
</table>
</td>
</tr>
<tr class="heading">
<td>
Payment Method
</td>
<td>
</td>
</tr>
<tr class="details">
<td>
<?php print $invoice_details->method ?>
</td>
<td>
</td>
</tr>
<tr class="heading">
<td>
Item
</td>
<td>
Price(UGX)
</td>
</tr>
<tr class="item">
<td>
<?php print ucfirst($invoice_details->event) ?> - Summit
</td>
<td>
<?php print number_format($invoice_details->amount) ?>
</td>
</tr>
<tr class="total">
<td></td>
<td>
Total: UGX <?php print number_format($invoice_details->amount) ?>
</td>
</tr>
</table>
</div>
<input type="button" value="Print Div" onclick="PrintElem('#invoice-box')" />
and my printing script
<script type="text/javascript">
function PrintElem(elem)
{
Popup($(elem).html());
}
function Popup(data)
{
var mywindow = window.open('', 'invoice-box', 'height=400,width=600');
mywindow.document.write('<html><head><title>my div</title>');
/*optional stylesheet*/ //mywindow.document.write('<link rel="stylesheet" href="main.css" type="text/css" />');
mywindow.document.write('</head><body >');
mywindow.document.write(data);
mywindow.document.write('</body></html>');
mywindow.document.close(); // necessary for IE >= 10
mywindow.focus(); // necessary for IE >= 10
mywindow.print();
mywindow.close();
return true;
}
</script>
Assuming I found the correct library, it has an image creator. What you need to do is use an output buffer around the imagegif (or imagepng) call to capture the image's binary data into a string, then base64 encode the string, and echo that as part of a data URI directly in the src attribute of an img tag.
$img = $qr->createImage(4, 2);
ob_start();
imagegif($img);
imagedestroy($img);
$img = ob_get_clean();
In your HTML
<img src="data:image/gif;base64,<?php echo base64_encode($img);?>">
If you're concerned about support for data URLs, leave out the output buffering, add a unique, random filename as the second parameter to the imagegif call to save it, then echo that filename in the src.
It seems that you're trying to print a black background color which is removed by default from printing. Unfortunately there's no way to force it back programatically in browsers other than Safari and Chrome.
You can force this back for Safari and Chrome by doing:
<div class="invoice-box" id="invoice-box">
<style>
.invoice-box table td: {
-webkit-print-color-adjust: exact !important;
}
</style>
<table cellpadding="0" cellspacing="0">
<tr class="top">
<td colspan="2">
<table>
<tr>
<td class="title">
<img src="images/logo.png" style="width:100%; max-width:200px; height:95px;">
</td>
<td>
Invoice #: <?php print $invoice_details->sub_code ?><br>
Created: <?php print date('Y/M/d', strtotime($invoice_details->paid_date)) ?><br>
Due: February 1, 2015
</td>
</tr>
</table>
</td>
</tr>
<tr class="information">
<td colspan="2">
<table>
<tr>
<td>
<br>
<br>
</td>
<td>
<?php print $invoice_details->org ?><br>
<?php print $invoice_details->lname ?> <?php print $invoice_details->fname ?><br>
<?php print $invoice_details->email ?>
</td>
<td>
<?php $qr->printHTML(); ?>
</td>
</tr>
</table>
</td>
</tr>
<tr class="heading">
<td>
Payment Method
</td>
<td>
</td>
</tr>
<tr class="details">
<td>
<?php print $invoice_details->method ?>
</td>
<td>
</td>
</tr>
<tr class="heading">
<td>
Item
</td>
<td>
Price(UGX)
</td>
</tr>
<tr class="item">
<td>
<?php print ucfirst($invoice_details->event) ?> - Summit
</td>
<td>
<?php print number_format($invoice_details->amount) ?>
</td>
</tr>
<tr class="total">
<td></td>
<td>
Total: UGX <?php print number_format($invoice_details->amount) ?>
</td>
</tr>
</table>
</div>
<input type="button" value="Print Div" onclick="PrintElem('#invoice-box')" />
For browsers like IE and Firefox unfortunately this requires user interaction. See this question for more answers: Printing background-color in Firefox and IE
Finally, i got a way around this, here is my solution
<?php
require_once("qrcode.php");
$qr = QRCode::getMinimumQRCode("http:/".$_SERVER['REQUEST_URI']."", QR_ERROR_CORRECT_LEVEL_L);
$img = $qr->createImage(4, 2);
ob_start();
imagegif($img);
imagedestroy($img);
$img = ob_get_clean();
?>
Then output the qrcode as image with this;
<img src="data:image/gif;base64,<?php echo base64_encode($img);?>">
Thanks to #walf for his solution somehow, hope it helps someone else.
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.
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
My html code but saved as Modyfyitems.php
<?include 'Login/login_check.php';?>
<?include 'inc/Application.php';?>
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Untitled Document</title>
<style type="text/css">
body {
background-color: #284489;
text-shadow: 0px 0px #FFFFFF;
color: #FFFFFF;
}
form1 {
background-color: #FFFFFF
}
</style>
<link rel="stylesheet" type="text/css" media="all" href="css/jsDatePick_ltr.min.css" />
<script type="text/javascript" src="js/jsDatePick.min.1.3.js"></script>
<script type="text/javascript">
window.onload = function(){
new JsDatePick({
useMode:2,
target:"datereceived",
dateFormat:"%d-%M-%Y"
});
};
</script>
</head>
<body>
<h2> </h2>
<form id="form1" name="form1" aling="center" method="post">
<div align="center">
<table width="393" border="0">
<tr>
<td><div align="center">
<h2><span style="text-align: left; color: #FFFFFF;">LAC Product Registery</span></h2>
</div></td>
</tr>
</table>
<p>
<input type="button" name="button4" id="button4" onClick="location.href='Menu.php'" value="Menu">
</p>
</div>
<div align="center" style="background-color: #FFFFFF; color: #000000;">
<table width="827" border="0" align="center">
<tr bgcolor="#FDFDFD">
<td width="501"><h3>Modify Items</h3>
<p>Enter Code
<input name="barcode" type="text" autofocus required="required" id="barcode" form="form1">
<input type="submit" name="search" id="search" onClick="location.href='Actions/loaditem.php'" value="Search">
</p>
<table width="500" border="0" cellpadding="10" cellspacing="1">
<tr>
<td width="141" bgcolor="#E8F1FC">Sponsor</td>
<td width="316" bgcolor="#E8F1FC"><?include 'Actions/loadLists/sponsor.php';?></td>
</tr>
<tr>
<td bgcolor="#f1f4f9">Date Received</td>
<td bgcolor="#f1f4f9"><input type="datetime" name="datereceived" value="<? echo $DateReceived; ?>" id="datereceived" placeholder="17-FEB-2014"></td>
</tr>
<tr>
<td bgcolor="#E8F1FC"><strong>Code</strong></td>
<td bgcolor="#E8F1FC"> </td>
</tr>
<tr>
<td bgcolor="#F1F4F9"><ul>
<li> Container</li>
</ul></td>
<td bgcolor="#F1F4F9"><input name="container" type="number" value="<? echo $Container; ?>" id="container" placeholder="0152"></td>
</tr>
<tr>
<td bgcolor="#E8F1FC"><ul>
<li>Pallet</li>
</ul></td>
<td bgcolor="#E8F1FC"><input name="pallet" type="number" value="<? echo $Pallet; ?>" id="number5" placeholder="0028"></td>
</tr>
<tr>
<td bgcolor="#F1F4F9"><ul>
<li>Amount</li>
</ul></td>
<td bgcolor="#F1F4F9"><input name="amount" type="number" id="number6" value="<? echo $Amount; ?>" placeholder="0002"></td>
</tr>
<tr>
<td bgcolor="#E8F1FC">Description</td>
<td bgcolor="#E8F1FC"><?include 'Actions/loadLists/descriptions.php';?></td>
</tr>
<tr>
<td bgcolor="#F1F4F9">Remarks</td>
<td bgcolor="#F1F4F9"><textarea name="remarks" id="remarks"><? echo $Remarks; ?></textarea></td>
</tr>
<tr>
<td bgcolor="#E8F1FC">Location</td>
<td bgcolor="#E8F1FC"><?include 'Actions/loadLists/locations.php';?></td>
</tr>
<tr>
<td height="18"> </td>
<td> </td>
</tr>
</table></td>
<td width="316" valign="top" style="text-align: left"><p><br>
</p>
<p> Documents</p>
<p> </p></td>
</tr>
</table>
</div>
<table width="383" border="0" align="center">
<tr>
<td width="377" style="text-align: center"><input type="button" name="button" id="button" value="Save">
...
<input type="button" name="button6" id="button6" onClick="location.href='Menu.php'" value="Cancel">
...
<input type="button" name="button2" id="button2" value="Delete">
...
<input type="button" name="button3" id="button3" value="Print Barcode"> </td>
</tr>
</table>
<p> </p>
<p> </p>
<p> </p>
</form>
<p> </p>
<p> </p>
</body>
</html>
Here is my PHP script
<?
$conn = mysql_connect('localhost', 'root', 'root');
if (!$conn)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("LAC", $conn);
$Barcode =$_REQUEST['barcode'];
$result = mysql_query("SELECT * FROM Lists WHERE Barcode = '$Barcode'");
$row = mysql_fetch_array($result);
if (!$result)
{
die("Error: Data not found..");
}
$Barcode = $row['Barcode'];
$Sponsor = $row['Sponsor'];
$DateReceived = $row['DateReceived'];
$Container = $row['Container'];
$Pallet = $row['Pallet'];
$Amount = $row['Amount'];
$Description = $row['Description'];
$Remarks = $row['Remarks'];
$Location = $row['Location'];
mysql_close($conn);
?>
So Basically I am trying to load all the text boxes and drop down boxes from the database when the correct barcode is entered and the search button is hit.
For some reason when I hit the search button it doesn't load anything it just reloads the page.
I am new to php but have programming experience in vb.net
I think your are initializing variables after fetching values from the database in PHP script. so the scope of those variable is only withing that file. So, I guess if you include that file in modifyitem.php, this would work.
thank you.
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";
}