Warning: mssql_execute(): message: Could not find stored procedure - php

I have wasted a day almost to solve this but not able to find solution. I am stuck in MSSQL procedure with php. i have a form of 5 fields which return a "Amount" when calculate. The Procedure is working perfectly on SQl Managemant 2008 but it display an error while execute from php code. Please help me please below my code and screenshot.
<div id="middle_pane">
<div>
<div id="inner_pane">
<div id="center_pane">
<div id="center_inner_pane">
<div class="txt_content">
<table width="385" height="200" style=" border:2px solid silver" cellpadding="6px" cellspacing="0px" align="center" border="0">
<form method="POST" action="<?php bloginfo('url');?>/fedex-tariff">
<tr>
<td colspan="2" style="background:#0066FF; color:#FFFFFF; fontsize:50px">Fedex Rate Card</td></tr>
<tr>
<td>Origin</td>
<td>
<select name="origin" id="origin" onChange="">
<option value="pakistan">Pakistan</option>
</select>
</td>
</tr>
<tr>
<td>Select Origin city </td>
<td>
<select name="city_id" id="city_id">
<option value="">--SELECT CITY--</option>
<?php
$city = "select * from branches";
$city_query = mssql_query($city);
while ($row_city = mssql_fetch_array($city_query)){
?>
<option value="<?php echo $row_city['zoneCode'];?>"> <?php echo $row_city['name']; ?></option>
<?php } ?>
</select>
</td>
</tr>
<tr>
<td>Select Destination </td>
<td>
<select name="country_id" id="country_id">
<option value="">--SELECT Destination--</option>
<?php
$service= "select * from country";
$service_query= mssql_query($service);
while ($row_service = mssql_fetch_array($service_query)){
?>
<option value="<?php echo $row_service['Code'];?>"> <?php echo $row_service['Name']; ?></option>
<?php } ?>
</select>
</td>
</tr>
<tr>
<td> Selection of Weight </td>
<td>
<div id="wgt">
<input type="text" id="weight" name="weight" value="" placeholder="weight...." required="">
</div>
</td>
</tr>
<tr>
<td>Select Your Service</td>
<td>
<select name="service_id" id="service_id">
<option value="">--SELECT--</option>
<?php
$service_type = "SELECT distinct ServiceTypeId from dbo.IntlZoneCountry where ServiceTypeId IN ('FedEx Cash Tariff Docs','FedEx Box','FedEx Student Package')";
$res_type = mssql_query($service_type);
$cnt_type = mssql_num_rows($res_type);
while($row_type = mssql_fetch_array($res_type)){
?>
<option value="<?php echo $row_type['ServiceTypeId'];?>"><?php echo $row_type['ServiceTypeId'];?></option>
<?php } ?>
</select>
</td>
</tr>
<tr>
<td> <input type="submit" value="Calculate" name="submit" class="btn"></td>
</tr>
</form>
<table width="385" style=" border:2px solid silver" cellpadding="6px" cellspacing="0px" align="center" border="0">
<tr>
<td>
<?php
if(isset($_POST['submit']))
{
$city_id = $_POST['city_id'];
$country_id = $_POST['country_id'];
$service_id = $_POST['service_id'];
$weight_id = $_POST['weight'];
//This is PHP validation
if(empty($city_id) || empty($country_id) || empty($service_id) || empty($weight_id)){
?><center><?php echo "Please filled all the fields first.";?></center>
<?php
}
else{
$tozoneCode = "Select ZoneCode from dbo.IntlZoneCountry where CountryCode= '$country_id' AND ServiceTypeId= '$service_id'";
$result_tozoneCode = mssql_query($tozoneCode,$conn);
while($row = mssql_fetch_assoc($result_tozoneCode)){
$toZone = $row['ZoneCode'];
}
$result = mssql_query('set ANSI_NULL_DFLT_ON ON',$conn);
$stmt = mssql_init('SP_UpdateCNPrice_Int_Tariff',$conn);
echo "<pre>";
print_r($stmt);
//$weight_id = '5';$city_id = '3';$toZone = 'D';$service_id = 'fedex';$gstPercent='12.2';
mssql_bind($stmt, '#weight', $weight_id, SQLVARCHAR);
mssql_bind($stmt, '#FromZone', $city_id, SQLVARCHAR);
mssql_bind($stmt, '#ToZone', $toZone, SQLVARCHAR);
mssql_bind($stmt, '#serviceType', $service_id, SQLVARCHAR);
// $outVar1 = '';
//$outVar2 = '';
// mssql_bind($stmt, '#amount', $outVar1, SQLVARCHAR);
//mssql_bind($stmt, '#gst', $outVar2, SQLVARCHAR);
//$proc_result = mssql_execute($stmt, true);
if ($proc_result = mssql_execute($stmt)){
while ($row = mssql_fetch_assoc($proc_result)){
echo $row["amount"];
}
}
die("<BR>".mssql_get_last_message());
//print($outVar1);
//print($outVar2);
mssql_close($conn);
// $proc = mssql_init("[SP_UpdateCNPrice_Int_Tariff] '$weight_id','$city_id','$toZone','$service_id'", $conn);
//$result = mssql_execute($proc);
//print_r($result);
/*while($row = mssql_fetch_assoc($result)){
//print_r($row);
?>
</td>
</tr>
<tr style="background:#00CFFF; color:blue;">
<td>
<center>
<font size="3">
<?php
$val = $row['amount'];
$gst = $row['gst'];
echo "<strong>"."Rate : "."$".""." ".$val.$gst;
?>
</font>
</center>
</td>
</tr>
<tr style="background:#00CFFF; color:blue;">
<td><center> All Rates are Exclusive of 16% GST + 23% fuel Charges (FSC).</center> </td>
</tr>
<?php
}*/
}
}
// mssql_close();
?>
</table>
</div>
</br>
<font size="2"><center>For more details <strong>Contact Us</strong> at any time.</center></font>
<div style="float:right;"></div>
</div>
</div>
</div>
</div>
</div>
Rate Card Front end display
MSSQL MANAGEMENT SCREENSHOT

