Update data, but want the data in sql view and change it - php

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

Related

Update specific column in loop

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.

Error reading from database in a web form

I'm trying to pull data from the database which matches data from the text box and the code I am using throws an error.
I think there is something wrong with my SQL query, but I'm not sure what.
The error is:
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\search.php on line 65
My syntax:
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css"></link>
</head>
<body>
<form action="" name="formdownload" method="post">
<table>
<tr><td colspan=2><h1>Domestic Flights</h1></td></tr></br>
<td height=50> From:</td><td><input type="From" name="from" size=30/>
<tr><td height=50>To: </td><td><input type="To" name="to" size=30/>
<tr><td><input name="submit" type="submit" value ="Search"></tr></td>
<table border="1" align="center" id="table1" cellpadding="0" cellspacing="0">
<tr>
<th>Flight No</th>
<th>Flight Company</th>
<th>Plane Type</th>
<th>From</th>
<th>To</th>
</tr>
<center>
<?php
$submit = #$_POST['submit'];
$from = #$_POST['from'];
$to = #$_POST['to'];
if($submit)
{
$select=mysql_query("select * from flight where ffrom='$from'and To='$to'");
while($row1=mysql_fetch_array($select))
{
$FlightNo = $row1['FlightNo'];
$FlightCompany=$row1['FlightCompany'];
$PlaneType = $row1['PlaneType'];
$From =$row1['ffrom'];
$To =$row1['To'];
?>
<tr>
<td width="90" align="center">
<?php echo $FlightNo;?>
</td>
<td width="90" align="center">
<?php echo $FlightCompany;?>
</td>
<td width="90" align="center">
<?php echo $PlaneType;?>
</td>
<td width="90" align="center">
<?php echo $From;?>
</td>
<td width="90" align="center">
<?php echo $To;?>
</td>
</tr>
<?php }}?>
</table>
</table>
</form>
</div>
</div>
</div>
</div>
</center>
</body>
</html>
You have an error at the line on the variable name :
$select=mysql_query("select * from logintbl where name='$uname'");
Replace it with :
$select=mysql_query("select * from logintbl where name='$name'");
EDIT : since your field is named 'uname' in your database, here is the correct code (a little bit more secure with the addition of mysql_real_escape) :
$select=mysql_query('select * from logintbl where uname="'.mysql_real_escape($name).'";');
REEDIT : you want a second parameter but didn't retrieve it in PHP before your query. Your code should be like this then :
<html>
<body>
<form enctype="multipart/form-data" action="" name="formdownload" method="post">
<table border="1" align="center" id="table1" cellpadding="0" cellspacing="0">
<tr>
<th>ID</th>
<th>Name</th>
<th>Password</th>
<th>User Type</th>
</tr>
<center>
<br/><br/><br/>
ID: <input type="text" name="idno" /> <br/><br/>
Name : <input type="text" name="name" /><br/><br/>
Marks : <input type="text" name="marks" /><br/><br/>
<input type="submit" name = "submit" value="submit">
</center>
<?php
$submit = #$_POST['submit'];
$name = #$_POST['name'];
$idno = #$_POST['idno'];
if($submit)
{
$select=mysql_query("select * from logintbl where uname='$name' and Id='$idno'");
while($row1=mysql_fetch_array($select))
{
$id = $row1['ID'];
$name=$row1['uname'];
$pass = $row1['pass'];
$type =$row1['type'];
?>
<tr>
<td width="300" align="center">
<?php echo $id;?>
</td>
<td width="300" align="center">
<?php echo $name;?>
</td>
<td width="300" align="center">
<?php echo $pass;?>
</td>
<td width="300" align="center">
<?php echo $type;?>
</td>
</tr>
<?php }}?>
</table>
</form>
</body>
I still strongly advise you to filter your variables before making a query with it with mysql_real_escape.

Login page not redirect to another page using header function

