-3

code..

<?php
ini_set('display_errors', 'On');
error_reporting(E_ALL);
require_once('conexion.php');

$producto = $_POST['prod'];
$cantidad = $_POST['cant'];
$precio = $_POST['total'];
$cliente = $_POST['nombre'];
$email = $_POST['email'];
$telefono = $_POST['tel'];
$imgData = addslashes(file_get_contents($_POST['userImage']['tmp_name']));
$imageProperties = getimageSize($_POST['userImage']['tmp_name']);

if (empty($_POST['prod'])) {
// code...
echo "<script>alert('no as elejido nada del menu...');history.go(-1);</script>";
// header("location: ../index.php?enviado");
}else{
$sql = "INSERT INTO pagos_hystory 
(Producto,Cantidad,Precio,cliente,email_cli,celular,imageType,imageData) VALUES 
('$producto','$cantidad','$precio','$cliente','$email','$telefono','{$imageProperties['mime']}', 
'{$imgData}')";
$result = mysqli_query($link,$sql);

// header("location: ../index.php?enviado");
 // echo ("<script>
//   window.alert('Su pedido ha sido enviado con éxito!');
//   window.location.href='../';
//   </script>");
}

?>

output:

Warning: Illegal string offset 'tmp_name' in D:\xampp\htdocs\wrapp\config\insert_pedido.php on line 13 Warning: file_get_contents(2): failed to open stream: No such file or directory in D:\xampp\htdocs\wrapp\config\insert_pedido.php on line 13 Warning: Illegal string offset 'tmp_name' in D:\xampp\htdocs\wrapp\config\insert_pedido.php on line 14 Warning: getimagesize(2): failed to open stream: No such file or directory in D:\xampp\htdocs\wrapp\config\insert_pedido.php on line 14

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
  • help! this is my project – david flores Dec 12 '20 at 09:50
  • Means `$_POST['userImage']` is a string. I'm guessing you want to access a file? – El_Vanja Dec 12 '20 at 09:54
  • Please note that the way you're building your query is unsafe. You're open to [SQL injection](https://stackoverflow.com/questions/332365/how-does-the-sql-injection-from-the-bobby-tables-xkcd-comic-work). You should use [prepared statements](https://www.php.net/manual/en/mysqli.quickstart.prepared-statements.php) or [PDO](https://www.php.net/manual/en/book.pdo) instead. – El_Vanja Dec 12 '20 at 09:54

1 Answers1

0

From this line

Warning: Illegal string offset 'tmp_name'

It seems either your file upload was not successful, or your file is actually under a different input name.

A good way to debug this is add the line

print_r($_FILES);exit;

So when you try to upload it will show you exactly what files were uploaded and how the array is set. If nothing shows it means there was no uploaded files.

Edit: As Your Common Sense pointed out, you should be using $_FILES for uploaded files, not $_POST

Also note files will only upload if you form has the following method="post" enctype="multipart/form-data" Added

Corby Jurgens
  • 76
  • 1
  • 6