web service update error - php

i have a web service that show me this error
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '0', date_de_naissance = '1988-02-02', lieu_de_naissance = ' at line 4{"items":[["succes"]]}
<?php
include('settings.php');
mysql_connect($host,$user,$password);
mysql_select_db($base);
mysql_query('SET CHARACTER SET utf8');
$id_patient = $_GET['id_patient'];
$nom = $_GET['nom'];
$prenom = $_GET['prenom'];
$Sexe = $_GET['Sexe'];
$date_de_naissance = $_GET['date_de_naissance'];
$lieu_de_naissance = $_GET['lieu_de_naissance'];
$adresse = $_GET['adresse'];
$latitude = $_GET['latitude'];
$longitude = $_GET['longitude'];
$telephone = $_GET['telephone'];
$email = $_GET['email'];
$situation_familiale = $_GET['situation_familiale'];
$profession = $_GET['profession'];
$numero_securite_sociale = $_GET['numero_securite_sociale'];
$taille = $_GET['taille'];
$poids = $_GET['poids'];
$groupe_sanguin = $_GET['groupe_sanguin'];
$allergies = $_GET['allergies'];
$antecedents_chirurgicaux = $_GET['antecedents_chirurgicaux'];
$antecedents_medicaux = $_GET['antecedents_medicaux'];
$antecedents_familiaux = $_GET['antecedents_familiaux'];
if ($id_patient!= NULL )
{
$req = "UPDATE patient SET nom = '".$nom."' , prenom = '".$prenom.", Sexe = '".$Sexe."',
date_de_naissance = '".$date_de_naissance."',
lieu_de_naissance = '".$lieu_de_naissance."',
adresse = '".$adresse."',
latitude = '".$latitude."',
longitude = '".$longitude."',
telephone = '".$telephone."',
email = '".$email."',
situation_familiale = '".$situation_familiale."',
profession = '".$profession."',
numero_securite_sociale = '".$numero_securite_sociale."',
taille = '".$taille."',
poids = '".$poids."',
groupe_sanguin = '".$groupe_sanguin."',
allergies = '".$allergies."',
antecedents_chirurgicaux = '".$antecedents_chirurgicaux."',
antecedents_medicaux = '".$antecedents_medicaux."',
antecedents_familiaux = '".$antecedents_familiaux."'
WHERE id_patient = '".$id_patient."' ";
$sql=mysql_query($req);
echo mysql_error();
$items = array("items" => NULL);
$items["items"][] = array("succes");
echo json_encode($items,JSON_UNESCAPED_UNICODE);
}
else{$items = array("items" => NULL);
$items["items"][] = array("erreur");
echo json_encode($items,JSON_UNESCAPED_UNICODE);}
?>

A closing quote was missing.
$req = "UPDATE patient SET nom = '".$nom."' , prenom = '".$prenom."', Sexe = '".$Sexe."',

Related

Index causes and Error in Updating Row