I was just having an identical problem to this.
My PHP -> MSSQL stored procs had been working properly previously, and then, something changed in the environment, and all of a sudden the code stopped working.
I switched from using:
$proc = mssql_init('storedProceedureName', $connection );
mssql_execute($proc);
to using
mssql_query( 'EXEC storedProceedureName', $connection );
And all of a sudden it started working again. Not really sure why that's the case, but I'm not about to look a gift horse in the mouth.

Related

Is it Malicious php Code? php.var.function.14

I scanned my site with WP Antivirus Site Protection and found an infected file.
This file is a main file in my site template.
Malware Type: php.var.function.14
Is this malicious code? If so, please suggest how to prevent the malicious activity.
Can anyone, please, advise what this php code will do?
Here is the code:
<?php
add_action( 'admin_menu', 'register_header_adv_page' );
function register_header_adv_page(){
add_submenu_page( 'wb_add_adv','wb_header_adv', 'تبلیغات هدر', 'manage_options', 'wb_header_adv','wb_header_adv' );
}
//---------------------------------------------------
function wb_header_adv(){
global $wpdb;
//------------------------add--------------------
if(isset($_POST['add_header_btn'])){
$date=date("Y-m-d H:i:s");
if($_POST['H1']=='update'){
$wpdb->query("update ".$wpdb->prefix."softadv set advid='".$_POST['h1r_adv_id']."', showadv='".$_POST['show_header1']."' where location='H1R'");
$wpdb->query("update ".$wpdb->prefix."softadv set advid='".$_POST['h1l_adv_id']."',showadv='".$_POST['show_header1']."' where location='H1L'");
} else{
$location="H1R";
$wpdb->query("insert into ".$wpdb->prefix."softadv (date,showadv,type,location,advid) values('".$date."','".$_POST['show_header1']."','img','".$location."','".$_POST['h1r_adv_id']."')");
$location="H1L";
$wpdb->query("insert into ".$wpdb->prefix."softadv (date,showadv,type,location,advid) values('".$date."','".$_POST['show_header1']."','img','".$location."','".$_POST['h1l_adv_id']."')");
}
$date=date("Y-m-d H:i:s");
if($_POST['H2']=='update'){
$wpdb->query("update ".$wpdb->prefix."softadv set advid='".$_POST['h2r_adv_id']."', showadv='".$_POST['show_header2']."' where location='H2R'");
$wpdb->query("update ".$wpdb->prefix."softadv set advid='".$_POST['h2l_adv_id']."',showadv='".$_POST['show_header2']."' where location='H2L'");
} else{
$location="H2R";
$wpdb->query("insert into ".$wpdb->prefix."softadv (date,showadv,type,location,advid) values('".$date."','".$_POST['show_header2']."','img','".$location."','".$_POST['h2r_adv_id']."')");
$location="H2L";
$wpdb->query("insert into ".$wpdb->prefix."softadv (date,showadv,type,location,advid) values('".$date."','".$_POST['show_header2']."','img','".$location."','".$_POST['h2l_adv_id']."')");
}
$date=date("Y-m-d H:i:s");
if($_POST['H3']=='update'){
if($_POST['h3_type']=="slider"){
$advids = serialize($_POST['h3r_adv_id']);
}else{
$advids = $_POST['h3r_adv_id'];
}
$wpdb->query("update ".$wpdb->prefix."softadv set advid='".$advids."', showadv='".$_POST['show_header3']."',type='".$_POST['h3_type']."' where location='H3R'");
} else{
$location="H3R";
if($_POST['h3_type']=="slider"){
$advids = serialize($_POST['h3r_adv_id']);
}else{
$advids = $_POST['h3r_adv_id'];
}
$wpdb->query("insert into ".$wpdb->prefix."softadv (date,showadv,type,location,advid) values('".$date."','".$_POST['show_header3']."','".$_POST['h3_type']."','".$location."','".$advids."')");
}
}
//-----------------------select------------------
$h1r_adv = $wpdb->get_row( "SELECT showadv,advid FROM ".$wpdb->prefix."softadv where location='H1R'");
$header1_showadv=$h1r_adv->showadv;
$h1r_id=$h1r_adv->advid;
//------------
$h1l_adv = $wpdb->get_row( "SELECT showadv,advid FROM ".$wpdb->prefix."softadv where location='H1L'");
$h1l_id=$h1l_adv->advid;
//----------
$h2r_adv = $wpdb->get_row( "SELECT showadv,advid FROM ".$wpdb->prefix."softadv where location='H2R'");
$header2_showadv=$h2r_adv->showadv;
$h2r_id=$h2r_adv->advid;
//------------
$h2l_adv = $wpdb->get_row( "SELECT showadv,advid FROM ".$wpdb->prefix."softadv where location='H2L'");
$h2l_id=$h2l_adv->advid;
//----------
$h3r_adv = $wpdb->get_row( "SELECT showadv,advid,type FROM ".$wpdb->prefix."softadv where location='H3R'");
$header3_showadv=$h3r_adv->showadv;
$h3r_id=$h3r_adv->advid;
$h3r_type=$h3r_adv->type;
//------------
?>
<h3>پلن 1</h3>
<form method="post">
<div class="line"></div>
<table>
<tr>
<td colspan="2">
<label><input type="checkbox" name="show_header1" value="1" <?php if($header1_showadv) echo 'checked'; ?> />نمایش</label>
</td>
</tr>
<tr>
<td>
تبلیغات سمت راست :
</td>
<td>
<select name="h1r_adv_id">
<option>انتخاب تبلیغ</option>
<?php show_img_adv_list_in_select('header',$h1r_id,'img') ?>
</select>
</td>
</tr>
<tr>
<td>
تبلیغات سمت چپ :
</td>
<td>
<select name="h1l_adv_id">
<option>انتخاب تبلیغ</option>
<?php show_img_adv_list_in_select('header',$h1l_id,'img') ?>
</select>
</td>
</tr>
</table>
<h3>پلن 2</h3>
<div class="line"></div>
<table>
<tr>
<td colspan="2">
<label><input type="checkbox" name="show_header2" value="1" <?php if($header2_showadv) echo 'checked'; ?> />نمایش</label>
</td>
</tr>
<tr>
<td>
تبلیغات سمت راست :
</td>
<td>
<select name="h2r_adv_id">
<option>انتخاب تبلیغ</option>
<?php show_img_adv_list_in_select('header',$h2r_id,'img') ?>
</select>
</td>
</tr>
<tr>
<td>
تبلیغات سمت چپ :
</td>
<td>
<select name="h2l_adv_id">
<option value="">انتخاب تبلیغ</option>
<?php show_img_adv_list_in_select('header',$h2l_id,'img') ?>
</select>
</td>
</tr>
</table>
<h3>پلن 3</h3>
<div class="line"></div>
<table>
<tr>
<td colspan="2">
<label><input type="checkbox" name="show_header3" value="1" <?php if($header3_showadv) echo 'checked'; ?> />نمایش</label>
</td>
</tr>
<tr>
<td colspan="2">
<select name="h3_type" class="h3_type">
<option <?php if($h3r_type=="img") echo "selected"; ?> value="img">بنر</option>
<option <?php if($h3r_type=="slider") echo "selected"; ?> value="slider">اسلایدر</option>
</select>
</td>
</tr>
<tr>
<td>
تبلیغات سمت راست :
</td>
<td>
<select <?php if($h3r_type=="slider"){ echo 'name="h3r_adv_id[]" multiple';} else if($h3r_type=="img") echo 'name="h3r_adv_id"'; ?> class="h3r_adv_id">
<option>انتخاب تبلیغ</option>
<?php show_img_adv_list_in_select('header',$h3r_id,$h3r_type) ?>
</select>
</td>
</tr>
<tr>
<td>
<input type="submit" value="ذخیره" name="add_header_btn" class="button-primary add_h_adv_btn" />
</td>
<td></td>
</tr>
</table>
<input type="hidden" value="<?php if ( null !== $h1r_adv ) { echo "update"; } ?>" name="H1" />
<input type="hidden" value="<?php if ( null !== $h2r_adv ) { echo "update"; } ?>" name="H2" />
<input type="hidden" value="<?php if ( null !== $h3r_adv ) { echo "update"; } ?>" name="H3" />
</form>
<?php
}
//--------------------------------------------------

