yandoos Posted July 22, 2015 Share Posted July 22, 2015 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 Quote Link to comment Share on other sites More sharing options...
ginerjm Posted July 22, 2015 Share Posted July 22, 2015 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 Quote Link to comment Share on other sites More sharing options...
yandoos Posted July 22, 2015 Author Share Posted July 22, 2015 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; Quote Link to comment Share on other sites More sharing options...
yandoos Posted July 22, 2015 Author Share Posted July 22, 2015 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; Quote Link to comment Share on other sites More sharing options...
yandoos Posted July 22, 2015 Author Share Posted July 22, 2015 That makes me think I have forgotten to add the $connection to it: $result = mysqli_query($connection, $sql); If I change it as above there is no error again... Quote Link to comment Share on other sites More sharing options...
yandoos Posted July 22, 2015 Author Share Posted July 22, 2015 The structure type of the date fields are set as Date. Could this be causing the problem? Quote Link to comment Share on other sites More sharing options...
Solution yandoos Posted July 23, 2015 Author Solution Share Posted July 23, 2015 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.