Why does Index causes an error in MySQL Update row? Removing it makes the Query work.
The error is
MySQLi failed to query: UPDATE quests SET id = '1', FactionID = '2', ReqReputation = '2', ReqClassID = '3', ReqClassPoints = '2', Name = '2', Description = '2', EndText = '2', Experience = '2', GExperience = '2', Copper = '2', Silver = '2', Gold = '2', Coins = '2', Reputation = '2', ClassPoints = '2', RewardType = 'S', Level = '2', Upgrade = '1', Once = '1', Slot = '2', Value = '2', Field = '2', Index = '2', Badges = '3', Guild = '1', GiveMembership = '0', War = '1' WHERE id = 1 - December 20, 2016, 1:58 am
$id = $_POST["Id"];
$FactionID = $_POST["Faction"];
$ReqReputation = $_POST["RequiredReputation"];
$ReqClassID = $_POST["Class"];
$ReqClassPoints = $_POST["ReqClassRank"];
$Name = $_POST["Name"];
$Description = $_POST["Description"];
$EndText = $_POST["EndText"];
$Experience = $_POST["Experience"];
$GExperience = $_POST["GuildExperience"];
$Copper = $_POST["Copper"];
$Silver = $_POST["Silver"];
$Gold = $_POST["Gold"];
$Coins = $_POST["Diamond"];
$Reputation = $_POST["Reputation"];
$ClassPoints = $_POST["ClassPoints"];
$RewardType = $_POST["RewardType"];
$Level = $_POST["Level"];
$Upgrade = $_POST["Upgrade"];
$Once = $_POST["Once"];
$Slot = $_POST["Slot"];
$Value = $_POST["Value"];
$Field = $_POST["Field"];
$QIndex = $_POST["Index"];
$Badges = $_POST["Badges"];
$Guild = $_POST["Guild"];
$GiveMembership = $_POST["GiveMembership"];
$War = $_POST["War"];
$MYSQL_QUERY = $content->DBase('Query', array( 0 => "UPDATE quests SET id = '$id', FactionID = '$FactionID', ReqReputation = '$ReqReputation', ReqClassID = '$ReqClassID', ReqClassPoints = '$ReqClassPoints', Name = '$Name', Description = '$Description', EndText = '$EndText', Experience = '$Experience', GExperience = '$GExperience', Copper = '$Copper', Silver = '$Silver', Gold = '$Gold', Coins = '$Coins', Reputation = '$Reputation', ClassPoints = '$ClassPoints', RewardType = '$RewardType', Level = '$Level', Upgrade = '$Upgrade', Once = '$Once', Slot = '$Slot', Value = '$Value', Field = '$Field', Index = '$Index', Badges = '$Badges', Guild = '$Guild', GiveMembership = '$GiveMembership', War = '$War' WHERE id = $id"));
Function DBase
/** MYSQL IMPROVED EXTENSION (PARENT CLASS) **/
public function DBase($type, $params = array()) {
if (!$this->SITE->CMS->Connection)
SystemExit('No available MySQLi connection', __LINE__, __FILE__);
switch (strtoupper($type)) {
case 'QUERY':
if ($Query = parent::query($params[0])) {
$this->SITE->CMS->TotalQuery++;
return $Query;
} else
SystemExit('MySQLi failed to query: ' . $params[0], __LINE__, __FILE__);
break;
case 'PREPARE':
if ($Query = parent::prepare($params[0])) {
$this->SITE->CMS->TotalQuery++;
return $Query;
} else
SystemExit('MySQLi failed to prepare: ' . $params[0], __LINE__, __FILE__);
break;
case 'ESCAPESTRING':
if ($Escape = parent::real_escape_string($params[0]))
return $Escape;
else
SystemExit('MySQLi failed to escape: ' . $params[0], __LINE__, __FILE__);
break;
}
}
Here is the Table Quest
You're using the wrong variable for index. You define it above as $QIndex but then refer to it as $Index on the last line. Try the following:
$id = $_POST["Id"];
$FactionID = $_POST["Faction"];
$ReqReputation = $_POST["RequiredReputation"];
$ReqClassID = $_POST["Class"];
$ReqClassPoints = $_POST["ReqClassRank"];
$Name = $_POST["Name"];
$Description = $_POST["Description"];
$EndText = $_POST["EndText"];
$Experience = $_POST["Experience"];
$GExperience = $_POST["GuildExperience"];
$Copper = $_POST["Copper"];
$Silver = $_POST["Silver"];
$Gold = $_POST["Gold"];
$Coins = $_POST["Diamond"];
$Reputation = $_POST["Reputation"];
$ClassPoints = $_POST["ClassPoints"];
$RewardType = $_POST["RewardType"];
$Level = $_POST["Level"];
$Upgrade = $_POST["Upgrade"];
$Once = $_POST["Once"];
$Slot = $_POST["Slot"];
$Value = $_POST["Value"];
$Field = $_POST["Field"];
$QIndex = $_POST["Index"];
$Badges = $_POST["Badges"];
$Guild = $_POST["Guild"];
$GiveMembership = $_POST["GiveMembership"];
$War = $_POST["War"];
$MYSQL_QUERY = $content->DBase('Query', array( 0 => "UPDATE quests SET id = '$id', FactionID = '$FactionID', ReqReputation = '$ReqReputation', ReqClassID = '$ReqClassID', ReqClassPoints = '$ReqClassPoints', Name = '$Name', Description = '$Description', EndText = '$EndText', Experience = '$Experience', GExperience = '$GExperience', Copper = '$Copper', Silver = '$Silver', Gold = '$Gold', Coins = '$Coins', Reputation = '$Reputation', ClassPoints = '$ClassPoints', RewardType = '$RewardType', Level = '$Level', Upgrade = '$Upgrade', Once = '$Once', Slot = '$Slot', Value = '$Value', Field = '$Field', Index = '$QIndex', Badges = '$Badges', Guild = '$Guild', GiveMembership = '$GiveMembership', War = '$War' WHERE id = $id"));
Also see #Rahul 's comment too. Your: "WHERE id='$id'" seems to be passing the wrong value. An ID is most likely not that version of a date/time. if you want to use the current date + time you could us something like NOW() It gives you the current date and time down to the second.

update data and show in single page without page reloading using php

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='$dAd‌​dress',
location='$dL‌​ocation', city='$dCity',driver_pincode='$dPincode',
PickUp_Area='$dPick‌​Up', vehicle_reg_no='$dVehicleNo' where Id='".$isession['d_id']."' ";

SQL Error while updating

