Displaying results from a dropdown list - php

I am stuck on creating a dropdown list that is connected to another php page. I have used a sql query to list the staffNames but i need them to have the value of staffID. I have connected the page task7.php (which has a query that displays purchase information of a given staffID), so once the user clicks on a name then clicks submit, that persons order information should be displayed.Currently I am able to view the drop down list, select a name, but when i click submit the table only has field names with an empty table. HERES MY CODE:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Prac 2 Task 9</title>
</head>
<body>
<?php
$conn = mysql_connect("localhost", "twa291", ".......");
mysql_select_db("factory291", $conn)
or die ('Database not found ' . mysql_error() );
?>
<form method="get" action="task7.php">
<select name="list" id="list" size="12">
<?php
$sql = "SELECT staffID, staffName FROM staff";
$result = mysql_query($sql, $conn)
or die ('Problem with query' . mysql_error());
while ($row = mysql_fetch_array($result)){
$title=$row["staffName"];
$id=$row["staffID"];
echo "<option value= ".$id.">".$title."</option>";
}
?>
<input type="submit" value="Submit" method="get">
</select>
</form>
<?php
mysql_close($conn); ?>
</body>
</html>
HERE IS MY task7.php FILE:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Prac 2 Task 3</title>
</head>
<body>
<?php
$conn = mysql_connect("localhost", "twa291", "......");
mysql_select_db("factory291", $conn)
or die ('Database not found ' . mysql_error() ); ?>
<?php
$staffid= $_GET["staffID"];
?>
<?php
$sql = "SELECT orderID, orderDate, orderDate, shippingDate, staffName FROM purchase,
staff
WHERE staff.staffID='$staffid'";
$rs = mysql_query($sql, $conn)
or die ('Problem with query' . mysql_error());
?>
<table border="1" summary="Staff Orders">
<tr>
<th>Order ID</th>
<th>Order Date</th>
<th>Shipping Date</th>
<th>Staff Name</th>
</tr>
<?php
while ($row = mysql_fetch_array($rs)) { ?>
<tr>
<td><?php echo $row["orderID"]?></td>
<td><?php echo $row["orderDate"]?></td>
<td><?php echo $row["shippingDate"]?></td>
<td><?php echo $row["staffName"]?></td>
</tr>
<?php }
mysql_close($conn); ?>
</table>
</body>
</html>

You have wrapped unwanted string with " "
<?php
$sql = "SELECT staffID, staffName FROM staff";
$result = mysql_query($sql, $conn)
or die ('Problem with query' . mysql_error());
while ($row = mysql_fetch_array($result))
{
$title=$row["staffName"];
$id=$row["staffID"];
echo "<option value= '.$id.'>".$title."</option>";
}
?>

?php
$staffid= $_GET["list"];
?>
<?php
$sql = "SELECT orderID, orderDate, orderDate, shippingDate, staffName FROM purchase,
staff
WHERE staff.staffID='$staffid'";
?>

Related

Edit MySQL Row PHP

I'm trying to edit and update a row using PHP.
Here is the code:
index.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">
<div class="header">
<?php include 'header.php';?>
</div>
<center>
<?php
/*
VIEW.PHP
Displays all data from 'players' table
*/
// connect to the database
include_once('../connection.php');
// get results from database
$query = "SELECT EmployeeName, DOB, Age, StreetAddress, City, State, ZipCode,
Email, HomePhone, Wireless, JobTitle, id, HomeDept, Manager FROM headcount ORDER BY `headcount`.`EmployeeName` ASC";
$response = #mysqli_query($dbc, $query);
// display data in table
echo "<p><b>View All</b> | <a href='../employees/rides.php'>Rides</a></p>";
echo "<table border='1' cellpadding='10'>";
echo "<tr> <th>Employee Name</th> <th>Home Department</th> <th>Job Title</th> <th>Edit</th></tr>";
// loop through results of database query, displaying them in the table
while($row = mysqli_fetch_array($response)){
// echo out the contents of each row into a table
echo "<tr>";
echo '<td>' . $row['EmployeeName'] . '</td>';
echo '<td>' . $row['HomeDept'] . '</td>';
echo '<td>' . $row['JobTitle'] . '</td>';
echo '<td>Edit</td>';
echo "</tr>";
}
// close table>
echo "</table>";
?>
</center>
edit.php
<?php
mysql_connect('localhost', 'root', 'root') or die(mysql_error());
mysql_select_db("hwss") or die(mysql_error());
$UID = (int)$_GET['ID'];
$query = mysql_query("SELECT * FROM headcount WHERE id = '$UID'") or die(mysql_error());
if(mysql_num_rows($query)>=1){
while($row = mysql_fetch_array($query)) {
$EmployeeName = $row['EmployeeName'];
$DOB = $row['DOB'];
$Age = $row['Age'];
$email = $row['email'];
}
?>
<form action="update.php" method="post">
<input type="hidden" name="ID" value="<?=$UID;?>">
email: <input type="text" name="ud_email" value="<?=$email;?>"><br>
Name: <input type="text" name="ud_EmployeeName" value="<?=$EmployeeName?>"><br>
DOB: <input type="text" name="ud_dob" value="<?=$DOB?>"><br>
Age: <input type="text" name="ud_Age" value="<?=$Age?>"><br>
<input type="Submit">
</form>
<?php
}else{
echo 'No entry found. Go back';
}
?>
</body>
</html>
When I click edit it says "No entry found" with the back link on each ID url. I understand that I don't have any Update code yet. I'm simply just trying to get it to display the data before adding the rest.
Error Message
Notice: Undefined index: ID in C:\xampp\htdocs\Scheduling\Employees\edit.php on line 5
No entry found. Go back
Use: $_GET['id']
$UID = (int)$_GET['id'];
instead of
$UID = (int)$_GET['ID'];