Good Day PHP wizards,
I would like to ask help from all of you. It seems my Log-in button does not direct to Home (Student_Home.php). Student ID and password has been registered to database already.
*Here is the script for Student_login.php*
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Login Page</title>
<link rel="stylesheet" href="Style.css" type="text/css"/>
<script type="text/javascript">
function validate()
{
if(document.form1.student_id.value=="")
{
alert("Please enter your login Id.");
document.form1.student_id.focus();
return false;
}
if(document.form1.student_password.value=="")
{
alert("Please enter your password.");
document.form1.student_password.focus();
return false;
}
}
</script>
<style type="text/css">
<!--
body {
background-color: #0099FF;
}
-->
</style></head>
<body onLoad="javascript:document.form1.student_id.focus()">
<form name="form1" method="post" action="Student_login_handler.php" onSubmit="return validate();">
<table width="100%" height="100%" >
<tr>
<td height="15%"><?php include 'Header.php';?></td>
</tr>
<tr>
<td width="100%" height="80%" align="center" valign="baseline"><table width="90%" >
<tr>
<td width="8%">Home</td>
<td width="35%" align="center"> </td>
<td width="27%"> </td>
<td width="30%" align="right">New Student Click Here</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<?php if(!empty($_GET['flag']) && $_GET['flag'] == "success") { ?>
<tr>
<td class="stylegreen" colspan="4" align="center">Congratulations! You Are successfully registered. You can use your Login Id and Password to login to your account.</td>
</tr>
<?php
}
else if(!empty($_GET['flag']) && $_GET['flag'] == "exists") { ?>
<tr>
<td class="stylered" colspan="4" align="center">This Login Id( <?=$_GET['student_id']?>) already exists.Please, try again with another Login Id</td>
</tr>
<?php
}else if(!empty($_GET['flag']) && $_GET['flag'] == "error") {
?>
<tr>
<td class="stylered" colspan="4" align="center">Error while inserting data. Please, try again.</td>
</tr>
<?php
}
?>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan="4"><table width="30%" border="1" align="center" cellpadding="3" cellspacing="0" bordercolor="#CCCCCC" bgcolor="#CCCCCC">
<tr align="center" bgcolor="#999999">
<td colspan="2" bgcolor="#99CC33" class="stylebig">Student Login Here</td>
</tr>
<tr bgcolor="#E1E1E1" class="stylesmall">
<td width="35%" align="left" class="style7">Login Id : </td>
<td width="65%" align="left"><input name="student_id" type="text" id="student_id"></td>
</tr>
<tr bgcolor="#E1E1E1" class="stylesmall">
<td align="left" class="style7">Password:</td>
<td align="left"><input name="student_password" type="password" id="student_password"></td>
</tr>
<tr bgcolor="#E1E1E1">
<td colspan="2" align="center">
<?php if(!empty($_GET['flag']) && $_GET['flag'] == "invalid") { ?>
<span class="stylered">Invalid Login Id or Password</span>
<?php }?> </td>
</tr>
<tr bgcolor="#E1E1E1">
<td colspan="2" align="center"><input name="login" class="style10" type="submit" id="login" value="Login">
<input name="close" type="button" id="close" class="style10" value="Close" onClick="self.location='index.php'"> </td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
<tr>
<td height="5%" align="center"><?php include 'Footer.php';?></td>
</tr>
</table>
</form>
</body>
</html>
*and here is also the Student_login_handler codes*
<?php
session_start();
include 'Connect.php';
$flag = "";
$student_id = $_POST['student_id'];
$student_password = $_POST['student_password'];
$query = "select last_login_date from student_information where student_id='$student_id' and student_password='$student_password' and student_status ='Enable'";
$result = mysql_query($query,$link_id);
if(mysql_error() != null){
die(mysql_error());
}
if($date = mysql_fetch_array($result))
{
$lastdate = $date['last_login_date'];
$date2 = date("d-m-Y h:i A",strtotime($lastdate));
$_SESSION['student_id'] = $_POST['student_id'];
$_SESSION['lastlogin'] =$date2;
$_SESSION['type'] = "Student";
mysql_query("update student_information set last_login_date=now() where student_id='$student_id'",$link_id);
if(mysql_error() != null){
die(mysql_error());
}
header("location:Student_Home.php");
die();
}
else
{
$flag = "invalid";
header("location:Student_login.php?flag=$flag");
die();
}
?>
***It keeps saying "Invalid ID or password"
Hope you can help me troubleshoot this..
I already got this problem, probably header() function not work. Anywhere following are two solution to solve this problem,
Solution 1
Using PHP you can just add ob_start(); function on first line of your starting php.
<?php
ob_start();
.....
.....
Solution 2
Using JavaScript to redirect Student_Home.php
<script type="text/javascript">
window.navigate("http://www.url.com/Student_Home.php");
</script>
another JavaScript function
<script type="text/javascript">
window.location="http://www.url.com/Student_Home.php";
</script>
Hope this help you!

I am trying to make a Edit form Using PHP

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.

date format is not seperated when fetching from database