update php&mysql : undefined index

I'm now making reservation system, and something is wrong with updating data. I made table updateMy_ReservationView.php like this.
this is an image of SelectMy_ReservationView.php I have an error with insert more codes because of this editor's error message.
<?php
include "connection.php";
$id=$_GET['reservation_id'];
$sql = "select reservation.*, customer.*, car_type.*, datediff(return_time,
rent) as total_day, (datediff(return_time, rent) * price ) AS total_price
FROM
reservation, customer, car_type
WHERE reservation.car_type_id=car_type.car_type_id AND
reservation.customer_id=customer.customer_id and reservation_id='$id' order
by reservation_id ";
$result = mysqli_query($conn, $sql);
$row = mysqli_fetch_assoc($result);
$sql_car = "SELECT car_type.* from car_type";
$result_car = mysqli_query($conn, $sql_car);
?>
<h3><b>Update Reservation</b></h3><br>
<form method = "post" action = "?page=updateMy_ReservationDo">
<table class="table table-striped table-sm"
style="width:500px; height:200px;">
<tr>
<td>Customer Name</td>
<td>
<?php echo" $row[customer_name]";?>
<input type = "hidden" name="reservation_id" value="
<?php echo"$row[reservation_id]";?>">
</td>
</tr>
<tr>
<td>Old car type</td>
<td>
<?php echo" $row[car_type]";?>
</td>
</tr>
<tr>
<td>New Car Type (Price USD)</td>
<td>
<select name = "car_type">
<?php
while($row_car = mysqli_fetch_assoc($result_car)) {
?>
<option value="<?php echo"$row_car[car_type_id]";?>">
<?php echo"$row_car[car_type] ($row_car[price])";?></option>
<?php
}
?>
</select>
</td>
</tr>
<tr>
<td>Old Rent</td>
<td><?php echo "$row[rent]"; ?></td>
</tr>
<tr>
<td>Rent</td>
<td><input type="text" name="rent" id="rent"
maxlength="25" size="25"/>
<img src="images_date/cal.gif" alt=""
onclick="javascript:NewCssCal('rent','yyyyMMdd','arrow',false,'24',false)"
style="cursor:pointer"/></td>
</tr>
<tr>
<td>Old Return</td>
<td><?php echo "$row[return_time]"; ?></td>
</tr>
<tr>
<td>Return</td>
<td><input type="text" name="return_time"
id="return_time" maxlength="25" size="25"/>
<img src="images_date/cal.gif" alt=""
onclick="javascript:NewCssCal('return_time','yyyyMMdd'
'arrow',false,'24',false)" style="cursor:pointer"/></td>
</tr>
<tr>
<td>Old Pickup Station</td>
<td><?php echo "$row[car_station]"; ?></td>
</tr>
<tr>
<td>Pickup Station</td>
<td>
<select name = "car_station">
<option value="Yeouido">Yeouido</option>
<option value="Shinchon">Shinchon</option>
<option value="Jongro">Jongro</option>
<option value="Seoul Station">Seoul
Station</option>
<option value="Gangnam">Gangnam</option>
<option value="Geondae">Geondae</option>
</select></td>
</tr>
<tr>
<td> </td>
<td><input type="reset" value="Reset"> <input name = "add" type = "submit" value = "Update Reservation">
</td>
</tr>
</table>
And I made updating function file updateMy_ReservationDo.php like below.
include "connection.php";
$reservation_id=$_POST['reservation_id'];
$car_type=$_POST['car_type_id'];
$rent=$_POST['rent'];
$return_time=$_POST['return_time'];
$car_station=$_POST['car_station'];
$sql = "update reservation set car_type='$car_type_id',rent='$rent',
return_time='$return_time' and car_station='$car_station' where
reservation_id=$reservation_id ";
if (mysqli_query($conn, $sql)) {
echo "Reservation is updated successfully<br>";
echo "<p><p><a href=?page=selectMy_reservationView><button type=button>Show
all reservation</button></a>";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
mysqli_close($conn);
?>
Then Error message like this happen:
Notice: Undefined index: car_type_id in C:\xampp\htdocs\rentcar\updateMy_ReservationDo.php on line 5
Notice: Undefined variable: car_type_id in C:\xampp\htdocs\rentcar\updateMy_ReservationDo.php on line 10
Error: update reservation set car_type='',rent='2018-05-31', return_time='2018-06-01' and car_station='Shinchon' where reservation_id=17
Unknown column 'car_type' in 'field list'
What should I modify?
Use isset like following :
$reservation_id = isset($_POST['reservation_id']) ? $_POST['reservation_id'] : '';
$car_type = isset($_POST['car_type_id']) ? $_POST['car_type_id'] : '';
$rent = isset($_POST['rent']) ? $_POST['rent'] : '';
$return_time = isset($_POST['return_time']) ? $_POST['return_time'] : '';
$car_station = isset($_POST['car_station']) ? $_POST['car_station'] : '';
and your defined variable is $car_type but you used in your sql query $car_type_id
use :
$car_type
and make sure car_type field exists in your table
Change the name of car_type to car_type_id.The error is due to you are sending car_type and accessing car_type_id in updateMy_ReservationDo.php.
<?php
include "connection.php";
$id=$_GET['reservation_id'];
$sql = "select reservation.*, customer.*, car_type.*, datediff(return_time,
rent) as total_day, (datediff(return_time, rent) * price ) AS total_price
FROM
reservation, customer, car_type
WHERE reservation.car_type_id=car_type.car_type_id AND
reservation.customer_id=customer.customer_id and reservation_id='$id' order
by reservation_id ";
$result = mysqli_query($conn, $sql);
$row = mysqli_fetch_assoc($result);
$sql_car = "SELECT car_type.* from car_type";
$result_car = mysqli_query($conn, $sql_car);
?>
<h3><b>Update Reservation</b></h3><br>
<form method = "post" action = "?page=updateMy_ReservationDo">
<table class="table table-striped table-sm"
style="width:500px; height:200px;">
<tr>
<td>Customer Name</td>
<td>
<?php echo" $row[customer_name]";?>
<input type = "hidden" name="reservation_id" value="
<?php echo"$row[reservation_id]";?>">
</td>
</tr>
<tr>
<td>Old car type</td>
<td>
<?php echo" $row[car_type]";?>
</td>
</tr>
<tr>
<td>New Car Type (Price USD)</td>
<td>
<select name = "car_type_id">
<?php
while($row_car = mysqli_fetch_assoc($result_car)) {
?>
<option value="<?php echo"$row_car[car_type_id]";?>">
<?php echo"$row_car[car_type] ($row_car[price])";?></option>
<?php
}
?>
</select>
</td>
</tr>
<tr>
<td>Old Rent</td>
<td><?php echo "$row[rent]"; ?></td>
</tr>
<tr>
<td>Rent</td>
<td><input type="text" name="rent" id="rent"
maxlength="25" size="25"/>
<img src="images_date/cal.gif" alt=""
onclick="javascript:NewCssCal('rent','yyyyMMdd','arrow',false,'24',false)"
style="cursor:pointer"/></td>
</tr>
<tr>
<td>Old Return</td>
<td><?php echo "$row[return_time]"; ?></td>
</tr>
<tr>
<td>Return</td>
<td><input type="text" name="return_time"
id="return_time" maxlength="25" size="25"/>
<img src="images_date/cal.gif" alt=""
onclick="javascript:NewCssCal('return_time','yyyyMMdd'
'arrow',false,'24',false)" style="cursor:pointer"/></td>
</tr>
<tr>
<td>Old Pickup Station</td>
<td><?php echo "$row[car_station]"; ?></td>
</tr>
<tr>
<td>Pickup Station</td>
<td>
<select name = "car_station">
<option value="Yeouido">Yeouido</option>
<option value="Shinchon">Shinchon</option>
<option value="Jongro">Jongro</option>
<option value="Seoul Station">Seoul
Station</option>
<option value="Gangnam">Gangnam</option>
<option value="Geondae">Geondae</option>
</select></td>
</tr>
<tr>
<td> </td>
<td><input type="reset" value="Reset"> <input name = "add" type = "submit" value = "Update Reservation">
</td>
</tr>
</table>