I have encountered an error and I do not know what is wrong with my code. Can someone help me?
Error: UPDATE users SET voornaam = Test, achternaam = Test2, mail = test#test.com, tel = ,adres = , geslacht = man, bestuur = 0, tc = 0, ic = 0, jec = 0, rvr = , instructeur = 0, webmaster = 0 WHERE id = 1
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'adres = , geslacht = man, bestuur = 0, tc = 0, ic = 0, jec = 0, rvr = , instruct' at line 1
$id = $_GET['u'];
$sql = "UPDATE users SET voornaam = $voornaam, achternaam = $achternaam,
mail = $mailadres, tel = $tel, adres = $adres, geslacht = $geslacht,
bestuur = $bestuur, tc = $tc, ic = $ic, jec = $jec, rvr = $rvr,
instructeur = $instructeur, webmaster = $webmaster WHERE id = ".$id."";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
You should have something like:
$sql = "UPDATE `users`
SET `voornaam` = '$voornaam',
`achternaam` = '$achternaam',
`mail` = '$mailadres',
`tel` = '$tel',
`adres` = '$adres',
`geslacht` = '$geslacht',
`bestuur` = '$bestuur',
`tc` = '$tc',
`ic` = '$ic',
`jec` = '$jec',
`rvr` = '$rvr',
`instructeur` = '$instructeur',
`webmaster` = '$webmaster'
WHERE id = '".$id."'";
This way you are protected if there are empty fields anywhere. You should also make sure you sanitize all the entries you wish to insert in the database.
You must quote ANY string like 'xxxx' else empty strings are missing and string with spaces are see as 2 strings achternaam= van mueller is wrong but achternaam = 'van mueller' is ok and also achternaam=''
You need add quote ' around the updated value, like
$sql = "UPDATE users SET voornaam = '$voornaam', achternaam = '$achternaam', mail = '$mailadres', tel = '$tel', adres = '$adres', geslacht = '$geslacht', bestuur = '$bestuur', tc = '$tc', ic = '$ic', jec = '$jec', rvr = '$rvr', instructeur = '$instructeur', webmaster = '$webmaster' WHERE id = '".$id."'";
If you are not sure that your variables are set before your query, then check them before you create sql query with isset:
if (!isset($a)) {
$a = ''
}
and put your variables in quote:
$sql = "UPDATE users SET voornaam='$voornaam', achternaam='$achternaam',
mail='$mailadres', tel='$tel', adres='$adres', geslacht='$geslacht',
bestuur='$bestuur', tc='$tc', ic='$ic', jec='$jec', rvr='$rvr',
instructeur='$instructeur', webmaster='$webmaster' WHERE id='".$id."'";

data not being updated

Data not being updated when i am trying to update, its showing could not update data only always, i have the session carrying reg from my registration table and i want to update with reg in my slam table in which reg is present. here reg is present in both tables.
<?php
session_start();
if($_SERVER["REQUEST_METHOD"] == "POST")
{
$con=mysqli_connect("xyz","aaa","aaa","aaa");
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$reg = $_REQUEST["reg"];
$t1 = $_REQUEST["t"];
$t2 = $_REQUEST['t2'];
$t3 = $_REQUEST['t3'];
$t4 = $_REQUEST['t4'];
$t5 = $_REQUEST['t5'];
$t6 = $_REQUEST['t6'];
$t7 = $_REQUEST['t7'];
$t8 = $_REQUEST['t8'];
$t9 = $_REQUEST['t9'];
$t10 = $_REQUEST['t10'];
$t11 = $_REQUEST['t11'];
$t13 = $_REQUEST['t13'];
$t14 = $_REQUEST['t14'];
$t15 = $_REQUEST['t15'];
$t16 = $_REQUEST['t16'];
$t17 = $_REQUEST['t17'];
$t18 = $_REQUEST['t18'];
$t19 = $_REQUEST['t19'];
$t20 = $_REQUEST['t20'];
$t21 = $_REQUEST['t21'];
$t22 = $_REQUEST['t22'];
$t23 = $_REQUEST['t23'];
$t24 = $_REQUEST['t24'];
$t25 = $_REQUEST['t25'];
$t26 = $_REQUEST['t26'];
$t27 = $_REQUEST['t27'];
$t28 = $_REQUEST['t28'];
$t29 = $_REQUEST['t29'];
$t30 = $_REQUEST['t30'];
$t31 = $_REQUEST['t31'];
$t32 = $_REQUEST['t32'];
$t33 = $_REQUEST['t33'];
$t34 = $_REQUEST['t34'];
$t35 = $_REQUEST['t35'];
$t36 = $_REQUEST['t36'];
$t37 = $_REQUEST['t37'];
$t38 = $_REQUEST['t38'];
$sql="UPDATE slambook SET iam = '$t1' ,pals = '$t2',birthday = '$t3' ,mobile = '$t4' ,zodiac ='$t5' ,address = '$t6',email ='$t7',site = '$t8',id = '$t9' ,hang = '$t10',food = '$t11',colour = '$t13',outfit = '$t14',novel = '$t15',singer = '$t16',song = '$t17',movie = '$t18',actor = '$t19',aim = '$t20',memor = '$t21',you = '$t22',date = '$t23',city = '$t24',frienship = '$t25',nuts = '$t26',besties = '$t27',destiny = '$t28',y = '$t29',moment = '$t30',achieve = '$t31',dream = '$t32',experience = '$t33',imagination = '$t34',regrets = '$t35',stupid = '$t36',belief = '$37',about = '$38' where reg=$reg";
$retval = mysqli_query($con,$sql);
if(!$retval )
{
die('Could not update data: ' . mysql_error());
}
echo "Updated data successfully\n";
mysqli_close($con);
}
else
{
?>

PHP Update issue with MYSQL Table, some fields revert to zero

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'";

Categories