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.
Related
I have search feature that I setup. When I type the keyword in I get no records back and no error message. Just the table header. I see the department other in the database. When I type it in the keyword box I get nothing back.
<html>
<head>
<title></title>
</head>
<body>
<form name="frmSearch" method="get" action="">
<table width="599" border="1">
<tr>
<th>Keyword
<input name="txtKeyword" type="text" id="txtKeyword" value="<?php echo $_GET["txtKeyword"];?>">
<input type="submit" value="Search"></th>
</tr>
</table>
</form>
<?php
if($_GET["txtKeyword"] != "")
{
$serverName = "localhost";
$objConnect = new PDO( "sqlsrv:server=$serverName ; Database=maintenance", "TestUser", "test") or die("Error Connect to Database");
// Search By lanId or department
$objQuery = $objConnect->prepare("SELECT * FROM requests WHERE (lanId LIKE '%".$_GET["txtKeyword"]."%' or department LIKE '%".$_GET["txtKeyword"]."%' ) ");
?>
<table width="600" border="1">
<tr>
<th width="91"> <div align="center">lanId </div></th>
<th width="98"> <div align="center">Name </div></th>
<th width="198"> <div align="center">department </div></th>
</tr>
<?php
while( $objResult = $objQuery->fetch(PDO::FETCH_ASSOC))
{
?>
<tr>
<td><div align="center"><?php echo $objResult["lanId"];?></div></td>
<td><?php echo $objResult["name"];?></td>
<td><?php echo $objResult["department"];?></td>
<?php
}
?>
</table>
<?php
}
?>
</body>
</html>
When you use prepare() statement you should also use execute() :
http://coursesweb.net/php-mysql/pdo-prepare-execute
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
So, I'm adding a forum section to my site. So far, everyone thing is good. You can create a topic, view a list of topics, but when you go to view a topic (which is view_topic.php?id=#) this keeps appearing:
Parse error: syntax error, unexpected $end in /home/papervip/public_html/forums/questions/view_topic.php on line 158
So, here's the full script of view_topic.php (without the database credentials included, so I can ensure my security :D ):
<?php
session_start();
$host="localhost"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name=""; // Database name
$tbl_name="forum_questions"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// get value of id that sent from address bar
$id=$_GET['id'];
$sql="SELECT * FROM $tbl_name WHERE id='$id'";
$result=mysql_query($sql);
$rows=mysql_fetch_array($result);
?>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="../../style/base.css">
<title>Paperviper - Questions - View Topic</title>
<meta name="keywords" content="games, free, indie, paperviper, pc, video games">
<meta name="description" content="Paperviper is a game developer group consisten of a team of indie-developers and freelancers. Working to bring you the best cheap and free games for addicting fun on your PC, Mac, and Linux!">
<style type="text/css">
</head>
<body>
<?php if(empty($_SESSION['user'])){
include("../../header.html");
}else{
include("../../user/user_header.html");
?>
<div id="page">
<table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td><table width="100%" border="0" cellpadding="3" cellspacing="1" bordercolor="1" bgcolor="#FFFFFF">
<tr>
<td bgcolor="#F8F7F1"><strong><? echo $rows['topic']; ?></strong></td>
</tr>
<tr>
<td bgcolor="#F8F7F1"><? echo $rows['detail']; ?></td>
</tr>
<tr>
<td bgcolor="#F8F7F1"><strong>By :</strong> <? echo $rows['name']; ?> <strong>Email : </strong><? echo $rows['email'];?></td>
</tr>
<tr>
<td bgcolor="#F8F7F1"><strong>Date/time : </strong><? echo $rows['datetime']; ?></td>
</tr>
</table></td>
</tr>
</table>
<BR>
<?php
$tbl_name2="forum_questions_answer";
$sql2="SELECT * FROM $tbl_name2 WHERE question_id='$id'";
$result2=mysql_query($sql2);
while($rows=mysql_fetch_array($result2)){
?>
<table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td><table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td bgcolor="#F8F7F1"><strong>ID</strong></td>
<td bgcolor="#F8F7F1">:</td>
<td bgcolor="#F8F7F1"><? echo $rows['a_id']; ?></td>
</tr>
<tr>
<td width="18%" bgcolor="#F8F7F1"><strong>Name</strong></td>
<td width="5%" bgcolor="#F8F7F1">:</td>
<td width="77%" bgcolor="#F8F7F1"><? echo $rows['a_name']; ?></td>
</tr>
<tr>
<td bgcolor="#F8F7F1"><strong>Email</strong></td>
<td bgcolor="#F8F7F1">:</td>
<td bgcolor="#F8F7F1"><? echo $rows['a_email']; ?></td>
</tr>
<tr>
<td bgcolor="#F8F7F1"><strong>Reply</strong></td>
<td bgcolor="#F8F7F1">:</td>
<td bgcolor="#F8F7F1"><? echo $rows['a_answer']; ?></td>
</tr>
<tr>
<td bgcolor="#F8F7F1"><strong>Date/Time</strong></td>
<td bgcolor="#F8F7F1">:</td>
<td bgcolor="#F8F7F1"><? echo $rows['a_datetime']; ?></td>
</tr>
</table></td>
</tr>
</table><br>
<?php
}
$sql3="SELECT view FROM $tbl_name WHERE id='$id'";
$result3=mysql_query($sql3);
$rows=mysql_fetch_array($result3);
$view=$rows['view'];
/
if(empty($view)){
$view=1;
$sql4="INSERT INTO $tbl_name(view) VALUES('$view') WHERE id='$id'";
$result4=mysql_query($sql4);
}
$addview=$view+1;
$sql5="update $tbl_name set view='$addview' WHERE id='$id'";
$result5=mysql_query($sql5);
mysql_close();
?>
<BR>
<table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form name="form1" method="post" action="add_answer.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td width="18%"><strong>Name</strong></td>
<td width="3%">:</td>
<td width="79%"><input name="a_name" type="text" id="a_name" size="45" value="<?php echo htmlentities($_SESSION['user']['username'], ENT_QUOTES, 'UTF-8'); ?>" readonly></td>
</tr>
<tr>
<td><strong>Email</strong></td>
<td>:</td>
<td><input name="a_email" type="text" id="a_email" size="45" value="<?php echo htmlentities($_SESSION['user']['email'], ENT_QUOTES, 'UTF-8'); ?>" readonly></td>
</tr>
<tr>
<td valign="top"><strong>Reply</strong></td>
<td valign="top">:</td>
<td><textarea name="a_answer" cols="38" rows="10" id="a_answer"></textarea></td>
</tr>
<tr>
<td> </td>
<td><input name="id" type="hidden" value="<? echo $id; ?>"></td>
<td><input type="submit" name="Submit" value="Submit" class="button"> <input type="reset" name="Submit2" value="Reset" class="button"></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
<?php include("../../footer.html");?>
</div>
</body>
</html>
I've re-read the entire file about 10 times now, but it still keeps stating the final closing html tag as a unexpected $end. Am I overlooking something? Thanks in advance.
I believe you have an unmatched { here:
<body>
<?php if(empty($_SESSION['user'])){
include("../../header.html");
}else{
include("../../user/user_header.html");
} // It looks like this is missing
?>