How to display selected value Form drop down list?

I have a list proxy.Once I select and save it I want to display the selected data. How can I do this?.I want to display it in selected list and once I reload or get back to that page `
<?php
include_once("../noaccess.php");
include_once(CLASS_PATH."fetch_service.php");
$objfetch = new fetchService();
include_once(CLASS_PATH."proxy.php");
$objproxy = new Proxy();
include_once(CLASS_PATH."log.php");
$objlog= new changelog();
$account_id=$_SESSION['account_id'];
global $mysqli;
if($_POST['submit']=="Save")
{
$pname=$_POST['proxy'];
$query="UPDATE `proxy` SET `proxy_default`='1' where `proxyname`='$pname'";
$mysqli->query($query) or die($mysqli->error);
$_SESSION['check_update'] = "1";
setcookie("msg","Proxy Seleted",time()+5,"/");
header("location:".SITE_URL."index.php?view=default_proxy");
}
?>
<form name="frmcr" id="frmcr" action="" method="post" enctype="multipart/form-data">
<input type="hidden" name="mode" id="mode" value="insert" />
<table align="left" id="tblworking_hours" class="tbl_altcolor shadow" style="width:25%;margin-left:30px">
<thead>
<tr>
<th align="center"><b>Proxy</b></th>
<td><select name="proxy" id="proxy" class="required input">
<option value="">Select</option>
<!-- <option value="<?php echo $i ;?>"<?php echo $i==$ring21 ? "selected":"";?> ><?php echo $i;?></option> -->
<?php
$result = $objfetch->fetch_proxy("*","where account_id='".$_SESSION['account_id']."' ");
foreach($result as $key=>$resrproxy)
{
?>
<option value="<?php echo $resrproxy['proxyname'];?>"<?php echo $resrproxy['proxyname']== $resrproxy['proxyname'] ? "selected":"";?>><?php echo $resrproxy['proxyname'];?></option>
<?php } ?>
</select></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" name="submit" id="submit" value="Save" class="btn" style="margin-left:35px;"/></td>
</tr>
</thead>
</table>
</div>
You've to compare $resrproxy['proxyname'] value with $pname. Your code should be like this:
// your code
<select name="proxy" id="proxy" class="required input">
<option value="">Select</option>
<?php
$result = $objfetch->fetch_proxy("*","where account_id='".$_SESSION['account_id']."' ");
foreach($result as $key=>$resrproxy){
$option = "<option value=\"{$resrproxy['proxyname']}\"";
if(isset($pname)){
if($pname == $resrproxy['proxyname']){
$option .= " selected=\"selected\"";
}
}
$option .= ">{$resrproxy['proxyname']}</option>";
echo $option;
}
?>
</select>
// your code `
<td>
<select name="proxy" id="proxy" class="required input">
<option value="">Select</option>
<?php
$result = $objfetch->fetch_proxy("*","where account_id='".$_SESSION['account_id']."' and `proxy_default`='1'");
$pname=$result[0]['proxyname'];
$result = $objfetch->fetch_proxy("*","where account_id='".$_SESSION['account_id']."' ");
foreach($result as $key=>$resrproxy)
{
?>
<option value="<?php echo $resrproxy['proxyname'];?>"<?php echo $resrproxy['proxyname']==$pname ? "selected":"";?>><?php echo $resrproxy['proxyname'];?></option>
<?php } ?>
</select>
</td>

