DB MAP:
Carriers "table1": carriername, carrierid, ect... Post data
carrierinfo "table2": carriername, id, contact, ect... carrier list
I am using mysql_query from table2 for my carriername drop down. Using this I am able to post a carrier name to table1. I am trying to use the same drop down to post the related id from the selcected carriername. So in short I need to have one drop down that displays only the Carrier names but querys both carriername & id from table2. When the form is posted I need to post to the carriername & carrierid to table1. Below is the drop down I am using. Please let me know how I can connect the dots and add what is needed. If its possible.
<?php
if (isset($_POST["submit"]) && $_POST["submit"] == "Submit")
{
for ($count = 1; $count <= 9; $count++)
{
$fields[$count] = "";
if (isset($_POST["field" . $count . ""]))
{
$fields[$count] = trim($_POST["field" . $count . ""]);
//echo $fields[$count] . "<br />";
}
}
$con = mysql_connect("", "", "");
mysql_select_db("", $con);
$carrierid = mysql_real_escape_string($_POST['carrierid']);
$fromzip = mysql_real_escape_string($_POST['fromzip']);
$tozip = mysql_real_escape_string($_POST['tozip']);
$typeofequipment = mysql_real_escape_string($_POST['typeofequipment']);
$weight = mysql_real_escape_string($_POST['weight']);
$length = mysql_real_escape_string($_POST['length']);
$paymentamount = mysql_real_escape_string($_POST['paymentamount']);
$contactperson = mysql_real_escape_string($_POST['contactperson']);
$loadtype = mysql_real_escape_string($_POST['loadtype']);
$date = mysql_real_escape_string($_POST['date']);
$insert = "INSERT INTO Carriers (`carriername` ,`carrierid`, `fromzip` ,`tozip` ,`typeofequipment` ,`weight` ,`length` ,`paymentamount` ,`contactperson` ,`loadtype` ,`date`)
SELECT carriername ,'$carrierid' ,'$fromzip' ,'$tozip' ,'$typeofequipment' ,'$weight' ,'$length' ,'$paymentamount' ,'$contactperson' ,'$loadtype', NOW()) FROM carrierinfo WHERE id = '$carrierid'";
mysql_query($insert) or die(mysql_error());
$select = "SELECT `carriername` ,`fromzip` ,`tozip` ,`typeofequipment` ,`weight` ,`length` ,`paymentamount` ,`contactperson` ,`loadtype` FROM `Carriers` ORDER BY `date` DESC;";
$result = mysql_query($select) or die(mysql_error());
}
?>
<style ="text-align: center; margin-left: auto; margin-right: auto;"></style>
</head>
<body>
<input type="button" onclick="window.location.href='search.php';" value="Search Board" /><div
style="border: 2px solid rgb(0, 0, 0); margin: 16px 20px 20px; width: 400px; background-color: rgb(236, 233, 216); text-align: center; float: left;">
<form action="" method="post";">
<div
style="margin: 8px auto auto; width: 300px; font-family: arial; text-align: left;"><br>
<table style="font-weight: normal; width: 100%; font-size: 12px;"
border="1" bordercolor="#929087" cellpadding="6" cellspacing="0">
<table
style="font-weight: normal; width: 100%; text-align: right; font-size: 12px;"
border="1" bordercolor="#929087" cellpadding="6" cellspacing="0">
<tbody>
<tr>
<td style="width: 10%;">Carrier:</td><td>
<?php
$con = mysql_connect("", "", "");
mysql_select_db("", $con);
$query=("SELECT * FROM carrierinfo");
$result=mysql_query($query) or die ("Unable to Make the Query:" . mysql_error() );
echo "<select name='carrierid'>";
while($row=mysql_fetch_array($result)){
echo "<OPTION VALUE='".$row['id']."'>".$row['carriername']."</OPTION>";
}
echo "</select>";
?>
</td>
</tr>
<tr>
<td style="width: 10%;">Load Type:</td><td>
<select name="loadtype">
<option></option>
<option value="TL">Truck Load</option>
<option value="Partial">Partial</option>
</select>
</td>
</tr>
<tr>
<td style="width: 35%;">Pick Zip:</td><td> <input id="fromzip" name="fromzip" maxlength="50"
style="width: 100%;" type="text">
</tr>
<tr>
<td style="width: 35%;">Drop Zip:</td><td> <input id="tozip" name="tozip" maxlength="50"
style="width: 100%;" type="text">
</tr>
<tr>
<td style="width: 35%;">Weight:</td><td> <input id="weight" name="weight" maxlength="50"
style="width: 100%;" type="text">
</tr>
<tr>
<td style="width: 35%;">Length:</td><td> <input id="length" name="length" maxlength="50"
style="width: 100%;" type="text">
</tr>
<tr>
<td style="width: 10%;">Equip:</td><td>
<select name="typeofequipment">
<option></option>
<option value="AUTO">Auto Carrier</option>
<option value="DD">Double Drop</option>
<option value="F">Flatbed</option>
<option value="LB">Lowboy</option>
<option value="Rail">Rail</option>
<option value="Ref">Reefer</option>
<option value="RGN">Removable Goose Neck</option>
<option value="SD">Step Deck</option>
<option value="TANK">Tanker (Food, liquid, etc.)</option>
<option value="V">Van</option>
</select>
</td>
</tr>
<tr>
<td style="width: 35%;">Contact:</td><td> <input id="contactperson" name="contactperson" maxlength="50"
style="width: 100%;" type="text">
</tr>
<tr>
<td style="width: 35%;">Rate:</td><td> <input id="paymentamount" name="paymentamount" maxlength="50"
style="width: 100%;" type="text">
</tr>
</tbody>
</table>
<p style="text-align: center;"><input name="submit" value="Submit"
class="submit" type="submit"><input type="button" onclick="window.location.href='newcarrier.php';" value="Add Carrier" /></p>
</div>
</form>
</div>
<p style="margin-bottom: -20px;"> </p>
</body>
Use a join:
SELECT t1.carrierid, t2.carriername, t2.id
FROM table1 t1 JOIN table2 t2 USING (carriername)
Joining tables should be one of the first things you learn when studying SQL.
UPDATE:
Never mind the above, your original query to populate the dropdown was correct. When you populate the select, you should do:
echo "<select name='carrierid'>";
while($row=mysql_fetch_array($result)){
echo "<OPTION VALUE='".$row['id']."'>".$row['carriername']."</OPTION>";
}
echo "</select>";
When posting the data, get rid of this line:
$carriername = mysql_real_escape_string($_POST['carriername']);
and change the insert query to:
$insert = "INSERT INTO Loads (`carriername` ,`carrierid`, `fromzip` ,`tozip` ,`typeofequipment` ,`weight` ,`length` ,`paymentamount` ,`contactperson` ,`loadtype` ,`date`)
SELECT carriername ,'$carrierid' ,'$fromzip' ,'$tozip' ,'$typeofequipment' ,'$weight' ,'$length' ,'$paymentamount' ,'$contactperson' ,'$loadtype', NOW())
FROM Carriers
WHERE id = '$carrierid'";
The change to the form makes it display the carrier name, but return the ID in the post data. Then the new INSERT query uses that ID to get the carrier name from table 2 and combine that with all the other post data when inserting into table 1.
Related
I'm trying to make a filter option using a select dropdown box and I don't know where I am failing. I have a search bar that works perfectly but I want to able to select the location where I would like to search .
For example I can type the name of the job I'm looking for but I would like to filter the locations to only view in one city
Here is my code
Edit : Thanks to ADyson I made some edits to the code I will post the new code over the last one
<?php
require 'views/header.php';
$connection = getDbConntection();
// Search //
if (!empty($_GET['search'])) {
$data = [
'job_name' => '%' . $_GET['search'] . '%',
'location_id' => $_GET['location_id']
];
$searches = $connection->prepare("select jobs.id, jobs.name as job_name, salary as job_salary, description, location_id, domain_id , locations.name as location_name , domains.name as domain_name from jobs
LEFT JOIN locations ON jobs.location_id = locations.id
LEFT JOIN domains on jobs.domain_id = domains.id "
. "where jobs.name like :job_name"
. 'AND location_id = :location_id');
$searches->execute($data);
$searches= $query->fetchAll();
// List //
} else {
$query = $connection->query("select jobs.id, jobs.name as job_name, salary as job_salary, description, location_id, domain_id , locations.name as location_name , domains.name as domain_name from jobs
LEFT JOIN locations ON jobs.location_id = locations.id
LEFT JOIN domains on jobs.domain_id = domains.id ");
$searches = $query->fetchAll();
}
?>
<div class="w3-row-padding w3-padding-64 w3-container">
<div class="w3-content">
<h1 class="center"> Jobs table </h1>
<br>
<form style="text-align:center" action="index.php" method="GET">
<input type="text" name="search" value="Search jobs..." onfocus="this.value = ''" class="btn btn-danger">
<select name="location_id" class="btn btn-danger">
<?php foreach ($searches as $location): ?>
<?php $selectedText = ($location['id']) ?>
<option value= <?= $selectedText ?> > <?= $location['location_name'] ?></option>
<?php endforeach; ?>
</select>
<input type="submit" value="Search" class="btn btn-danger">
Back to list
</form>
<br>
<div class="center">
<table>
<tr>
<th>ID</th>
<th> Job Name</th>
<th> Job Location</th>
<th> Job Domain</th>
<th> Job Description</th>
<th> Job Salary</th>
<th>Actions</th>
</tr>
<?php foreach ($searches as $key => $job_name) : ?>
<tr>
<th><?= $job_name['id'] ?></th>
<th style="background-color: lightskyblue"><?= $job_name['job_name'] ?></th>
<td><?= $job_name['location_name'] ?></td>
<td><?= $job_name['domain_name'] ?></td>
<td><?= $job_name['description'] ?></td>
<td><?= $job_name['job_salary'] ?></td>
<td> <a class="btn btn-success" href="edit.php?id=<?= $job_name['id'] ?>"> Edit </a>
<a class="btn btn-danger" href="delete.php?id=<?= $job_name['id'] ?>">Delete</a> </td>
</tr>
<?php endforeach; ?>
</table>
</div>
<style>
table td, table th {
padding: 15px;
text-align: center;
}
table th {
background:#3390FF;
}
table {
width: 100%;
border: 3px solid #ccc;
border-collapse: collapse;
}
.ce
nter {
margin: auto;
width: 100%;
border: 3px solid red;
padding: 10px;
text-align: center;
}
</style>
</div>
</div>
Sorry for the messy code, I'm new to coding in general
Thanks to ADysom I solved the problem , here is the correct code
<?php
require 'views/header.php';
$connection = getDbConntection();
$locations = $connection->query("select * from locations");
// Search //
if (!empty($_GET['search'])) {
$data = [
'job_name' => '%' . $_GET['search'] . '%',
'location_id' => $_GET['location_id']
];
$query = $connection->prepare("select jobs.id, jobs.name as job_name, salary as job_salary, description, location_id, domain_id , locations.name as location_name , domains.name as domain_name from jobs
LEFT JOIN locations ON jobs.location_id = locations.id
LEFT JOIN domains on jobs.domain_id = domains.id "
. "where jobs.name like :job_name "
. "AND location_id = :location_id ");
$query->execute($data);
$query = $query->fetchAll();
// print_r($_GET);
// List //
} else {
$query = $connection->query("select jobs.id, jobs.name as job_name, salary as job_salary, description, location_id, domain_id , locations.name as location_name , domains.name as domain_name from jobs
LEFT JOIN locations ON jobs.location_id = locations.id
LEFT JOIN domains on jobs.domain_id = domains.id ");
$query = $query->fetchAll();
}
?>
<div class="w3-row-padding w3-padding-64 w3-container">
<div class="w3-content">
<h1 class="center"> Jobs table </h1>
<br>
<form style="text-align:center" action="index.php" method="GET">
<input type="text" placeholder='Search jobs..' name="search" onfocus="this.value = ''" class="btn btn-danger">
<select name="location_id" class="btn btn-danger">
<?php foreach ($locations as $location): ?>
<option value="<?= $location['id'] ?>">
<?= $location['name'] ?>
</option>
<?php endforeach; ?>
</select>
<input type="submit" value="Search" class="btn btn-danger">
Back to list
</form>
<br>
<div class="center">
<table>
<tr>
<th>ID</th>
<th> Job Name</th>
<th> Job Location</th>
<th> Job Domain</th>
<th> Job Description</th>
<th> Job Salary</th>
<th>Actions</th>
</tr>
<?php foreach ($query as $key => $job_name) : ?>
<tr>
<th><?= $job_name['id'] ?></th>
<th style="background-color: lightskyblue"><?= $job_name['job_name'] ?></th>
<td><?= $job_name['location_name'] ?></td>
<td><?= $job_name['domain_name'] ?></td>
<td><?= $job_name['description'] ?></td>
<td><?= $job_name['job_salary'] ?></td>
<td> <a class="btn btn-success" href="edit.php?id=<?= $job_name['id'] ?>"> Edit </a>
<a class="btn btn-danger" href="delete.php?id=<?= $job_name['id'] ?>">Delete</a> </td>
</tr>
<?php endforeach; ?>
</table>
</div>
<style>
table td, table th {
padding: 15px;
text-align: center;
}
table th {
background:#3390FF;
}
table {
width: 100%;
border: 3px solid #ccc;
border-collapse: collapse;
}
.center {
margin: auto;
width: 100%;
border: 3px solid red;
padding: 10px;
text-align: center;
}
::placeholder {
color: white;
opacity: 1;
}
</style>
</div>
</div>
Sooo I've been working on a site for a friend of my dads so he can keep his business in check etc. I've been using the While Loop to print out a table of the 'Tasks' that can be inputted in to the site, however when I go to change the status of the task it's not doing so?
I'm sure that is the way I'm getting the ID for locating the record that needs to be updated, but I think I'm on the correct lines. So firstly, is there anything obvious other than my shoddy coding? Secondly, this there any better way of getting the ID or the reasoning for the lack of updating? Much Obliged!
HTML - The page
<table class="tasktable">
<tr>
<th style="text-align: center; width: 100px ">Job Number (ID)</th>
<th style="text-align: center; width: 100px">VRM</th>
<th style="text-align: center; width: 175px;">Date Arrived</th>
<th style="text-align: center;">Work</th>
<th style="text-align: center; width:200px;">Customer</th>
<th style="text-align: center; width: 250px;">Task Progress</th>
</tr>
<?php
include 'Login-System/db.php';
$query = 'SELECT * FROM outstanding WHERE taskprogress = "New" OR taskprogress = "In Progress" ORDER by id ASC';
$result = mysqli_query($conn, $query);
if($result):
if(mysqli_num_rows($result)>0):
while($tasks = mysqli_fetch_assoc($result)):
?>
<tr>
<td style="text-align: center;"><h4 name="jobnumberid"><?php echo $tasks['id'];?></h4></td>
<td style="text-align: center;"><h4><?php echo $tasks['VRM'];?></h4></td>
<td style="text-align: center;"><h4><?php echo $tasks['datearrived'];?></h4></td>
<td style="text-align: center;"><h4><?php echo $tasks['work'];?></h4></td>
<td style="text-align: center;"><h4><?php echo $tasks['customer'];?></h4></td>
<td>
<form action="SQL/taskchange.php" role="form" method="post" id="taskchange">
<select name="taskchanger" id="taskchanger" style="margin-top:6px;
width: 150px; float:left" class="form-control">
<option value="#"><?php echo $tasks['taskprogress'];?></option>
<?php
if ($tasks['taskprogress']== "New") {
echo '<option value="In Progress" class="form-control">In Progress</option>
<option value="Complete" class="form-control">Complete</option>';
} else { if ($tasks['taskprogress']== "In Progress") {
echo '<option value="New" class="form-control">New</option>
<option value="Complete" class="form-control">Complete</option>';
} else {
echo '<option value="New" class="form-control">New</option>
option value="In Progress" class="form-control">In Progress</option>';
}
}
?>
</select>
<button name="save" id="save" class="form-control" style="width: 75px; float:right;margin-top: 6px">Save</button>
</form>
</td>
</tr>
<?php
endwhile;
endif;
endif;
?>
</table>
PHP - Bit that inserts into the DB
<?php
if(isset($_POST['save'])){
include '../Login-System/db.php';
$id = mysqli_real_escape_string($conn, $_POST['jobnumberid']);
$newtask = mysqli_real_escape_string($conn, $_POST['taskchanger']);
$sql = "UPDATE outstanding SET taskprogress = '$newtask' WHERE id = '$id'";
mysqli_query($conn, $sql);
header("Location: ../outstanding.php?updated");
exit();
} else {
header("Location: ../outstanding.php?whoops");
exit();
}
This question already has answers here:
Reference - What does this error mean in PHP?
(38 answers)
Closed 8 years ago.
I have to make one system where the system requires the process of adding new information. The process flow is the process of adding the new information carried by the employee where all the information, name and id of staff will insert in mysql database. When I tried the process of that, I found staff_id and staff_name was empty in database mysql.
This is my addStaff.php
<?php
include("authenticationStaff.php");
include ("dbase.php");
$query= "SELECT * FROM staff WHERE staff_name ='".$_SESSION['SESS_STAFF_NAME']."'";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
$id = $row["id"];
$staff_id=$row["staff_id"];
#mysql_free_result($result);
?>
<html>
<head>
<script>
function Validate()
{
if (document.addStaff.project_name.value == '')
{
alert('Please Insert Project Name!');
document.addStaff.project_name.focus();
return false;
}
if (document.addStaff.project_id.value == '')
{
alert('Please Insert Project ID !');
document.addStaff.project_id.focus();
return false;
}
if (document.addStaff.location.value == '')
{
alert('Please Insert Location!');
document.addStaff.location.focus();
return false;
}
if (document.addStaff.cost.value == '')
{
alert('Please Insert Cost!');
document.addStaff.cost.focus();
return false;
}
if (document.addStaff.pic.value == '')
{
alert('Please Insert Person In Charge!');
document.addStaff..pic.focus();
return false;
}
if (document.addStaff.detail.value == '')
{
alert('Please Insert Detail about the Project!');
document.addStaff.detail.focus();
return false;
}
}
</script>
</head>
<body>
<table width="869" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="645" height="50" align="left" valign="middle"><strong>Welcome , You log in as <?php echo $_SESSION['SESS_STAFF_NAME'];?> </strong></td>
<td width="224" align="right" valign="middle"><strong>Log Out</strong></td>
</tr>
</table>
<?php
$idURL = $_GET['id'];
$query ="SELECT *
FROM staff s
JOIN inter1 i
ON (s.staff_name=i.staff_name)";
$result = mysql_query($query, $conn) or die("Could not execute query");
$row = mysql_fetch_array($result, MYSQL_BOTH); // using numeric index or array index
$staff_id = $row['staff_id'];
$project_name = $row['project_name'];
$location = $row['location'];
$detail = $row['detail'];
$pic = $row['pic'];
$staff_name = $row['staff_name'];
$project_id = $row['project_id'];
#mysql_free_result ($result);
?>
<center>
<form action="addStaff_process.php?id=<?php echo $staff_id; ?>" method="post" enctype="multipart/form-data" name="add_process" id="add_process" onSubmit="return Validate()" >
<table border="1" width="70%" cellspacing="1" cellpadding="6" >
<tr align="center" bgcolor="">
<td align="left" style="padding:10px 10px 10px 10px;" >PROJECT NAME :</td>
<td align="left" style="padding:10px 10px 10px 10px;" ><textarea name="project_name" cols="50" rows="2" id="project_name"></textarea></td>
</tr>
<tr align="center" bgcolor="">
<td align="left" style="padding:10px 10px 10px 10px;" >PROJECT ID:</td>
<td align="left" style="padding:10px 10px 10px 10px;" ><textarea name="project_id" cols="50" rows="2" id="project_id"></textarea></td>
</tr>
<tr align="center" bgcolor="">
<td align="left" style="padding:10px 10px 10px 10px;" >LOCATION :</td>
<td align="left" style="padding:10px 10px 10px 10px;" ><textarea name="location" cols="50" rows="2" id="location"></textarea></td>
</tr>
<tr align="center" bgcolor="">
<td align="left" style="padding:10px 10px 10px 10px;" > COST :</td>
<td align="left" style="padding:10px 10px 10px 10px;" ><textarea name="cost" cols="50" rows="2" id="cost"></textarea></td>
</tr>
<tr align="center" bgcolor="" >
<td align="left" style="padding:10px 10px 10px 10px;" >PERSON IN CHARGE :</td>
<td align="left" style="padding:10px 10px 10px 10px;" ><textarea name="pic" cols="50" rows="3" id="pic"></textarea></td>
</tr>
<tr>
<td align="left" style="padding:10px 10px 10px 10px;">DETAIL ABOUT THE PROJECT:</td>
<td align="left" style="padding:10px 10px 10px 10px;" ><textarea name="detail" cols="50" rows="4" id="detail"></textarea></td>
</tr>
</table>
<p> </p>
<p>
<input class="form-submit" type="submit" name="submit" value="SUBMIT" onClick="return Validate()"/>
<input type = "reset" value = "RESET" />
</p>
</form>
</center>
</body>
</html>
And this is my addStaff_process.php
<?php
include("authenticationStaff.php");
include ("dbase.php");
extract( $_POST );
$idURL = $_GET['id'];
$project_name = $_POST['project_name'];
$location = $_POST['location'];
$cost= $_POST['cost'];
$pic= $_POST['pic'];
$detail = $_POST['detail'];
$project_id = $_POST['project_id'];
$staff_id = $_POST['staff_id'];
$staff_name = $_SESSION['SESS_STAFF_NAME'];
$result ="INSERT INTO inter1 (project_name,location,cost,pic,detail,project_id)
VALUES ('$project_name','$location','$cost','$pic','$detail','$project_id')";
$query = mysql_query ($result, $conn);
if(mysql_num_rows($query)){
echo "<script type='text/javascript'> window.location='pageStaff.php'</script>";
}
else{
$query1 = "UPDATE inter1 SET staff_name = '$staff_name',staff_id = '$staff_id' WHERE staff_name=$idURL";
$result1 = mysql_query ($query1, $conn);
if($result1){
echo "<script type='text/javascript'> window.location='pageStaff.php'</script>";
}
}
?>
Can someone see where I am going wrong?if you need any more info then please let me know. thanks.
You need to use session_start(); at the start of every page that accesses the session values.
This is the full code of the page which i am using to update data.I Tried many time but it still not updating values in database..also tried to echo but still not updating
<?php
session_start();
include '../func-tion/func.php';
if(isset($_SESSION['m_uname']) && isset($_SESSION['m_pass']))
{
?>
<?php
if(isset($_POST['subup']))
{
$SQL="update appid set android_appid='".$_POST['and_a']."' , iphone_appid='".$_POST['iph_a']."' , ipad_appid='".$_POST['ipa_a']."' where u_name='".$_GET['name']."'";
echo $SQL;
}
?>
<?php
$main_qry=mysql_query("select * from users where u_name='".$_GET['name']."'");
$main_fetch=mysql_fetch_assoc($main_qry);
?>
<center><h2 class="art-postheader">Edit details of <b></b></h2></center><br/><br/>
<table align="center">
<tr align="center">
<td style="height: 60px; font-family: Helvetica,Arial,sans-serif; font-weight: bold;">Username:<br>
<input type="text" name="u_name" style="width: 300px;" value="<?php echo $main_fetch['u_name']?>"></td>
</tr>
<tr align="center">
<td style="height: 60px; font-family: Helvetica,Arial,sans-serif; font-weight: bold;">Email:<br>
<input type="text" name="u_email" style="width: 300px;" value="<?php echo $main_fetch['u_email']?>"></td>
</tr><?php
$main_qrys=mysql_query("select * from appid where u_name='".$_GET['name']."'");
$row=mysql_fetch_assoc($main_qrys);
?> <form name="user" method="post" action="users_edit.php" onSubmit="return valid();">
<tr align="center">
<td style="width: 100px; font-family: Helvetica,Arial,sans-serif; font-weight: bold;">Android Appid:<br>
<input type="text" name="and_a" style="width: 300px;" value="<?php echo $row['android_appid']?>"></td>
</tr>
<tr align="center">
<td style="width: 100px; font-family: Helvetica,Arial,sans-serif; font-weight: bold;">Iphone Appid:<br>
<input type="text" name="iph_a" style="width: 300px;" value="<?php echo $row['iphone_appid']?>"></td>
</tr>
<tr align="center">
<td style="width: 100px; font-family: Helvetica,Arial,sans-serif; font-weight: bold;">Iphone(ipad) Appid:<br>
<input type="text" name="ipa_a" style="width: 300px;" value="<?php echo $row['ipad_appid']?>"></td>
</tr>
<tr align="center">
<td style="height: 28px;">
<button name="subup" type="submit">Edit</button>
</td>
</tr>
</form>
</table>
</div>
</div>
</div>
</div>
</div>
</body></html>
<?php
}
else
{
header("Location:notserver.php?l=fake");
}
?>
if anyone know..Please help me i will be very thankfull to him
Use the query:
UPDATE appid
set android_appid='$android_appid', iphone_appid='$iphone_appid', ipad_appid='$ipad_appid'
where u_name IN (select u_name from users where u_id = $_GET[id])
I wonder why you're using $_GET['id'] rather than $_POST['id'] like the other parameters in your script. Make sure that's correct. And you should check for errors from mysql_query(); if it returns false, print mysql_error() to see the reason.
I have a table which initially get filled while page loading.Now,I have a search button to filter the table where i have post function to filter the search results but it is loading every-time i search through the text-box which is not good.I need a ajax or J son or JavaScript code to load the grid each time it is searched.
My table:
<table align="center" class="sortable" border="1" width="900px">
<tr >
<td class="sorttable_nosort" style=" font-weight:bold; text-align:center">Select</td>
<td class="sorttable_nosort" style=" font-weight:bold; text-align:center">Action</td>
<td style=" font-weight:bold;">Product Code</td>
<td style=" font-weight:bold;">Warranty Periods In Months</td>
<td style=" font-weight:bold;">ProRata Period In Months </td>
<td style=" font-weight:bold;">Manufacturer Date</td>
<td style=" font-weight:bold;">Applicable Form Date</td></tr>
<?php
// This while will loop through all of the records as long as there is another record left.
while( $record = mysql_fetch_array($query))
{ // Basically as long as $record isn't false, we'll keep looping.
// You'll see below here the short hand for echoing php strings.
// <?=$record[key] - will display the value for that array.
?>
<tr>
<td bgcolor="#FFFFFF" style=" font-weight:bold; text-align:center"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $record['ProductCode']."~".$record['ManufactureDate']; ?>"></td>
<td bgcolor="#FFFFFF" style=" font-weight:bold; text-align:center"> <a style="color:#FF2222" name="edit" href="productwarrantymaster.php?<?php if(($row['editrights'])=='Yes') { echo 'ProductCode='; echo $record['ProductCode'];echo '&ManufactureDate=';echo $record['ManufactureDate'];} else echo 'permiss'; ?>">Edit</a></td>
<td bgcolor="#FFFFFF"><?=$record['ProductCode']?> </td>
<td bgcolor="#FFFFFF" ><?=$record['WarrantyPeriod']?></td>
<td bgcolor="#FFFFFF"> <?=$record['ProRataPeriod']?> </td>
<td bgcolor="#FFFFFF" > <?=$record['ManufactureDate']?> </td>
<td bgcolor="#FFFFFF" > <?=$record['ApplicableFormDate']?> </td></tr>
<?php
}
?>
</table>
I have used the pagination code too to fill the grid which is also added here.
My POST function:
if(isset($_POST['Search']))
{
if(isset($_POST['codes'])||isset($_POST['names']))
{
if(empty($_POST['codes'])&&empty($_POST['names']))
{
?>
<script type="text/javascript">
alert("Enter text Field!!");document.location='productwarrantymaster.php';
</script>
<?
}
else
{
if(!empty($_POST['codes'])&&!empty($_POST['names']))
{
$condition="SELECT * FROM productwarranty WHERE ProductCode like'%".$_POST['codes']."%' AND ManufactureDate like'".
$_POST['names']."%'";
}
else if(!empty($_POST['codes'])&&empty($_POST['names']))
{
$condition="SELECT * FROM productwarranty WHERE ProductCode like'%".$_POST['codes']."%'";
}
else if(!empty($_POST['names'])&&empty($_POST['codes']))
{
$condition="SELECT * FROM productwarranty WHERE ManufactureDate like'".$_POST['names']."%'";
}
else
{
$condition="SELECT * FROM productwarranty WHERE 1";
}
$refer=mysql_query($condition);
$myrow1 = mysql_num_rows($refer);
//mysql_fetch_array($query);
$page = (int) (!isset($_GET["page"]) ? 1 : $_GET["page"]);
$limit = 10;
$startpoint = ($page * $limit) - $limit;
//to make pagination
$statement = "productwarranty";
//show records
$starvalue = $myrow1;
$query = mysql_query("{$condition} LIMIT {$startpoint} , {$limit}");
if($myrow1==0)
{
?>
<script type="text/javascript">
alert("Entered keyword not found!!");document.location='productwarrantymaster.php';
</script>
<?
}
}
}
}
My Search Table:
<div style="width:80px; height:30px; float:left; margin-left:3px; margin-top:16px;" >
<label>Product Code</label>
</div>
<div style="width:145px; height:30px; float:left; margin-left:3px; margin-top:16px;">
<input type="text" name="codes" value=""/>
</div>
<!--Row1 end-->
<!--Row2 -->
<div style="width:80px; height:30px; float:left; margin-left:3px; margin-top:9px;">
<label>Manufacturer Date</label>
</div>
<div style="width:145px; height:30px; float:left; margin-left:3px; margin-top:16px;" >
<input type="text" id="searchdate" name="names" value=""/>
</div>
<!--Row2 end-->
<div style="width:83px; height:32px; float:left; margin-top:16px;">
<input type="submit" name="Search" value="" class="button1"/>
</div>
Kindly help me out for this issue.
Thanks in Advance:P
jQuery is very good at loading data
This is the general direction you can go to achieve this:
Modify your php to output JSON: http://php.net/manual/en/function.json-encode.php
The php script stands alone. Calling the script by itself in the browser will print the JSON to the screen. jQuery will call this script and gather the output.
Remove the existing table: (Something like this) $('#mytable').remove();
Clear the table from the front-side. In the next step you will add a new one.
Getting the JSON:: http://api.jquery.com/jQuery.getJSON/
The link above shows how to call the php file and parse the JSON
Rebuild the table with jQuery. The link above also shows how to output data.