My first page is owner details then I send id and show owner wise driver in driver details page if I select particular driver and show information in third page for select driver. In this page selected driver information show currently but when I perform update query so data not updated what I do. My problem is that show and update in same page and how to pass id of select item
<?php
include("config.php");
$d_idd = $_GET['d_id'];
$_SESSION['d_id'] = $d_idd;
$d_id = $_SESSION['d_id'];
//print_r("select * from tbl_multiple_driver where Id = '$d_id'");
die();
$driverUpdate = sqlsrv_query($conn,"select * from tbl_multiple_driver where Id = '$d_id'");
while($driverdetails = sqlsrv_fetch_array($driverUpdate)){
$id = $driverdetails['Id'];
$name = $driverdetails['driver_name'];
$mobile = $driverdetails['driver_mobile'];
$dob = $driverdetails['driver_birth_date'];
$address = $driverdetails['driver_address'];
$location = $driverdetails['location'];
$city = $driverdetails['city'];
$pincode = $driverdetails['driver_pincode'];
$pick_up_area = $driverdetails['PickUp_Area'];
$vehicle_no = $driverdetails['vehicle_reg_no'];
$vehicle_company = $driverdetails['V_id'];
$vehicle_module = $driverdetails['V_id'];
$user_name = $driverdetails['username'];
$reg_date = $driverdetails['reg_date'];
$vehicle = "SELECT * FROM Vehicle where id = '$vehicle_company'";
$vehicleDisplay = sqlsrv_query($conn,$vehicle);
while($vehicleDetails = sqlsrv_fetch_array($vehicleDisplay)){
$vehicleModel = $vehicleDetails['Vehicle_Model_id'];
}
$vehicleMod = "SELECT * FROM Vehicle_Modle where id = '$vehicleModel'";
$vehicleModDisplay = sqlsrv_query($conn,$vehicleMod);
while($vehicleModDetails = sqlsrv_fetch_array($vehicleModDisplay)){
$vehicleId = $vehicleModDetails['vehicle_id'];
$vehicleModName = $vehicleModDetails['vehicle_modle_Name'];
}
$Mainvehicle = "SELECT * FROM MainVehicle where id = '$vehicleId'";
$mainvehicleDisplay = sqlsrv_query($conn,$Mainvehicle);
while($mainvehicleDetails = sqlsrv_fetch_array($mainvehicleDisplay)){
$vehiclename = $mainvehicleDetails['vehicle_company'];
}
}
?>
<?php
if(isset($_POST['btnUpdate'])){
//$id = $_POST['Id'];
$dName = $_POST['txtDriverName'];
$dMobile = $_POST['txtMobileNumber'];
$dDob = $_POST['txtDob'];
$dAddress = $_POST['txtDriverAddress'];
$dLocation = $_POST['Location'];
$dCity = $_POST['city'];
$dPincode = $_POST['pincode'];
$dPickUp = $_POST['txtPickup'];
$dVehicleNo = $_POST['txtVehicleNo'];
//print_r("update tbl_multiple_driver set driver_name = '$dName',driver_mobile='$dMobile',driver_birth_date='$dDob',driver_address='$dAddress',location='$dLocation', city='$dCity',driver_pincode='$dPincode',PickUp_Area='$dPickUp', vehicle_reg_no='$dVehicleNo' where Id= '$id' "); die();
$driver_update = "update tbl_multiple_driver set driver_name = '$dName',driver_mobile='$dMobile',driver_birth_date='$dDob',driver_address='$dAddress',location='$dLocation', city='$dCity',driver_pincode='$dPincode',PickUp_Area='$dPickUp', vehicle_reg_no='$dVehicleNo' where Id= '$id' ";
$res = sqlsrv_query($conn,$driver_update);
if($res){
echo '<script language="javascript">';
echo 'window.location.href = Details.php';
echo '</script>';
}
// header('location:Details.php');
}
?>
On user select you have to pass id again and then update info on base of this id:
$driver_update = "update tbl_multiple_driver set driver_name = '$dName',
driver_mobile='$dMobile',driver_birth_date='$dDob',driver_address='$dAddress',
location='$dLocation', city='$dCity',driver_pincode='$dPincode',
PickUp_Area='$dPickUp', vehicle_reg_no='$dVehicleNo' where Id='".$isession['d_id']."' ";
Related
we have two tables name "students" AND vouchers. we create the voucher of the fee and display voucher, and we also want to display the roll no of that particular student which was we create voucher, but we can't get the roll any of student table ... we got error,enter image description here I've added the code below
<?php if(isset($_GET['session_id'])):?>
<?php $student_session= $_GET['session_id'];?>
<?php
$stu = "select * from students where
session_id='$student_session'";
$run_stu = mysqli_query($con,$stu);
while($row = mysqli_fetch_array($run_stu)){
$stu_id = $row['student_id'];
$stu_roll = $row['roll_no'];
$stu_name= $row['s_name'];
?>
<?php
if (isset($_POST['many_voucher'])){
$student_roll = $_GET['roll_no'];
$student_session_post = $_GET['session_id'];
$fee_date = $_POST['fee_date'];
$adm_fee = $_POST['adm_fee'];
$reg_fee = $_POST['reg_fee'];
$tution_fee = $_POST['tution_fee'];
$lab_fund = $_POST['lab_fund'];
$misc_dues = $_POST['misc_fund'];
$others = $_POST['others'];
$total_amount = $_POST['total_amount'];
$due_date = $_POST['due_date'];
$remarks = $_POST['remarks'];
$query = "Insert INTO vouchers(session_id,roll_no,fee_month,adm_fee,reg_fee,tution_fee,lab_fund,misc_dues,other_dues,total_amount,due_date,remarks)
VALUES('$student_session_post','$student_roll','$fee_date','$adm_fee','$reg_fee','$tution_fee','$lab_fund','$misc_dues','$others','$total_amount','$due_date','$remarks')";
if(mysqli_query($con,$query)){
//echo "<script>alert('Run')</script>";
}else{
echo"query failed";
}
}
?>
try with this
<?php if(isset($_POST['many_voucher'])){
$student_roll = $stu_roll;
}
?>
I have a table named collection and has columns like title,author,edition,volume, etc. Now, i want to be able to update all columns that has been edited with the same title but have different ids.
here is my example code
$con=mysqli_connect("localhost","root","","library03");
$check="SELECT * FROM collection WHERE title = '$_POST[title]'";
$rs = mysqli_query($con,$check);
$data = mysqli_fetch_array($rs, MYSQLI_NUM);
if($data[0] > 1) {
for($i=0;$i<=COUNT($data);$i++){
$sql="UPDATE collection SET author = '$new_author' WHERE title = '$_POST[title]'";
$sql_connect = mysqli_query($sql);
And these are under my $_POST
$collection = Collection::find_by_id($_POST['id']);
$collection->date_received = $_POST['date_received'];
$collection->title = $_POST['title'];
$collection->author = $_POST['author'];
$collection->edition = $_POST['edition'];
$collection->volume = $_POST['volume'];
$collection->pages = $_POST['pages'];
$collection->cost = $_POST['cost'];
$collection->publisher = $_POST['publisher'];
$collection->pub_year = $_POST['pub_year'];
$collection->remarks = $_POST['remarks'];
$collection->call_number = $_POST['call_number'];
$collection->col_copy = $_POST['col_copy'];
Kindly pardon me if i look silly mates.
My issue is , i have a profile page which on update and submit changes the data in db. To refresh the data then, i use select query after that. Then i save it in the current session. still the changes happens only in the page where the update and select query presents . I have some pages which is been included like top bar, left nav . which changes only if i refresh the page . My code is as follows
<?php
if(isset($_POST['update'])) {
$name_t = $_POST['name'];
$email_t = $_POST['email'];
$pass_t = $_POST['password'];
$contact_t = $_POST['contact'];
$address_t = $_POST['address'];
$dob_t = $_POST['dob'];
$religion_t = $_POST['religion'];
$pic_t = ($_FILES['imagefile']['name']);
$sql = "
UPDATE teacher
SET t_name = '$name_t'
, t_email = '$email_t'
, t_password = '$pass_t'
, t_phone = '$contact_t'
, t_address = '$address_t'
, t_dob = '$dob_t'
, t_religion = '$religion_t'
where teacher_id='$update_id'
";
$retval = mysql_query($sql,$link);
if(! $retval ) {
die('Could not update data: ' . mysql_error());
}
if (!empty($_FILES['imagefile']['name'])) {
$sql = "UPDATE teacher SET t_photo = '$pic_t' where teacher_id='$update_id' ";
$retval = mysql_query($sql,$link);
$info = pathinfo($_FILES['imagefile']['name']);
$ext = $info['extension']; // get the extension of the file
$target = 'img/upload/'.$pic_t;
move_uploaded_file( $_FILES['imagefile']['tmp_name'], $target);
}
}
$result = mysql_query("SELECT * FROM teacher where teacher_id='$update_id' ",$link);
while($row = mysql_fetch_array($result)){
$name = $row['t_name'];
$email = $row['t_email'];
$password = $row['t_password'];
$contact = $row['t_phone'];
$address = $row['t_address'];
$dob = $row['t_dob'];
$religion = $row['t_religion'];
$img = WEB_URL . 'img/upload/'.$row['t_photo'];
$_SESSION['objLogin'] = $row;
}
mysql_close($link);
?>
Kindly help me in updating the included page too without refresh . Because for instance there is the username displayed at top bar .
I'm using php for a profiles site that I'm working on and I need to check that the profile id doesn't equal the member id. So I have this:
<?php
$get_personal_sql = "SELECT * FROM members WHERE username = '$thisuser'";
$get_personal_res = mysqli_query($con, $get_personal_sql);
while ($personal = mysqli_fetch_assoc($get_personal_res)){
$yourid = $personal['id'];
$yourtype = $personal['type'];
$yoursubtype = $personal['subtype'];
$yourusername = $personal['username'];
$youremail = $personal['email'];
$yourname = $personal['name'];
$youractive = $personal['active'];
$yourpro = $personal['pro'];
$yourdel = $personal['del'];
$yourdate = $personal['date'];
}
?>
<?php
$get_member_sql = "SELECT * FROM members WHERE username = '$thismember'";
$get_member_res = mysqli_query($con, $get_member_sql);
$count_member = mysqli_num_rows($get_member_res);
if($count_member == 0){
header("Location: notfound.php");
}
while ($member = mysqli_fetch_assoc($get_member_res)){
$memberid = $member['id'];
$membertype = $member['type'];
$membersubtype = $member['subtype'];
$memberusername = $member['username'];
$memberemail = $member['email'];
$membername = $member['name'];
$memberactive = $member['active'];
$memberpro = $member['pro'];
$memberdel = $member['del'];
$memberdate = $member['date'];
}
?>
<?php
if($memberid === $yourid){
$yourprofile = "true";
}
else{
$yourprofile = "false";
}
?>
I have echoed both $memberid & $yourid in the page and they are Completely different, yet when I echo $yourprofile it displays "true". Can anyone see why this might be?
I'm building a website to learn PHP and have just built a membership app.
Here's my code to get the user cookies that I set when the user logs in, then take the business id they are associated with, called biz and look up all the details for the business with the id equal to biz, in the table named company: (btw, I know I'm using mysql but when I finalize my app, I'll switch to PDO or mysqli)
<?
$auth = $_COOKIE["auth"];
if ($auth != "1"){
header("Location: ./signin.php");
}
//Grab all the cookies
$firstname = $_COOKIE['firstname'];
$id = $_COOKIE['id'];
$fname = ucwords($_COOKIE['firstname']);
$lname = ucwords($_COOKIE['lastname']);
$email = $_COOKIE['email'];
$city = ucwords($_COOKIE['city']);
$biz = $_COOKIE['biz'];
if(!empty($biz)){
$donthaveabizyet = "false";
}
else{
include("./config.php");
$result = mysql_query("SELECT * FROM company WHERE id = '$biz'") or mysql_error();
while($row = mysql_fetch_array($result))
{
$business_name = $row['name'];
$business_phone = $row['phone'];
$business_website = $row['website'];
$business_phone = $row['phone'];
$business_cat1 = $row['cat1'];
$business_cat2 = $row['cat2'];
$business_cat3 = $row['cat3'];
$business_subcat1 = $row['subcat1'];
$business_subcat2 = $row['subcat2'];
$business_subcat3 = $row['subcat3'];
$business_email = $row['email'];
$business_product1 = $row['product1'];
$business_product2 = $row['product2'];
$business_product3 = $row['product3'];
$business_product4 = $row['product4'];
$business_product5 = $row['product5'];
$business_product6 = $row['product6'];
$business_product7 = $row['product7'];
$business_noaddress = $row['noaddress'];
$business_address = $row['address'];
$business_address2 = $row['address2'];
$business_zipcode = $row['zipcode'];
$business_city = $row['city'];
}
$result = mysql_query("SELECT * FROM company_secondary WHERE company_id = '$biz'") or mysql_error();
while($row = mysql_fetch_array($result))
{
$business_description = $row['company_description'];
$business_since = $row['phone'];
$business_logo = $row['logo'];
$business_since = $row['since'];
$business_smoking = $row['smoking'];
$business_delivery = $row['delivery'];
$business_alcohol = $row['alcohol'];
$business_kids = $row['kids'];
$business_wheelchair = $row['wheelchair'];
$business_twitter = $row['twitter'];
$business_facebook = $row['facebook'];
$business_youtube = $row['youtube'];
$business_creditcards = $row['creditcards'];
$business_outdoor = $row['outdoor'];
$business_featured = $row['featured'];
}
}
?>
Now I show a link to claim.php if the user's business id is equal to 0, or if the user's business id is set, I show the name of the business.
<?php
if($donthaveabizyet != "false")
{
echo "<br/><br/>You haven't claimed a business yet. <a href='claim.php'>Click here to claim one now.</a>";
}
else
{
echo $business_name;
}
?>
Unfortunately, $business_name isn't displaying, and the error is Notice: Undefined variable: business_name. Why is business_name not set?
Big thanks for all help!!
while($row = mysql_fetch_array($result))
{
is causing your problem. Change it to
while($row = mysql_fetch_assoc($result))
{
This is because fetch_array creates an array with numeric indexes ($array[1], $array[2], etc.). fetch_assoc makes the indexes the same as the column names ($array['this'], $array['that'], etc.)