SQL statement to populate more than one listbox at a time

I'm trying to allow a user to specify how many rows they would like to add to the order form for the customer's purchase. This allows the user to have as many rows as needed for purchasing products rather than having a set list. I have the functionality working properly, where if you type in 3 and submit, it will give you three rows to enter in product order information.
The problem I am running into is where I am populating a listbox with the product id and name for the user to select. It populates the first row's list box, but the following list boxes only get the " - " and not the $row[] values. It seems like it's not passing in the sql statement anymore, why is this?
This is the area in my code where I'm running into a problem with the functionality:
<?
if (isset($_POST['update']))
{
//Execute this code if the update button is clicked.
$num = $_POST['rows'];
for ($i=0; $i<$num; $i++) { ?>
<tr>
<td class="inputCol2">
<select name="'product<?= $i ?>">
<option value="selectProduct">Select Product</option>
<!-- Populate listbox with Product ID and Product Name -->
<?
do { ?>
<option value="<?= $row[0]; ?>"><?= $row[0] . " - " . $row[2]; ?></option>
<? } while($row = mysqli_fetch_array($result)) ?>
</select>
</td>
<td class="inputCol2"><input type="text" name="'quantity<?= $i ?>" ></td>
<td class="inputCol2">$<input type="text" name="'unit<?= $i ?>" value=""></td>
<td class="inputCol2">$<input type="text" name="'total<?= $i ?>" value="" ></td>
</tr>
<? } ?>
And this is my entire code:
<?
connectDB();
$sql = "SELECT * FROM product";
$sql2 = "SELECT DISTINCT emp_id, emp_fname, emp_lname FROM employee";
$sql3 = "SELECT DISTINCT status_id FROM salesorder ORDER BY status_id asc";
$sql4 = "SELECT * FROM salesorder ORDER BY order_id desc";
$result = mysqli_query($db, $sql) or die("SQL error: " . mysqli_error());
$result2 = mysqli_query($db, $sql2) or die("SQL error: " . mysqli_error());
$result3 = mysqli_query($db, $sql3) or die("SQL error: " . mysqli_error());
$result4 = mysqli_query($db, $sql4) or die("SQL error: " . mysqli_error());
$row = mysqli_fetch_array($result);
$row2 = mysqli_fetch_array($result2);
$row3 = mysqli_fetch_array($result3);
$row4 = mysqli_fetch_array($result4);
?>
<div id="order-wrap">
<form method="post" action="order.php">
<table class="orderInfo"><br>
<tr>
<th class="textCol">Product Rows:</th>
<td class="inputCol"><input type="text" name="rows"></td>
<td><input class="update" type="submit" name="update" value="Update"></td>
<td class="inputCol"></td>
</tr>
</table>
</form><!-- Order Rows -->
<form class="orderform" action ="order-report.php" METHOD = "post">
<h2>Order Form</h2>
<h3>Piedmont Furnishings</h3>
<img id="couch-img" src="couch.jpg" alt="couch">
<table class="orderInfo">
<tr>
<th class="textCol">Order Number:</th>
<td class="inputCol"><input type="text" name="orderNumber" value="<?= $row4[0] + 1; ?>" disabled></td>
<th class="textCol">Order Date:</th>
<td class="inputCol"><input type="text" name="orderDate" value="<?= date("Y-m-d") ?>"></td>
</tr>
<tr>
<th class="textCol">Customer:</th>
<td class="inputCol"><input type="text" name="customer"></td>
<td class="textCol"></td>
<td class="inputCol"></td>
</tr>
<tr>
<th class="textCol">Sales Agent:</th>
<td class="inputCol">
<select name="salesAgent">
<option value="selectAgent">Select One</option>
<!-- Populate listbox with Sales Agents ID -->
<?
do { ?>
<option value="<?= $row2[0]; ?>"><?= $row2[1] . " " . $row2[2]; ?></option>
<? } while($row2 = mysqli_fetch_array($result2)) ?>
</select>
</td>
<th class="textCol">Order Status:</th>
<td class="inputCol">
<select name="orderStatus">
<option value="selectStatus">Select One</option>
<!-- Populate listbox with Status ID -->
<?
do { ?>
<option value="<?= $row3[0]; ?>"><?= $row3[0] ?></option>
<? } while($row3 = mysqli_fetch_array($result3)) ?>
</select>
</td>
</tr>
</table>
<!-- Where the product rows input show go ??? -->
<table class="bottomTable">
<tr>
<th class="textCol">Product</th>
<th class="textCol">Quantity</th>
<th class="textCol">Unit Price</th>
<th class="textCol">Total Price</th>
</tr>
<?
if (isset($_POST['update']))
{
//Execute this code if the update button is clicked.
$num = $_POST['rows'];
for ($i=0; $i<$num; $i++) { ?>
<tr>
<td class="inputCol2">
<select name="'product<?= $i ?>">
<option value="selectProduct">Select Product</option>
<!-- Populate listbox with Product ID and Product Name -->
<?
do { ?>
<option value="<?= $row[0]; ?>"><?= $row[0] . " - " . $row[2]; ?></option>
<? } while($row = mysqli_fetch_array($result)) ?>
</select>
</td>
<td class="inputCol2"><input type="text" name="'quantity<?= $i ?>" ></td>
<td class="inputCol2">$<input type="text" name="'unit<?= $i ?>" value=""></td>
<td class="inputCol2">$<input type="text" name="'total<?= $i ?>" value="" ></td>
</tr>
<? } ?>
<tr>
<td class="textCol"></td>
<td class="textCol"></td>
<td class="textCol">Total Order:</td>
<td class="inputCol2">$<input type="text" name="totalfinal"></td>
</tr>
<input class="submit" type="submit" value="Submit" name="orderSubmit"/>
</table>
</form>
<? } else {?>
<tr>
<td class="textCol"></td>
<td class="textCol"></td>
<td class="textCol">Total Order:</td>
<td class="inputCol2">$<input type="text" name="totalfinal"></td>
</tr>
<input class="submit" type="submit" value="Submit" name="orderSubmit"/>
</table>
</form>
<? } ?>
<?
mysqli_free_result($result);
mysqli_close($db);
?>
</div>
the problem with your code is for first iteration while($row = mysqli_fetch_array($result)) the internal pointer of $result reached at the end... so for next iteration $i=1 there is nothing in the $result but As you use do-while loop the loop must run at least one time and $row[0] & $row[2] is null so you get only "-" . to fix the problem you need to change code slightly.
remove this line $row = mysqli_fetch_array($result);
and add
$options = '<option value="selectProduct">Select Product</option>';
while($row = mysqli_fetch_array($result,MYSQLI_NUM)){
$options .= '<option value="'.$row[0].'">'.$row[0].' - '.$row[1].'</option>';
}
then change like this inside for loop :
<td class="inputCol2">
<select name="'product<?= $i ?>">
<?php
echo $options;
?>
</select>
</td>

Comparison and data extraction with PHP, MySQL, JS

I have a database, golf_add.php and ajax_price.php Files.
So I can not do this:
After I choose values from form like > From | To | Transfer Type | Golf Date option box fields, I want these fields' values are compared and select the appropriate data from database (for golf price value) into Golf Price textBox.
For example:
From: XXX Otel (id=15)To: YYY Place(id=25)Transfer Type: Shuttle (id=4)Golf Date: 2015/08/05
After I choose these values from form I want to click refresh button OR after I selected the Golf Date last step its automatically must get only price from correct row according to my selection as above..
You can preview my form here :
golf_add.php code:
<!-- OTHER CODES ... -->
<script>
function refreshforprice() {
jQuery.ajax({
type: 'GET',
url: 'ajax_price.php',
data: 'tid='+jQuery('#op_transfer_type_id').val()+'&p='+jQuery('#operation_pax').val()+'&p2='+jQuery('#operation_pax2').val()+'&v=1',
cache : false,
success: function(sonuc){
sonucx = sonuc.split(';');
jQuery('#sold_tour_price_auto').val(sonucx[0]+'.00');
jQuery('#xprice1').html('* '+sonucx[1]+'.00 €');
jQuery('#xprice2').html('* '+sonucx[2]+'.00 €');
}
});
}
</script>
<form method="POST" action="golf_add.php" name="adminForm" id="adminForm">
<table class="adminlist">
<thead>
<tr>
<th> GOLF DETAILS </th>
</tr>
</thead>
</table>
<table class="adminlist">
<tbody>
<?PHP $i = 0; ?>
<tr class="<?php $i++; $m=$i%2; if($m=='1') echo "row0"; else echo "row1";?>">
<td align="right"><b>From</b></td>
<td id="fromarea">
<select size="1" name="operation_pickup_from" id="operation_pickup_from">
<option value="-1" disabled selected> --- Select Pick Up Point --- </option>
<?php
$strSQL2 = "SELECT * FROM pickup_points_From WHERE region_id='".$regionidx."' soldtours='1' ORDER BY pickup_point_name ASC";
$resultSQL2 = mysql_query($strSQL2);
$ks = mysql_num_rows($resultSQL2);
for ($z=0; $z<$ks; $z++) {
$rowSQL2 = mysql_fetch_array($resultSQL2);
?><option value="<?=$rowSQL2['pickup_point_id']?>"><?=$rowSQL2['pickup_point_name']?></option><?
}
?>
</select>
</td>
</tr>
<tr class="<?php echo "row1";?>">
<td align="right"><b>To</b></td>
<td id="fromarea">
<select size="1" name="operation_pickup_to" id="operation_pickup_to">
<option value="-1" disabled selected> --- Select Drop Point --- </option>
<?php
$strSQL3 = "SELECT * FROM pickup_points_To WHERE region_id='".$regionidx."' AND soldtours='1' ORDER BY drop_point_name";
$resultSQL3 = mysql_query($strSQL3);
while($rowSQL3 = mysql_fetch_array($resultSQL3)) {
?>
<option value="<?=$rowSQL3['drop_point_id']?>"><?=$rowSQL3['drop_point_name']?></option>
<? } ?>
</select>
</td>
</tr>
<tr class="<?php $i++; $m=$i%2; if($m=='1') echo "row0"; else echo "row1";?>">
<td align="right"><b>Transfer Type</b></td>
<td id="tourtypes">
<select size="1" name="op_transfer_type_id" id="op_transfer_type_id">
<option value="-1" disabled selected> --- Select Transfer Type --- </option>
<?php
$strSQL2 = "SELECT * FROM operation_transfer_types WHERE op_transfer_type_id IN (4,10) ORDER BY op_transfer_type_name";
$resultSQL2 = mysql_query($strSQL2);
while($rowSQL2 = mysql_fetch_array($resultSQL2)) {
?><option value="<?=$rowSQL2['op_transfer_type_id']?>"><?=$rowSQL2['op_transfer_type_name']?></option><?
}
?>
</select>
</td>
</tr>
<tr class="<?php $i++; $m=$i%2; if($m=='1') echo "row0"; else echo "row1";?>">
<td width="45%" align="right"><b>Golf Date</b>»</td>
<td width="55%"><input type="text" name="operation_date" id="operation_date" value="<?=$_GET['selected_day']?>" size="10" class="datepicker" autocomplete="off"> <input type="text" name="operation_time" id="operation_time" size="5" class="timepicker" autocomplete="off">«<b>Golf Time</b></td>
</tr>
<tr class="<?php $i++; $m=$i%2; if($m=='1') echo "row0"; else echo "row1";?>">
<td align="right"><b>Adult</b></td>
<td><input type="text" name="operation_pax" id="operation_pax" size="5" value="1" onkeypress="return OnlyDigits(event);"
onblur="OnlyDigits(event,false)" autocomplete="off"> <span id="xprice1" style="color: green;">* 0.00 €. </span>
</tr>
<tr class="<?php $i++; $m=$i%2; if($m=='1') echo "row0"; else echo "row1";?>">
<td align="right" id="agex1"><b>06-12 Age</b></td>
<td><input type="text" name="operation_pax2" id="operation_pax2" size="5" value="0" onkeypress="return OnlyDigits(event);"
onblur="OnlyDigits(event,false)" autocomplete="off"> <span id="xprice2" style="color: green;">* 0.00 €. </span>
</td>
</tr>
<tr class="<?php $i++; $m=$i%2; if($m=='1') echo "row0"; else echo "row1";?>">
<td align="right"><b>Golf Price</b></td>
<td id="pricediv"><input type="text" name="sold_tour_price_auto" id="sold_tour_price_auto" size="8" class="bestupper"
value="0.00" onkeypress="return OnlyDigits(event,'.');" onblur="OnlyDigits(event,false)"> EUR
</td>
</tr>
</tbody>
</table>
</form>
<!-- OTHER CODES ... -->
ajax_price.php Code:
<?php
$tid = intval(#$_GET['tid']);
$p = intval(#$_GET['p']);
$p2 = intval(#$_GET['p2']);
$v = intval(#$_GET['v']);
$sql = "SELECT * FROM transfer_type WHERE transfer_id='".$tid."'";
$s = mysql_query($sql);
$ks = mysql_num_rows($s);
if ($ks > 0) {
$k = mysql_fetch_assoc($s);
$pprice = floatval($k['golf_price']);
if ($tid == 4) {
$price_pax = $p + $p2;
$price = ($price_pax * $pprice) + ($price_pax * 7);
}
else {
$price = ($pprice * $p) + ($pprice * $p2);
}
if ($v == 1) { echo $price.';'.$pprice.';'.$pprice; }
else { echo $price; }
?><?PHP
}
else {
if ($v == 1) { ?>0;0;0<?PHP }
else { ?>0<?PHP }
}
?>
I'm not too sure but I can't see where you are using the function refreshforprice() in your form, I have done similar using the function in a onchange in a <select> box.
eg <select id="something" name="something" onchange"function();">

Categories