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
Related
So im kinda trying to delete row from my mysql database using checkboxes. Here is my code. Would be glad if someone could write me down simple delete code. Tryed many but failed, stuck for hours with this :(
<html>
<head>
<title>Admin, User</title>
</head>
<body>
<?php include 'connect.php';?>
<?php include 'functions.php';?>
<?php include 'title_bar.php';?>
<h3>Sukurti Nauja uzduoti: </h3>
<form method='post'>
<?php
if(isset($_POST['submit2']))
{
$pav = $_POST['pav'];
$uzduotis = $_POST['uzduotis'];
if(empty($pav) or empty($uzduotis)){
echo "<p>Privalomi visi langai!</p>";
}
else {
$sql = ("INSERT INTO uzduotys VALUES ('','$pav','$uzduotis')");
}
if($database->query($sql) == TRUE)
{
header('location:kurtisalinti.php');
}
else {
echo "<p>Klaida!</p>";
}
}
?>
<p>Uzduoties pavadinimas:
<p><input type='text' name='pav' />
<p>Uzduotis:
<p><textarea name='uzduotis'></textarea>
<p><input type='submit' name='submit2' value='Sukurti Uzduoti' />
</form>
</p></p></p></p>
</form>
<h3>Pasalinti pasirinkta uzduoti is uzduociu saraso: </h3>
<?php
$query = mysqli_query($database,"SELECT uzid,pav,uzduotis FROM uzduotys");
$count=mysqli_num_rows($query);
?>
<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<td><form name="form1" method="post" action="">
<table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td align="center" bgcolor="#FFFFFF">#</td>
<td align="center" bgcolor="#FFFFFF"><strong>id</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Pavadinimas</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Aprasymas</strong></td>
</tr>
<?php
while($rows = mysqli_fetch_array($query)){
?>
<tr>
<td align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox" value="<?php echo $row['uzid']; ?>"></td>
<td bgcolor="#FFFFFF"><?php echo $rows['uzid']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $rows['pav']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $rows['uzduotis']; ?></td>
</tr>
<?php
}
?>
<tr>
<td colspan="5" align="center" bgcolor="#FFFFFF"><input name="delete" type="submit" id="delete" value="Istrinti Uzduotis"></td>
</tr>
<?php
?>
</table>
</form>
</td>
</tr>
</table>
</body>
</html>
Welcome to StackOverflow! Generally as a rule of thumb asking to write you some code doesn't get you very far, however I know that some people learn better from seeing it implemented and being able to modify off of that.
There is a number of ways you can do this. Using something like jquery and ajax you can post your requests without having to reload the page. Keep in mind what I have below may not fully work for you since taking the time to do this much already without a database or connection should give you an idea of what you're looking to do. Good luck!
CAUTION: PSUEDO CODE (This may not fully work and is not intended for production) The idea is to show you an approach to achieving what you are looking for.
<?php
include('connect.php');
include('functions.php');
include('title_bar.php');
if(isset($_POST['submit-uzduotis']))
{
$pav = $_POST['pav'];
$uzduotis = $_POST['uzduotis'];
if(empty($pav) or empty($uzduotis))
{
$result = "<span>Privalomi visi langai!</span>";
}
else
{
$sql = ("INSERT INTO uzduotys VALUES ('','$pav','$uzduotis')");
}
if($database->query($sql) == true)
{
header('location:kurtisalinti.php');
}
else
{
$result = "<span>Įvyko klaida!</span>";
}
}
if(isset($_POST['remove']))
{
$id = mysql_real_escape_string($_POST['remove']);
mysqli_query($database, "DELETE FROM uzduotys WHERE uzid = $id");
}
function showTableData()
{
$query = mysqli_query($database, "SELECT uzid, pav, uzduotis FROM uzduotys");
$count = mysqli_num_rows($query);
while($row = mysqli_fetch_array($query))
{
echo '<tr id="'. $row['uzid'] .'">
<td>
<input type="checkbox" name="checkbox[]" value="'. $row['uzid'] .'">
</td>
<td>'. $row['uzid'] .'</td>
<td>'. $row['pav'] .'</td>
<td>'. $row['uzduotis'] .'</td>
<td>
<button id="remove-single" data-id="'. $row['uzid'] .'">REMOVE</button>
</td>
</tr>';
}
}
?>
<html>
<head>
<title>Admin, User</title>
<style>
.uzduotis-table {
background-color: #ccc;
border-collapse: collapse;
}
.uzduotis-table thead > td {
background-color: #333;
font-weight: bold;
}
.uzduotis-table td {
padding: 3px;
text-align: center;
background-color: #fff;
}
label {
display:block;
position:relative;
font-weight: bold;
}
</style>
</head>
<body>
<h3>Sukurti Nauja uzduoti: </h3>
<form method='post'>
<?php echo $result; ?>
<div>
<label>Uzduoties pavadinimas:</label>
<input type='text' name='pav' />
</div>
<div>
<label>Uzduoties:</label>
<textarea name='uzduotis'></textarea>
</div>
<div>
<input type='submit' name='submit-uzduoties' value='Sukurti Uzduoti' />
</div>
</form>
<h3>Pasalinti pasirinkta uzduoti is uzduociu saraso: </h3>
<table class="uzduotis-table">
<thead>
<tr>
<td>#</td>
<td>Id</td>
<td>Pavadinimas</td>
<td>Aprasymas</td>
</tr>
</thead>
<tbody>
<?php showTableData(); ?>
<tr>
<td colspan="5">
<button id="remove-selected" data-id="'. $row['uzid'] .'">REMOVE SELECTED</button>
</td>
</tr>
</tbody>
</table>
<script src="https://code.jquery.com/jquery-2.2.3.min.js" integrity="sha256-a23g1Nt4dtEYOj7bR+vTu7+T8VP13humZFBJNIYoEJo=" crossorigin="anonymous"></script>
<script>
$(document).ready(function(){
// Remove Single (Button)
$('body').on('click', '#remove-single', function() {
remove($(this).data('id'));
});
// Remove All Checked
$('body').on('click', '#remove-selected', function() {
$('.uzduotis-table tr').filter(':has(:checkbox:checked)').each(function() {
remove(this.id);
});
});
function remove(id)
{
console.log("Remove: " + id);
alert('Removing: ' + id);
$.ajax({
type: "POST",
url: '<?php echo $url; ?>',
data: { remove: id },
success: function (data) {
$('#' + id).remove();
}
});
}
})
</script>
</body>
</html>
I cleaned up a bit of the html and styles, just made it easier for me to read. Also I would recommend looking into a library such as PDO to handle your database queries as there currently isn't much in place to protect or safe guard against sql injection.
im developing a project my own and i use codeigniter as my framework, i'm pretty begginer to php and codeignier. i created a confirm box in jquery ,but it's and html alert. so how to do that? don't laugh at me guys. thanks.
view
<?php
$_instance = get_instance();
$attributes = array('id' => 'main_form');
?>
<?php echo form_open('registration/reset',$attributes);?>
<style>
span{
color: red;
}
#main_tb{
margin-top:100px;
}
</style>
<table cellspacing='10' id>
</table>
<div id='main_form'>
<form id="main_form" name="form">
<table CELLSPACING=2 CELLSPACING=10 id='main_tb' >
<tr>
<td></td>
<td id="error"></td>
</tr>
<tr>
<td>User Name</td>
<td> <select class="cmb" style="width: 200px;" id="cmb_user" name="cmb_user"> </select></td>
</tr>
<tr>
<td></td>
<td><?php echo $this->session->flashdata('reset_error'); ?></td>
</tr>
<tr>
<td></td>
<td> <input type="submit" id="save" value="reset password"/></td>
</tr>
</table>
</form>
</div>
<?php echo form_close();?>
script
$j('#main_form').submit(function() {
// event.preventDefault();
var status = confirm("Are you sure? This cannot be undone");
if(status == false){
return false;
}
else{
return true;
}
});
controller
function reset(){
$password =$_POST['cmb_user'];
echo $username = $this->input->post('cmb_user');
$data_array = array(
'id_user' => $this->input->post('cmb_user'),
);
// // echo 'sdsd';
// echo $_POST['cmb_user'];
//
$this->load->model('registration/registration_model');
$this->registration_model->reset_pass($data_array);
$this->session->set_flashdata('reset_error', ' <br><span style="font-size: 10px;background-color: #FFFFFF;color:#ff0000;border:solid 1px #ff99cc;padding:2px;border-radius: 5px 5px 5px 5px">Reset Successfull</span>');
redirect('/registration/admin_reset');
}
this function works great. but i want to add jquery fancy popup like sweet alert. thank's again..
Add the following code into your view
<script src="https://cdn.rawgit.com/t4t5/sweetalert/master/dist/sweetalert.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.rawgit.com/t4t5/sweetalert/master/dist/sweetalert.css">
<script language="javascript">
sweetAlert("Oops...", "Something went wrong!", "error");
</script>
Hi if you go to http://www.deakin.edu.au/~jrhaywar/SIT104/Contact.php you will find the webpage workings (or not working in this case). What i wish for the program to do is show the form if there is not post action however if there is a post action to replace the form entries with the details of the forms. As Well as add the details to the SQL Database. However it now just repeats the tables and forms multiple times. Could someone look at this quickly for me and try to help fix the problem?
Cheers
Jesse,
Here's the code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Assignment 1 - SIT 104 - 214151511</title>
<!--This is where the Classes and Division Styles are setup for recall later in the code-->
<style type="text/css">
#Wrapper{
Background:url(images/Crests.png);
background-size:26%;
background-position:top 6px;
height:100%;
}
#NavBar{
Height:26%;
Border:groove Gold 6px;
}
#Body{
Height:76%;
border:groove Gold 6px;
text-align:center;
}
#Footer{
Height:26%;
background:#999;
Border:groove gold 6px;
}
</style>
</head>
<body>
<!-- This is the php to setup the connection to the oracle database needed to record information and to display reciept -->
<?php
/* Set oracle user login and password info */
$dbuser = "jrhaywar"; /* your deakin login */
$dbpass = "haybreaker"; /* your oracle access password */
$db = "SSID";
$connect = OCILogon($dbuser, $dbpass, $db);
if (!$connect) {
echo "An error occurred connecting to the database";
exit;
}
/* build sql statement using form data */
$query = "SELECT * FROM sit104Items";
if(isset($_POST['Submit'])){
$name = $POST_['Name'];
$phone = $POST_['Phone'];
$email = $POST_['Email'];
$reason = $POST_['Reason'];
$message = $POST_['Message'];
$insert = $insert = "INSERT INTO ContactUs VALUES ('$name','$phone','$email','$reason','$message')";
$Insert = OCIParse($connect, $insert);
}
/* check the sql statement for errors and if errors report them */
$stmt = OCIParse($connect, $query);
//echo "SQL: $query<br>";
if(!$stmt) {
echo "An error occurred in parsing the sql string.\n";
exit;
}
OCIExecute($stmt);
?>
<!--This is the beggining of the code that will be shown in the browser Starting with the wrapper and Navigation bar and then continuing with the "body" division and ended by the footer-->
<div id="Wrapper">
<div id="NavBar">
<table style="width:100%" height="10%" bgcolor="#CCFF00">
<tr>
<td width="26%" align="center" ><a link href="ass1.htm"><b>Home Page</b></a></td>
<td width="26%" align="center"><a link href="Items.php"><b>Items</b></a></td>
<td width="26%" align="center" ><a link href="FAQ.html"><b>FAQ/HELP</b></a></td>
<td width="26%" align="center" ><a link href="Contact.html"><b>Contact Us</b></a></td>
</tr>
</table>
</div>
<div id="Body">
<font size="6" face="Serpentine Bold" color="lime" ><b>
Welcome to the Order Page, please order what you wish!</b>
<hr/>
</font>
<?php
while(OCIFetch($stmt)){
/*Calculate what to do and show if Post is found*/
if(isset($_POST['Submit'])){
echo('<table align="center" bgcolor="#00FF66" border="4" bordercolor="black" width="100%">
<tr>
<td colspan="4" bgcolor="#00FFCC"><b>Personal and Delivery Details</b></td>
</tr>
<tr>
<td width="6%" >Name:</td>
<td width="46%" >');
$fg1 = OCIResult($stmt, "NAME");
echo $fg1;
echo('</td>
<td width="6%" >Phone Number:</td>
<td width="46%" >');
$fg2 = OCIResult($stmt, "PHONE");
echo $fg2;
echo('</td>
</tr>
<tr>
<td width="10%">E-mail</td>
<td width="80%" colspan="3">');
$fg3 = OCIResult($stmt, "EMAIL");
echo $fg3;
echo('</td>
</tr>
</table>
<hr/>
<table align="center" bgcolor="#00FF66" border="4" bordercolor="black" width="100%">
<tr>
<td colspan="2" bgcolor="#00FFCC" ><b>Message</b></td>
</tr>
<tr>
<td width="10%">Reason for message:</td>
<td width="90%">');
$fg4 = OCIResult($stmt, "REASON");
echo $fg4;
echo('</tr>
<tr>
<td width="10%">Type Message Here: </td>
<td width="90%">
');
$fg5 = OCIResult($stmt, "MESSAGE");
echo $fg5;
echo('</td>
</tr>
</table>');
} /*End of the First If. So now compute what to do if post isn't used */
else
{
echo('
<form name="ContactForm" onSubmit="Contact.php" >
<table align="center" bgcolor="#00FF66" border="4" bordercolor="black" width="100%">
<tr>
<td colspan="4" bgcolor="#00FFCC"><b>Personal and Delivery Details</b></td>
</tr>
<tr>
<td width="6%" >Name:</td>
<td width="46%" ><input Type="text" name="Name" style="width:86%"/></td>
<td width="6%" >Phone Number:</td>
<td width="46%" ><input type="text" Name="Phone" style="width:86%"/></td>
</tr>
<tr>
<td width="10%">E-mail</td>
<td width="80%" colspan="3"><input type="text" name="Email" style="width:30%" /></td>
</tr>
</table>
<hr/>
<table align="center" bgcolor="#00FF66" border="4" bordercolor="black" width="100%">
<tr>
<td colspan="2" bgcolor="#00FFCC" ><b>Message</b></td>
</tr>
<tr>
<td width="10%">Reason for message:</td>
<td width="90%"><select name="Reason">
<option value="General Enquiry" >General Enquiry</option>
<option value="Returning Item" >Returning Item</option>
<option value="Missing Item" >Missing Item</option>
<option value="Price Negotiation">Price Negotiation</option>
</select>
</tr>
<tr>
<td width="10%">Type Message Here: </td>
<td width="90%"><textarea name="Message" rows="5" style="width:90%;height:100%;"></textarea> </td>
</tr>
</table>
<input type="submit" value="Send Message" style="width:95%; height:35px; margin-top:10px; background- color:#0F0"/>
</form>
');}
}
OCILogOff($connect);
?>
<br/>
</div>
<div id="Footer">
Links:<br/>
Home<br/>
Items<br/>
Order Form<br/>
faq/help<br/>
Contact Us<hr/>
<p align="left">
©Deakin University, School of Information Technology. This web page has been developed as a student assignment for the unit SIT104: Introduction to Web Development. Therefore it is not part of the University's authorised web site. DO NOT USE THE INFORMATION CONTAINED ON THIS WEB PAGE IN ANY WAY
</p>
</div>
</div>
</body>
</html>
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.
This is my code; I will tell you the issue then.
<?php
//checking for perfect loging
session_start();
$user_name = $_SESSION['username'];
$user_pass = $_SESSION['password'];
require ("connection.php");
if ( $user_name == '' ) {
header('location:home.php');
exit();
}
/////////////////////////////////////
?>
<?php
//collecting posted variables by pressing addanother button
if(isset($_POST['adnother'])) {
$date = $_POST['date'];
$billnmbr = $_POST['billnmbr'];
$itemcode = $_POST['itemcode'];
$itemname = $_POST['itemname'];
$exdate = $_POST['exdate'];
$eachprice = $_POST['eachprice'];
$itmtotal = $_POST['itmtotal'];
$wasFound=false;
$i=0;
// check for >>>>>>>>>>> if the session bill_array array is not set or cart array is empty <<<<<<<<<<<<<<<
if(!isset($_SESSION["bill_array"]) || count($_SESSION["bill_array"]) < 1 ) {
// Run if the bill_array is empty or not set
$_SESSION["bill_array"]= array(1 => array("date"=> $date, "billnmbr"=> $billnmbr, "itemcode"=> $itemcode, "itemname"=> $itemname, "exdate"=> $exdate, "eachprice"=> $eachprice, "itmtotal"=> $itmtotal));
} else {
// Run if the bill has at least one item in it
foreach($_SESSION["bill_array"] as $each_item) {
$i++;
while(list($key,$value)=each($each_item)){
if($key=="itemcode" && $value == $itemcode){
// That item is in cart already so push a error message in to screen
$wasFound = true;
?>
<script type="text/javascript">
var error = "<?= $wasFound ?>";
if(error == "true") {
alert("You trying to add same item twice")
}
</script>
<?php
}//close if condition
}//close while loop
}//close foreach loop
//if the next item is not in the bill and then add it to the bill_array
if($wasFound==false){
array_push($_SESSION["bill_array"],array("date"=> $date, "billnmbr"=> $billnmbr, "itemcode"=> $itemcode, "itemname"=> $itemname, "exdate"=> $exdate, "eachprice"=> $eachprice, "itmtotal"=> $itmtotal));
}//clos if condition
}//close else statment
}//close ifisset
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Front-end Billing</title>
<link href="main.css" rel="stylesheet" type="text/css" media="all" />
<style type="text/css">
.mainheder {
font-size: 36px;
font-weight: bolder;
color: #00C;
text-align: center;
}
#headertopic {
position:absolute;
left:304px;
top:1px;
width:395px;
height:44px;
z-index:1;
background-color: #999900;
}
#mainmenue {
position:absolute;
left:208px;
top:78px;
width:614px;
height:48px;
z-index:10000;
}
#dateandtime {
position:absolute;
left:790px;
top:251px;
width:208px;
height:82px;
z-index:1;
}
#redcross {
position:absolute;
left:377px;
top:321px;
width:247px;
height:239px;
z-index:0;
}
#usrlogin {
position:absolute;
left:4px;
top:216px;
width:265px;
height:184px;
z-index:1;
}
#address {
position:absolute;
left:2px;
top:462px;
width:204px;
height:155px;
z-index:2;
}
#logdas {
position:absolute;
left:10px;
top:92px;
width:197px;
height:58px;
z-index:1;
}
.logdas {
font-weight: bold;
color: #00F;
}
#pagetheam {
position:absolute;
left:332px;
top:49px;
width:341px;
height:24px;
z-index:1;
text-align: center;
font-size: 18px;
font-weight: bolder;
color: #0CF;
text-decoration: underline;
}
#billingitems {
position:absolute;
left:11px;
top:186px;
width:489px;
height:293px;
z-index:1;
}
#printlayout {
position:absolute;
left:531px;
top:186px;
width:211px;
height:322px;
z-index:1;
text-align: center;
}
.printlayoutshopname {
font-size: 14px;
font-weight: bold;
color: #000;
}
.billaddrs {
font-size: 10px;
}
.bilnmbr {
font-size: 10px;
font-weight: bold;
text-align: left;
}
</style></head>
<body>
<div id="wrap">
<div id="headertopic" class="mainheder">Accoutnig for Phamacy</div>
<p> </p>
<p> </p>
<div id="mainmenue"> <?php // include 'index.html' ;?> </div>
<div id="logdas"><p class="logdas">Logged in as : <?php echo $user_name; ?></p>
<p class="logdas">Date : <?php echo date("Y-m-d") ?></p>
</div>
<div id="pagetheam">Front-end Billing </div>
<div id="billingitems">
<form id="form1" name="form1" method="post" action="biling.php">
<?php $data = mysql_query("SELECT * FROM billnumber ") ;
$info = mysql_fetch_array( $data );
$oldnumber = $info['bill_number'];
$oldnumber= $oldnumber + 1;
$Transaction_number = "PM". $oldnumber ;
?>
<table width="490" height="282" border="0">
<tr>
<td width="160"><input type="hidden" name="date" id="date" value=" <?php echo date("Y-m-d") ?> " /><?php echo date("Y-m-d") ?></td>
<td width="47"> </td>
<td width="69"> </td>
</tr>
<tr>
<td width="206">Bill Number</td>
<td width="160"><input type="hidden" name="billnmbr" id="billnmbr" value="<?php echo $Transaction_number; ?>" /><?php echo $Transaction_number; ?></td>
<td width="47"> </td>
<td width="69"> </td>
</tr>
<tr>
<td>Item Code</td>
<td><input type="text" name="itemcode" id="itemcode" tabindex="1" /></td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Item Name</td>
<td><input type="text" name="itemname" id="itemname" tabindex="2" /></td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Expier Date</td>
<td><input type="text" name="exdate" id="exdate" /></td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Item Price</td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>Each :
<input type="text" name="eachprice" id="eachprice" /></td>
<td>Total :
<input type="text" name="itmtotal" id="itmtotal" /></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="adnother" id="adnother" value="add another item" tabindex="5" /></td>
<td><input type="submit" name="submit" id="submit" value="Submit" /></td>
<td> </td>
</tr>
</table>
</form>
</div>
<div id="printlayout">
<p><span class="printlayoutshopname">Yasitha Pharacy<br />
</span><span class="billaddrs">22,Colombathanthiri Mawatha, Ethulkotte, Kotte.</span></p>
<table width="211" border="0">
<tr>
<td width="103"><span class="bilnmbr">Bill No: <?php echo $Transaction_number; ?></span></td>
<td colspan="2" class="bilnmbr">Date: <?php echo date("Y-m-d") ?></td>
</tr>
<?php
if(isset($_POST['adnother'])) {
//taking items in the bill to variables if the bill_array is not empty.
$cartOutput="";
if(!isset($_SESSION["bill_array"]) || count($_SESSION["bill_array"]) < 1 ) {
$cartOutput = "<h2 align='center'> Bill is still empty </hd>";
}
else {
$i = 0;
foreach ($_SESSION["bill_array"]as $each_item ): ?>
<tr>
<td class="bilnmbr">Item code: </td>
<td colspan="2" class="bilnmbr"><?php echo $each_item['itemcode']; ?></td>
</tr>
<tr>
<td colspan="3" class="bilnmbr">Item Name:</td>
</tr>
<tr>
<td colspan="3" class="bilnmbr"><?php echo $each_item['itemname']; ?></td>
</tr>
<tr class="bilnmbr">
<td>Each</td>
<td width="98">Qty</td>
<td width="98">Total</td>
</tr>
<tr class="bilnmbr">
<td><?php echo $each_item['eachprice']; ?></td>
<td>20</td>
<td><?php echo $each_item['itmtotal']; ?></td>
</tr>
</table>
<?php endforeach; ?>
<?php
}
}
////////////////////////////////////////
?>
<p>
</p>
</div>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<?php //closing div for wrapper?>
</div>
</body>
</html>
I used two dimensional array for insert item details to a session array, after inserting a item I want its details to be displayed in a separate table (right hand side) there is no problem with one item, when I add a item it is viewing in the perfect place, but when I add the second item it is going under that table without creating new row. What is the wrong with what I had done?
I found my error
i ended my foreach loop like this
</tr>
</table>
<?php endforeach;
}
}
////////////////////////////////////////
?>
but now i corrected to this way
</tr>
<?php endforeach;
}
}
////////////////////////////////////////
?>
</table>
now it's all ok.... thank you guys for wasting your time for my silly mistake... sorry.... :(