Search with pagination [duplicate]

This question already exists:
How can i edit the search and pagination because i don't want it to be echoed?
Closed 7 years ago.
I have this search with pagination, the search function is working fine and the pagination is also working fine but my real problem is that I don't know how to merge those two. Every time I try to search, the search result is showing but the pagination is not functioning normal. Please someone help me about this issue. I don't know where to start.
I have this code:
<?php
$con = mysql_connect("localhost","root","");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("region_survey", $con);
$sql="SELECT * FROM municipality";
if(isset($_POST['search'])){
$search_term=mysql_real_escape_string($_POST['search_box']);
$sql .= " WHERE province_id LIKE '%{$search_term}%' ";
}
$query=mysql_query($sql) or die (mysql_error());
?>
<form name="search_form" method="POST" action="">
Search:<input type="text" name="search_box" value="" />
<input type="submit" name="search" value="search the table" />
</form>
<!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>Untitled Document</title>
</head>
<body>
<?php
//Include the PS_Pagination class
include('ps.php');
//Connect to mysql db
$conn = mysql_connect('localhost','root','');
if(!$conn) die("Failed to connect to database!");
$status = mysql_select_db('region_survey', $conn);
if(!$status) die("Failed to select database!");
$sql = 'SELECT * FROM municipality';
//Create a PS_Pagination object
$pager = new PS_Pagination($conn, $sql, 15, 17);
//The paginate() function returns a mysql result set for the current page
$rs = $pager->paginate();
?>
<?php
$con = mysql_connect("localhost","root","");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
//Count total number of records after search
mysql_select_db("region_survey", $con);
if(isset($_POST['search'])){
$search_term=mysql_real_escape_string($_POST['search_box']);
$sql="SELECT * FROM municipality WHERE province_id LIKE '%$search_term%'";
}
$result = mysql_query($sql, $con);
$row = mysql_num_rows($result);
echo "Total Number: ";
echo $row;
?>
<table border="1" cellpadding="0" cellspacing="0" id="resultTable">
<tr>
<th> <strong>ID</strong> </th>
<th> <strong>Province ID</strong> </th>
<th> <strong>Municipality Name</strong> </th>
</tr>
<?php
while($row = mysql_fetch_array($query))
{
?>
<tr>
<td> <?php echo $row["id"]; ?> </td>
<td> <?php echo $row["province_id"]; ?></td>
<td> <?php echo $row["municipality_name"]; ?></td>
<td><input name="selector[]" type="checkbox"
id="checkbox[]" value="<?php echo $row['id'];?>"></td>
<td>Edit </td>
</tr>
<?php
}
?>
</table>
<?php
//Display the navigation
//echo $pager->renderFullNav();
echo '<div style="text-align:center">'.$pager->renderFullNav().'</div>';
?>
</body>
</html>
Pages will have URL like example.com/search/term/?page=2 (or example.com/search.php?term=xyz&page=2, doesn't matter if you redirect URLs or not).
In PHP then will be something like:
$pagelimit = 10; // records per page
$page = isset($_GET['page']) ? (int)$_GET['page'] : 1; // set current page
And LIMIT with OFFSET in your SQL query:
$sql = "SELECT *
FROM municipality
WHERE province_id LIKE '%$search_term%'
LIMIT " . ($page - 1) * $pagelimit . ", " . $pagelimit;

selection of query using multiple selection

I am beginner to php.I want to select the department from the options and after the selection of the department, I want to display the roll no in the next drop down box belong to that department. Help me by providing some ideas related to my questions.
<!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>Untitled Document</title>
</head>
<body>
<?php include('C:\wamp\www\fms\background.php'); ?>
<?php include('C:\wamp\www\fms\adminmenu.php'); ?>
<?php
if (isset($_POST['delete'])) {
$con = mysql_connect("localhost", "root", "");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
$cid = $_POST['cid'];
$sql = "DELETE from addpassenger WHERE rno='$rno'";
mysql_select_db('fms');
$retval = mysql_query($sql, $con);
if (!$retval) {
die('Could not delete data: ' . mysql_error());
}
echo "Deleted data successfully\n";
mysql_close($con);
} else {
?>
<p></p>
<p></p>
<p></p>
<p></p>
<center>
<form method="post">
<table width="344" border="0" cellspacing="1" cellpadding="2">
<tr>
<td>SELECT THE DEPARTMENT</td>
<td><?php
$con = mysql_connect("localhost", "root", "") or die(mysql_error());
$db = #mysql_select_db("fms", $con) or die(mysql_error());
$str = "select dept from addpassenger";
$res1 = #mysql_query($str);
echo '<select name="dept">';
echo '<option selected="----------"></option>';
while ($row = mysql_fetch_array($res1)) {
echo '<option value="' . $row['dept'] . '">' . $row['dept'] . '</option>';
}
echo '</select>';
?></td>
</tr>
<tr>
<td width="208">SELECT THE ROLL NO</td>
<td width="125">
<?php
$con = mysql_connect("localhost", "root", "") or die(mysql_error());
$db = #mysql_select_db("fms", $con) or die(mysql_error());
$str = "select rno from addpassenger ";
$res1 = #mysql_query($str);
echo '<select name="rno">';
echo '<option selected="----------"></option>';
while ($row = mysql_fetch_array($res1)) {
echo '<option value="' . $row['rno'] . '">' . $row['rno'] . '</option>';
}
echo '</select>';
?>
</select>
</td>
</tr>
<tr>
<td width="208"></td>
<td></td>
</tr>
<tr>
<td width="208"></td>
<td>
<input name="delete" type="submit" id="delete" value="Delete">
</td>
</tr>
</table>
</form>
</center>
<?php
}
?>
</body>
</html>
select rno from addpassenger
needs to have a where clause which selects based on previous selection

Select box populated from database invisible text

My problem is not connecting my select box to my database but getting the info to show.... It connects and i can see the boxes for the amount of items i have in my database table but there is no text in any of them. My database table is .CSV im not sure if that could cause a problem?
Here is my code: In my code i will just put in dummy_.... (What ever item) instead of the real thing.
<?php
require_once('auth.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<link href="styles/stylesheet.css" rel="stylesheet" type="text/css">
<head>
</head>
<body>
<form id="dropdown">
<?php
mysql_connect("localhost", "repaiami_member", "zmozmozm2083") or die("Connection Failed");
mysql_select_db("repaiami_member")or die("Connection Failed");
?>
<?php
$query = "SELECT * FROM lighting";
$result = mysql_query($query);
?>
<table width="450px;">
<tr>
<td>
<select id="dropdown_description" name="select1" class="ui-select selBox">
<?php
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
?>
<option value="<?php echo $line['field'];?>"> <?php echo $line['field'];?></option>
<?php } ?>
</select>
</td>
<td>
<input type="text" name="first_name" maxlength="50" size="30">
</td>
</tr>
</table>
</form>
</body>
</html>
Can anyone help?

Getting dependant data from two tables

I'm trying to create a page which uses session data to find a user in a database and then sends the events that this user has signed up to. I'm a bit of a newbie and have got very confused with where I am at. I am using two different tables to get the data, and this is where I'm getting confused and where I believe the errors are occurring. Thanks in Advance.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php
session_start();
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<?php
$username = $_SESSION['username'];
$email = $_SESSION['user_email'];
$con=mysqli_connect("localhost","emuas","******","EMUAS_signUp");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
echo "<table>
<tr>
<td> Logged in as:</td>
</tr>
<tr>
<th>" . $username . "</th>
</tr>
<tr>
<td>
<form action='logout.php' method='post'>
<input type='submit' value='Logout' >
</form>
</td>
</tr>
<tr>
<th>Events Attending:</th>
</tr>";
$find = mysqli_query($con,"SELECT * FROM SIGN_UP_TEST WHERE User = '$username'");
while($find_row = mysqli_fetch_array($find)){
//Get Event ID
$eventId = $find_row['EventID'];
//Use Event ID to get Event Name
$result = mysqli_query($con,"SELECT * TEST WHERE EventID = '$eventId'");
//Insert Event Name into table with link from Page Name
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td> <a href='http://www.emuas.co.uk/members/sign_up_sheets/S" . $row['PageName'] . ".php'>" . $row["EventName"] . "</a> </td>";
echo "</tr>";
}
}
echo "</table>";
?>
<body>
</body>
</html>

Categories