i have a table named as item_request and it has twofields named as projectmanager and createddate which has the Timestamp format as 2012-09-11 17:46:25.
Now i want to call these two fields in another form which count the user entry between 2 different dates.and the date field is fetched from the timestamp.with this form i m sending the value through datetime picker having the format 10-12-2012 but the value in databse is in different format and the value i m sending is in diffferent format.how is it possible plzzz help me guys.
Here is the code for my form:
<?php
include("config.php");
ob_start();
error_reporting(0);
if(!isset($_SESSION[username]))
header("location: index.php");
if(isset($_POST[submit]))
{
$projectmanager=mysql_real_escape_string($_POST['projectmanager']);
$date=mysql_real_escape_string($_POST['date']);
$dateexp = explode("-",$date);
$date = mysql_real_escape_string($dateexp[0]."/".$dateexp[1]."/".$dateexp[2]);
$date1=mysql_real_escape_string($_POST['date1']);
$dateexp1 = explode("-",$date1);
$date1 = mysql_real_escape_string($dateexp1[0]."/".$dateexp1[1]."/".$dateexp1[2]);
echo $queryuser= "select * from item_request where projectmanager=$projectmanager AND (requireddate>=$date AND requireddate<=$date1)";
}
?>
<!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>Project Managers Registrarion</title>
<link rel="stylesheet" type="text/css" href="css/style.css"/>
<script language="javascript" type="text/javascript" src="js/datetimepicker.js">
//Date Time Picker script- by TengYong Ng of http://www.rainforestnet.com
//Script featured on JavaScript Kit (http://www.javascriptkit.com)
//For this script, visit http://www.javascriptkit.com
</script>
</head>
<body>
<div class="container">
<div class="header"><img src="images/cherry-new.jpg" width="79" height="93" />
<!-- end .header --></div>
<?php include("rightMenu.php");?>
<div class="content">
<h1>PR Count</h1>
<div style="padding:10px 0px; text-align:center; color:#990000;">
</div>
<form action="" method="post" name="loginform">
<table width="100%" border="0" cellspacing="2" cellpadding="2">
<tr>
<td>Project Managers</td>
<td><select name="projectmanager" style="width:145px;" id="projectmanager" onChange="showUser(this.options[this.selectedIndex].id)">
<option value="">Select</option>
<?php $queryuser= "select * from projectmanagers";
$fetuser1user = mysql_query($queryuser);
while($fetuser = mysql_fetch_array($fetuser1user)){
?>
<option id="<?php echo $fetuser['id']?>" value="<?php echo $fetuser['id']?>"><?php echo $fetuser['projectmanager']?></option>
<?php }
?>
</select></td>
</tr>
<tr>
<td>Date From</td>
<td>
<input id="date" type="text" size="20" name="date" /><img src="images/cal.gif" width="16" height="16" border="0" alt="Pick a date"></td>
</tr>
<tr>
<td>Date To</td>
<td>
<input id="date1" type="text" size="20" name="date1"><img src="images/cal.gif" width="16" height="16" border="0" alt="Pick a date"></td>
</tr>
<tr>
<td> </td>
<td>
<input type="submit" name="submit" id="submit" value="Submit" onClick="return formvalidate();"/>
</td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</table>
<table width="100%" border="1"><tr>
<td width="18%" valign="middle" class="tableheading">PI.No.</td>
<td width="18%" valign="middle" class="tableheading">Project Manager</td>
<td width="18%" valign="middle" class="tableheading">Date Created</td>
<td width="15%" valign="middle" class="tableheading">Action</td>
</tr>
<?php
// to print the records
$select = "select * from item_request";
$query1 = mysql_query($select);
while($value = mysql_fetch_array($query1)){ ?>
<tr>
<td class="tabletext"><?php echo $value[id];?></td>
<td class="tabletext"><?php echo $value[projectmanager];?></td>
<td class="tabletext"><?php echo $value[datefrom];?></td>
<td class="tabletext"><img src="images/edit.png" width="25" height="25" border="0" title="Edit" />
<img src="images/deleteBtn.png" width="25" height="25" border="0" title="Edit" /></td>
</tr><?php }?>
</table>
</form>
<!-- end .content --></div>
<?php include("footer.php");?>
<!-- end .container --></div>
</body>
</html>
Replace this function call...
javascript:NewCal('date','ddmmyyyy');
with this one...
javascript:NewCal('date','ddmmyyyy',true,24);
Hope it helps.

Categories