UPDATE command not working?

sanjose.42web.io

The update works fine on localhost, but not in this live server. I could even see the console transporting the header but it doesnt reflect in the database. I have another php page with INSERT commands, and it works, so I dont know why this one doesnt.

It turns out that all my update and even delete queries across all pages doesnt work. What could be the problem?

It says something about datetime, even if I dont mess with touching the datetime at all

Uncaught PDOException: SQLSTATE[22007]: Invalid datetime format: 1292 Truncated incorrect DOUBLE value:

this is updatepeople.php

include_once("../connections/db.inc.php");
   
    if(isset($_POST['id'])) {
        $value = $_POST['value'];
        $column = $_POST['column'];
        $id = $_POST['id'];

        $sql = "UPDATE people SET $column = :value WHERE md5(personId) = :id OR personId =:id LIMIT 1";
        $stmt = $db->prepare($sql);
        $stmt->bindParam(":value", $value);
        $stmt->bindParam(":id", $id);

        if($stmt->execute()){
            echo "Yup";
        }
        else {
            echo "fail";
        }

    }

html

<td><div contenteditable="true" onBlur="updateValue(this, 'lName', '<?php echo $id;?>')" ><?php echo $lName; ?></div></td>

jquery

 function updateValue(element,column,id) {
			var result = confirm("Are you sure you want to update value?");
			if (result) {
				var value = element.innerText;     
				$.ajax({
					url:'updatepeople.php',
					type: 'post',
					data:{
						value: value,
						column: column,
						id: id
					},
				success: function(php_result) {
					console.log(php_result);
					}
				})
			}
							
		}

my table structure is this

I tried this setting PDO::PARAM_INT for the $id bind. The error message disappeared, but no update happens in the database.
EDIT: alright it worked. Setting PDO::PARAM_INT for the id variable worked, it only needed a little time to update the changes.

Did you check your credentials again?

I dont think the problem is about credentials. At first it wont allow me into accessing the website at all (wrong database name and password), now I can enter the website, log in, but this update operation still does not work

1 Like

In the end it works or not ?

if it is not a secret, can you state what was returned
after this DOUBLE value: <HERE?

1 Like

Oh sorry, forgot to mention the edit date. Yes it worked, my post arrived earlier than the edit.
To answer the question: the double value in question was in fact an md5 hashed sql id. I solved it by setting PDO::PARAM_INT to classify it as an int.

Futher problems appeared, so I removed the md5 altogether.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.