0

I can insert just fine by directly sending a string e.g.

$sql ""INSERT INTO op2 (time, label, fromWho, photo) VALUES ('".$time."', '{$username}', '{$password}', 'test')"; 

But the following with a prepared statement refused to insert and any echoes past "$stmt->execute();" do not appear in the web page.

<?php
$servername = "localhost";
$database = "------";
$username = "-----";
$password = "-------";

// Create connection

$conn = mysqli_connect($servername, $username, $password, $database);

// Check connection

if (!$conn) {
      die("Connection failed: " . mysqli_connect_error());
}
 
 
//set timezone:
date_default_timezone_set("America/New_York");

//op2 () VALUES ('" . date("dMY-H:i:s") . "', '$_POST["username', '$_POST["password"]', 'Testes')";

$date = date("dMY-H:i:s")
$username = $_POST['username'];
$password = $_POST['password'];
$photo = "test";
$sqlinput = "INSERT INTO op2 (time, label, fromWho, photo) VALUES (?,?,?,?)";
$stmt = mysqli_prepare($sqlinput);
$stmt->bind_param("ssss", $date, $username, $password, $photo);
$stmt->execute();


if (mysqli_query($conn, $sql)) {
      echo "New record created successfully";
} else {
      echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
mysqli_close($conn);

?>
brigand
  • 11
  • 1

0 Answers0