A few months ago I was working on a project and posted it here for help: How to submit a form results to a table on another page?. Now I need help again. If you go down to this comment on my previous question (see comment here: How to submit a form results to a table on another page?), this user was helping me and I got everything figured out except the the database. When I submit my form, the page loads with a blank table. How can I get it so when I enter the form information and submit it, it then goes to the 2nd page (see below) and puts the data into the table? I had it working before, before I incorporated the database in it.
Here is my code for the page called dispatch.php (which is the the form page):
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>LMCS CAD - Live Incident Status</title>
<link href="styles.css" rel="stylesheet" type="text/css" />
<link rel="shortcut icon" href="http://tabstart.com/system/icons/14476/original/favicon.ico?1306467370" />
<meta name="robots" content="noindex">
</head>
<body style="font-family: Arial, Sans-Serif; font-size: 12px;">
<div align="center">
<h1><img src="assests/lmcslogo.png" alt="York County 911 - Live Incident Status"/></h1>
<p>
<script type="text/javascript">
document.write(Date());
</script></p>
<h1>Home | Dispatch An Incident | Help</h1>
<div></div>
</div>
<div align="center">
<form id="dispatch" name="dispatch" method="post" action="indexcad.php">
<table width="801" height="420" border="1">
<tr>
<td align="center" id="town">TOWN</td>
<td><input type="text" name="town" id="town" /></td>
</tr>
<tr>
<td align="center" id="location">LOCATION</td>
<td><input type="text" name="location" id="location" /></td>
</tr>
<tr>
<td align="center" id="incident_type">INCIDENT TYPE</td>
<td><input type="text" name="incident_type" id="incident_type" /></td>
</tr>
<tr>
<td align="center" id="time_date">TIME/DATE</td>
<td><input name="time_date" type="text" id="time_date" maxlength="60" /></td>
</tr>
<tr>
<td width="138" align="center"><p id="admin">ADMIN </p></td>
<td width="228"><input name="admin" type="text" id="admin" size="4" maxlength="4" /></td>
</tr>
</table>
<p>
<input type="submit" name="button" id="button" value="Submit" />
<input type="reset" name="button2" id="button2" value="Reset" />
</p>
</form>
</div>
<p> </p>
<hr />
<p style="text-align:center; font-size: 12px;">© 2014 Lake McHenry County Scanner</p>
</body>
</html>
And here is my page called indexcad.php (which is the page the form data comes up on):
<!DOCTYPE html>
<html>
<?php
//because you use method post you can access your form value by using this code
$town = $_POST['town'];
$location = $_POST['location'];
$incident_type= $_POST['incident_type'];
$time_date= $_POST['time_date'];
$admin = $_POST['admin'];
$db = mysql_connect('localhost','root','') or die("Database error");
mysql_select_db('mydatabase', $db);
$result= mysql_query("select * from cad");
while($row = mysql_fetch_array($result))
?>
<head>
<title>LMCS CAD</title>
</head>
<body>
<div align="center">
<form action="" method="get">
<table width="968" height="248" border="1" align="center" cellpadding="10" cellspacing="0" rules="rows" id="incidents" style="color:#333333;border-collapse:collapse;text-align:left;">
<tr style="color:White;background-color:#5D7B9D;font-weight:bold;font-style:italic;">
<th scope="col">TOWN</th>
<th scope="col">LOCATION</th>
<th scope="col">INCIDENT TYPE</th>
<th scope="col">TIME/DATE</th>
<th scope="col">ADMIN</th>
</tr>
<tr style="color:#333333;background-color:#F7F6F3;font-weight:bold;">
<?php
//replace this to your old php code
echo "<td>" .$row['town'] ."</td>";
echo "<td>" .$row['location'] ."</td>";
echo "<td>" .$row['incident_type'] ."</td>";
echo "<td>" .$row['time_date'] ."</td>";
echo "<td>" .$row['admin'] ."</td>";
?>
</tr>
</table>
</form>
</body>
</html>
The general shape of your script could look like this (i didn't look precisely if smthg wrong in your code, just reorganized it a bit...
<!DOCTYPE html>
<html>
<head>
<title>LMCS CAD</title>
</head>
<body>
<div align="center">
<form action="" method="get">
<table width="968" height="248" border="1" align="center" cellpadding="10" cellspacing="0" rules="rows" id="incidents" style="color:#333333;border-collapse:collapse;text-align:left;">
<tr style="color:White;background-color:#5D7B9D;font-weight:bold;font-style:italic;">
<th scope="col">TOWN</th>
<th scope="col">LOCATION</th>
<th scope="col">INCIDENT TYPE</th>
<th scope="col">TIME/DATE</th>
<th scope="col">ADMIN</th>
</tr>
<tr style="color:#333333;background-color:#F7F6F3;font-weight:bold;">
<?php
$town = $_POST['town'];
$location = $_POST['location'];
$incident_type= $_POST['incident_type'];
$time_date= $_POST['time_date'];
$admin = $_POST['admin'];
$db = mysqli_connect('localhost','root','') or die("Database error");
mysqli_select_db($db, 'mydatabase');
$result= mysqli_query($db, "select * from cad");
while($row = mysqli_fetch_array($result))
{
echo "<td>" .$row['town'] ."</td>";
echo "<td>" .$row['location'] ."</td>";
echo "<td>" .$row['incident_type'] ."</td>";
echo "<td>" .$row['time_date'] ."</td>";
echo "<td>" .$row['admin'] ."</td>";
}
?>
</tr>
</table>
</form>
</body>
</html>
Related
I want to update record in php using GET method but whenever i click on "update button" it does not change anything and just refresh the page.and data remains the same.Here are the codes. Kindly tell me where i m doing it wrong. Thanks
<?php
include_once"dbconfig.php";
if(isset($_GET['edit']))
{
$id=$_GET['edit'];
echo $id;
$sql_query="SELECT * FROM users WHERE user_id='$id' ";
$result_set=mysql_query($sql_query);
$fetched_row=mysql_fetch_array($result_set);
}
if(isset($_POST['btn-update']))
{
// variables for input data
$first_name=$_POST['first_name'];
$last_name=$_POST['last_name'];
$city_name=$_POST['city_name'];
//sql query to update into database
$sql_query="UPDATE users SET first_name='$first_name',last_name='$last_name',user_city='$city_name' WHERE user_id='$id' ";
mysql_query($sql_query);
//if(!$sql_query)
//die('data can not update'.mysql_error());
//else
//echo 'data updated successfully';
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<center>
<form method="post">
<table align="center">
<tr>
<td><input type="text" name="first_name" placeholder="First Name" value="<?php echo $fetched_row['first_name']; ?>"required /> </td>
</tr>
<tr>
<td><input type="text" name="last_name" placeholder="Last Name" value="<?php echo $fetched_row['last_name']; ?>" required /> </td>
</tr>
<tr>
<td><input type="text" name="city_name" placeholder="City" value="<?php echo $fetched_row['user_city']; ?>" required /> </td>
</tr>
<tr>
<td>
<button type="submit" name="btn-update"><strong>UPDATE</strong></button>
</td>
</tr>
</table>
</form>
</center>
</body>
</html>
Second File
<?php
include_once"dbconfig.php";
?>
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>CRUD Operations With php and MySql </title>
<link rel="stylesheet" href="style.css" type="text/css"/>
</head>
<body>
<center>
<div id="body">
<div id="content">
<table align="center">
<table align="center">
<tr>
<th colspan="9">Add data Here ! </th>
</tr>
<tr>
<th colspan="2">FirstName </th>
<th colspan="8">LastName</th>
<th colspan="4">CityName </th>
<th>Operations</th>
<!--<th colspan="2">Operations</th> -->
</tr>
<?php
$sql_query="SELECT * FROM users";
$result_set=mysql_query($sql_query);
while($row=mysql_fetch_row($result_set))
{
?>
<tr>
<td><?php echo $row[0]; ?> </td>
<td colspan="4"><?php echo $row[1]; ?></td>
<td colspan="6"><?php echo $row[2];?></td>
<td colspan="4"><?php echo $row[3];?></td>
<td> <a href='edit_data.php?edit=$row[0]'>EDIT</a> </td>
<!--<td align="center"><a href="javascript edt_id('<//?php echo $row[0]; ?><img src="b_edit.png" align="EDIT" /></a></td>
<td align="center"><a href="javascript:delete_id('<//?php echo $row[0];?><img src="b_drop.png" align="DELETE" /></a></td>
</tr> -->
<?php
}
?>
</table>
</div>
</div>
</center>
</body>
</html>
Change
mysql_query($sql_query);
To
mysql_query($sql_query) or die (mysql_error()) ;
You're not sending the id (the form action property is missing
I am having an issue on designing a web page. I want to display a POST variable inside of an HTML table.
Here is the form code from the first page:
<form action="buy.php" method="post">
<input type="text" name="uid" />
<input type="submit" value="Buy Now" />
</form>
This code works fine if I am displaying the POST variable on a normal blank PHP file.
But when I go to use it in an html table it just won't display.
Here is the table code:
<td id="bal"><?php echo $_POST['uid']; ?></td>
<td id="amt">test1</td>
<td id="type">test2</td>
The first tabledata just appears blank.
Can anyone help me fix this?
Here is the entire code in the buy.php file: http://pastebin.com/ffWAP92C
(was having trouble posting it in here )
This is what the problem looks like:
Change this <td id="bal"> <?php echo "$_POST['uid'];" ?> </td> to <td id="bal"> <?php echo $_POST['uid']; ?> </td>
Try this one,
<html>
<head>
<title></title>
<style type="text/css">
</style>
</head>
<body>
<center><h1>Purchase Account ID</h1></center>
<table border="1" style="width:100%;">
<tr>
<td><b>Account ID</b></td>
<td><b>Account Type</b></td>
<td><b>Account Price</b></td>
</tr>
<tr>
<td id="bal">
<?php
if(isset($_POST['uid']))
echo $_POST['uid'];
else
echo "Nothing";
?>
</td>
<td id="amt">test1</td>
<td id="type">test2</td>
</tr>
</table>
</body>
</html>
Hope this works.
Remove " signs inside php tag. i.e. replace
<td id="bal"> <?php echo "$_POST['uid'];" ?> </td>
with
<td id="bal"> <?php echo $_POST['uid']; ?> </td>
OR insert semicolon after " sign. i.e.
<td id="bal"> <?php echo "$_POST['uid']"; ?> </td>
you can copy past below code in a test.php file. i have updated code. It is working in my localhost.
<html>
<head>
<title></title>
<style type="text/css">
</style>
</head>
<center><h1>Purchase Account ID</h1></center>
<body>
<table border="1" style="width:100%;">
<tr>
<td><b>Account ID</b></td>
<td><b>Account Type</b></td>
<td><b>Account Price</b></td>
</tr>
<tr>
<td id="bal"> <?php if(isset($_POST['uid'])) echo $_POST['uid']; ?> </td>
<td id="amt">test1</td>
<td id="type">test2</td>
</tr>
</table>
</body>
<form action="test.php" method="post">
<input type="text" name="uid" />
<input type="submit" value="Buy Now" />
</form>
</html>
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
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.
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.