I am working on my PHP code (insert_post.php) and I have two errors:
**Warning: move_uploaded_file(news_images/RaiderX.jpg): failed to open stream: No such file or directory in C:\xampp\htdocs\my_cms\admin\insert_post.php on line 106
Warning: move_uploaded_file(): Unable to move 'C:\xampp\tmp\php60F7.tmp' to 'news_images/RaiderX.jpg' in C:\xampp\htdocs\my_cms\admin\insert_post.php on line 106**
Everything is fine and I can see that data (images) is coming through to my mysql database but I cannot understand why there are these two errors.
This is the code:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<style type="text/css">
td, td {
padding:0px;
margin:0px;
}
</style>
<script src="//tinymce.cachefly.net/4.1/tinymce.min.js"></script>
<script>tinymce.init({selector:'textarea'});</script>
</head>
<body>
<form action="insert_post.php" method="post" enctype="multipart/form-data">
<table width="800" align="center" border="2">
<tr bgcolor="#F47302">
<td colspan="6" align="center"><h1>Insert New Post</h1></td>
</tr>
<tr>
<td align="right" bgcolor="F47302"><strong>Post Title:</strong></td>
<td><input type="text" name="post_title" size="40"</td>
</tr>
<tr>
<td align="right"bgcolor="F47302" ><strong>Post Categories:</strong></td>
<td>
<select name="cat">
<option value="null">Select a Category</option>
<?php
include("../includes/database.php");
$get_cats = "select * from categories";
$run_cats = mysqli_query($con, $get_cats);
while ($cats_row=mysqli_fetch_array($run_cats)) {
$cat_id=$cats_row['cat_id'];
$cat_title=$cats_row['cat_title'];
echo "<option value='$cat_id'>$cat_title</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td align="right" bgcolor="F47302"><strong>Post Author:</strong></td>
<td><input type="text" name="post_author" size="40"</td>
</tr>
<tr>
<td align="right" bgcolor="F47302"><strong>Post Keywords:</strong></td>
<td><input type="text" name="post_keywords" size="50"</td>
</tr>
<tr>
<td align="right" bgcolor="F47302"><strong>Post Image:</strong></td>
<td><input type="file" name="post_image" size="50"</td>
</tr>
<tr>
<td align="right" bgcolor="F47302"><strong>Post Content:</strong></td>
<td><textarea name="post_content" rows="15" cols="60"></textarea></td>
</tr>
<tr>
<td colspan="6" align="center" bgcolor="F47302"><input type="submit" name="submit" value="Publish Now"</td>
</tr>
</table>
</form>
</body>
</html>
<?php
if(isset($_POST['submit'])) {
$post_title = $_POST['post_title'];
$post_date = date('m-d-y');
$post_cat = $_POST['cat'];
$post_author = $_POST['post_author'];
$post_keywords = $_POST['post_keywords'];
$post_image = $_FILES['post_image'] ['name'];
$post_image_tmp = $_FILES['post_image']['tmp_name'];
$post_content = $_POST['post_content'];
if($post_title=='' OR $post_cat=='null' OR $post_author=='' OR $post_keywords=='' OR $post_image=='' OR $post_content==''){
echo "<script>alert('Please fill in all the fileds')</script>";
exit();
}
else {
move_uploaded_file($post_image_tmp,"news_images/$post_image");
$insert_posts = "insert into posts (category_id,post_title,post_date,post_author,post_keywords,post_image,post_content) values ('$post_cat','$post_title','$post_date','$post_author','$post_keywords','$post_image','$post_content')";
$run_posts = mysqli_query($con,$insert_posts);
echo "<script>alert('Post Has been Published!')</script>";
echo "<script>window.open('index.php?insert_post','_self')</script>";
}
}
?>
check
$_FILES["post_image"]["error"]
for any sort of upload error first, this may give you a better idea of why this is happening and also catch the problem so you don't cache the info of a missing file in your DB
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.
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>
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
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!