I have a curious problem, I have the following UPDATE query which works well for me, however when I update column ZW, row 6; column GK row 1 and column OK row 1 they all revert back to zero on update?? All the other fields update perfectly.
MYSQL all set to INT.
id = $_POST['id'];
$date = $_POST['date'];
$vorname = $_POST['vorname'];
$nachname = $_POST['nachname'];
$Adress = $_POST['Adress'];
$plz = $_POST['plz'];
$ort = $_POST['ort'];
$age = $_POST['age'];
$ringe = $_POST['ringe'];
$mzs = $_POST['mzs'];
$mg = $_POST['mg'];
$onezw = $_POST['onezw'];
$twozw = $_POST['twozw'];
$threezw = $_POST['threezw'];
$fourzw = $_POST['fourzw'];
$fivezw = $_POST['fivezw'];
$sixzw = $_POST['sixzw'];
$onegk = $_POST['onegk'];
$twogk = $_POST['twogk'];
$threegk = $_POST['threegk'];
$fourgk = $_POST['fourgk'];
$fivegk = $_POST['fivegk'];
$sixgk = $_POST['sixgk'];
$onegk = $_POST['oneok'];
$twook = $_POST['twook'];
$threeok = $_POST['threeok'];
$fourok = $_POST['fourok'];
$fiveok = $_POST['fiveok'];
$sixok = $_POST['sixok'];
$sql="UPDATE $tbl_name SET minzw = LEAST(onezw,twozw,threezw,fourzw,fivezw,sixzw), mingk = LEAST(onegk,twogk,threegk,fourgk,fivegk,sixgk), minok = LEAST(oneok,twook,threeok,fourok,fiveok,sixok), date='$date', vorname='$vorname', nachname='$nachname', Adress='$Adress', plz='$plz', ort='$ort', age='$age', ringe='$ringe', mzs='$mzs', mg='$mg', onezw='$onezw', twozw='$twozw', threezw='$threezw', fourzw='$fourzw', fivezw='$fivezw', sixzw='$sixzw', onegk='$onegk', twogk='$twogk', threegk='$threegk', fourgk='$fourgk', fivegk='$fivegk', sixgk='$sixgk', oneok='$oneok', twook='$twook', threeok='$threeok', fourok='$fourok', fiveok='$fiveok', sixok='$sixok' WHERE id='$id'";
Related
So I want to update my data in database, and I wanna make sure that the row it updates (which is the last name) is the same as the one logged in. I did is this:
'data' is the name of the table where the logged in last name is to be found, 'ict' is the table where the grades is in and another last name to so that i can compare if they're the same and update that row.
After I input the datas and confirm it, it says "Successfully Inserted" but the data doesn't get updated and it turns to 1.
This is my code:
<?php
include("sq.php");
$a21st = isset(($_POST['a21st']));
$a21st2 = isset(($_POST['a21st2']));
$entre = isset(($_POST['entre']));
$entre2 = isset(($_POST['entre2']));
$pe3 = isset(($_POST['pe3']));
$pe32 = isset(($_POST['pe32']));
$a1 = isset(($_POST['a1']));
$a12 = isset(($_POST['a12']));
$a2 = isset(($_POST['a2']));
$a22 = isset(($_POST['a22']));
$fil = isset(($_POST['fil']));
$fil2 = isset(($_POST['fil2']));
$mil = isset(($_POST['mil']));
$mil2 = isset(($_POST['mil2']));
$contem = isset(($_POST['contem']));
$contem2 = isset(($_POST['contem2']));
$physci = isset(($_POST['physci']));
$physci2 = isset(($_POST['physci2']));
$pe4 = isset(($_POST['pe4']));
$pe42 = isset(($_POST['pe42']));
$reaspro = isset(($_POST['reaspro']));
$reaspro2 = isset(($_POST['reaspro2']));
$a3 = isset(($_POST['a3']));
$a32 = isset(($_POST['a32']));
$a4 = isset(($_POST['a4']));
$a42 = isset(($_POST['a42']));
$immers = isset(($_POST['immers']));
$immers2 = isset(($_POST['immers2']));
if (mysqli_connect_error()) {
die('Connect Error('. mysqli_connect_errno().')'. mysqli_connect_error());
} else {
$SELECT =("SELECT * FROM data");
$result = mysqli_query($db,$SELECT);
$row = mysqli_fetch_array($result,MYSQLI_ASSOC);
$last = $row['last'];
$UPDATE = "UPDATE `ict` SET a21st = $a21st, a21st2 = $a21st2, entre= $entre, entre2 = $entre2, pe3 = $pe3, pe32 = $pe32, a1 = $a1, a12 = $a12, a2 = $a2, a22 = $a22, fil = $fil, fil2 = $fil2, mil = $mil, mil2 = $mil2, contem = $contem, contem2 = $contem2, physci = $physci, physci2 = $physci2, pe4 = $pe4, pe42 = $pe42, reaspro = $reaspro, reaspro2 = $reaspro2, a3 = $a3, a32 = $a32, a4 = $a4, a42 = $a42, immers = $immers, immers2 = $immers2 WHERE last = '".$last."'";
if (mysqli_query($db,$UPDATE)){
$message = "Successfully Inputted!!";
echo "<script type='text/javascript'>alert('$message');</script>";
}else {
echo "Error: <br>". $db->error;
}
}
$db->close();$db
isset returns true if the value exists, which translates to 1 in a numeric context, which is probably not what you meant. Instead, you need to get the value itself. E.g.:
$a21st = isset($_POST['a21st']) ? $_POST['a21st'] : null;
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'];
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']."' ";
$id = $_POST["id"];
$prevread = $_POST["prev"];
$presread = $_POST["pres"];
$getPrev = (int)$prevread;
$getPres = (int)$presread;
$totalcons = (int)$_POST[$getPres - $getPrev];
$sql = "UPDATE con_billing SET totalConsumed ='$totalcons' WHERE con_id='$id';
At the moment this code updates the user info in MYSQLTABLE1. What I also want done is user info to be copied to WMYSQLTABLE which I can do but I also want a code from MYSQLTABLE2 to be copied over into a column in WMYSQLTABLE as well. Here is the part I need changing:
$sql_insert2 = "INSERT INTO ".WMYSQLTABLE2."(ip,date,address)values
('','$ip','$date','$address')";
$res_insert2 = mysql_query($sql_insert2)or die(mysql_error());
//Need to also insert code from first row from column named 'codes' in MYSQLTABLE2.
Actual code, it's a bit messy at the moment and the if/else statements do the exact same at the moment. It works but I get the error " Column count doesn't match value count at row 1" because I cannot fill the last column with the code from MYSQLTABLE2.
<?php
include("includes/config.php");
include("includes/mysql.php");
include("amount.php");
if(isset($_POST['func']))
{
$address = $_POST['address'];
$ip = $_POST['ip'];
$date = $_POST['date'];
$time = $_POST['time'];
$price = $_POST['price'];
$increment = $_POST['increment'];
$id = $_POST['id'];
$num = 0;
$sql_check_address = "SELECT * FROM ".MYSQLTABLE1." WHERE address='$address'";
$res_check_address = mysql_query($sql_check_address)or die(mysql_error());
$num = mysql_num_rows($res_check_address);
$row = mysql_fetch_assoc($res_check_address);
if($num > 0)
{
$address = $row['address'];
$ip = $row['ip'];
$date = $row['date'];
$oldprice = $row['price'];
$id = $row['id'];
$newprice = $oldprice - $payAmount*200;
$newinc = $increment - 200;
$sql_update1 = "UPDATE ".MYSQLTABLE1." SET ip='$ip',date='$date',price='$newprice',increment='$newinc',address='$address' WHERE id='$id'";
$res_update1 = mysql_query($sql_update1)or die(mysql_error());
/////////////////Insert user info and copy code from MYSQLTABLE2 to WMYSQLTABLE2
$sql_insert2 = "INSERT INTO ".WMYSQLTABLE2."(ip,date,address)values
('','$ip','$date','$address')";
$res_insert2 = mysql_query($sql_insert2)or die(mysql_error());
}
else{
$address = $row['address'];
$ip = $row['ip'];
$date = $row['date'];
$oldprice = $row['price'];
$id = $row['id'];
$newprice = $oldprice - $payAmount*200;
$newinc = $increment - 200;
$sql_update = "UPDATE ".MYSQLTABLE1." SET ip='$ip',date='$date',price='$newprice',increment='$newinc',address='$address' WHERE id='$id'";
$res_update = mysql_query($sql_update)or die(mysql_error());
/////////////////Insert user info and copy code from MYSQLTABLE2 to WMYSQLTABLE2
$sql_insert2 = "INSERT INTO ".WMYSQLTABLE2."(ip,date,address)values
('','$ip','$date','$address')";
$res_insert2 = mysql_query($sql_insert2)or die(mysql_error());
e
}
}
Any help will be greatly appreciated.
The general form of the query would be:
$sql_insert = "INSERT INTO " . WMYSQLTABLE2 . "(code, ip, date, address)
SELECT code, '$ip', '$date', '$address'
FROM OtherTable
WHERE <put something here to select the row>";