Jump to content

mysqli query not updating some fields


Go to solution Solved by yandoos,

Recommended Posts

I've been staring at this for ages now and just don't see what the problem is. I have an update query that updates records in the db. It only updates some of the fields and ignores all the date fields. I've echoed out variables and they are all correct but they just dont update and there is no error either?

<?php 
ini_set('display_errors', 1); 
error_reporting(E_ALL);
include "include/session.php";
  require('config.php'); 
  require('include/functions.php'); 

  

if (isset($_POST['Submit1'])) { 
echo 'cheese';
$pdid = $_POST['pdid']; 
$delivery_date = $_POST['delivery_date'];
$status = $_POST['status'];
$start = $_POST['start'];
$ending = $_POST['end'];
$balance = $_POST['balance'];
}

echo $pdid; echo '<br>';
echo $delivery_date; echo '<br>';
echo $status; echo '<br>';
echo $start; echo '<br>';
echo $ending; echo '<br>';
echo $balance; echo '<br>';
echo $pdid; echo '<br>';

$connection = mysqli_connect($dbhost_name, $username, $password, $database);


$result = mysqli_query($connection, "UPDATE distribution SET delivery_date = '$delivery_date', status = '$status', start = '$start', end = '$ending', balance = '$balance' WHERE pdid = '$pdid'");

echo 'done';


?>

What am I doing wrong?

 

Thanks :(

Link to comment
https://forums.phpfreaks.com/topic/297433-mysqli-query-not-updating-some-fields/
Share on other sites

Do these two things.

 

1 - build the query statement into a variable and then echo it out and use that variable in the query call instead of the statement. Much better way to do things IMHO.

 

2 - test the result of the query call to be sure it ran

Thanks for the reply, I've added or die (mysql_error()); to the query and  if I echo $sql; It displays 1.

$connection = mysqli_connect($dbhost_name, $username, $password, $database)or die('Could not connect: ' . mysqli_connect_error());
$sql = mysqli_query($connection,"UPDATE distribution SET delivery_date = '$delivery_date', status = '$status', start = '$start', end = '$ending', balance = '$balance' WHERE pdid = '$pdid'" )or die (mysql_error());

echo $sql;

if I add $result = mysqli_query($sql); I get an error: Warning: mysqli_query() expects at least 2 parameters, 1 given in /home/dusousbo/public_html/update_distributions.php on line 37
 

$connection = mysqli_connect($dbhost_name, $username, $password, $database);
$sql = mysqli_query($connection,"UPDATE distribution SET delivery_date = '$delivery_date', status = '$status', start = '$start', end = '$ending', balance = '$balance' WHERE pdid = '$pdid'" )or die (mysql_error());
$result = mysqli_query($sql);
echo $sql;
echo $result;
  • Solution

I realised the date needed to be reformatted before it could be updated in the db.

$pdid = $_POST['pdid']; 
$delivery_date1 = $_POST['delivery_date'];
$status = $_POST['status'];
$start1 = $_POST['start'];
$ending1 = $_POST['end'];
$balance = $_POST['balance'];

$delivery_date = date_create($delivery_date1)->format('Y-m-d');
$start = date_create($start1)->format('Y-m-d');
$ending = date_create($ending1)->format('Y-m-d');

Thank you :)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.