0

I have this database add page, which allows you to add more objects to a database and it works fine, but I need the entries to have an image attached to them and cant get it to work. Below is my current working solution (- the image), what do I need to add to make it able to have images uploaded to the entries. The variables are in finnish because that is the language I need to have the final product in so never mind them.

Here are pictures of the layout

The add page: https://i.stack.imgur.com/ycqqL.jpg

The index page that shows everything in the database: https://i.stack.imgur.com/JDpmd.jpg

 <?php
$mysqli = new mysqli(---); // I put in lines to protect my personal info
if ($mysqli->connect_errno) {
    echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
$Tyyppi = $_POST["tyyppi"];
$Malli = $_POST["malli"];
$Sarjanumero = $_POST["sarjanum"];
$Paikka = $_POST["paikka"];
$Kuvaus = $_POST["kuvaus"];
$Lainassa = $_POST["laina"];
$Lainaaja = $_POST["lainaaja"];
$Puhelin = $_POST["puhelin"];
$Sposti = $_POST["sposti"];
$Palautus = $_POST["palautus"];

if ($Lainassa==1){
if ($stmt = $mysqli->prepare("INSERT laitteet (tyyppi, malli, sarjanumero, paikka, kuvaus, lainassa, lainaaja, puhelin, sposti, palautus) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"))
                {
                    $stmt->bind_param("sssssissss", $Tyyppi, $Malli, $Sarjanumero, $Paikka, $Kuvaus, $Lainassa, $Lainaaja, $Puhelin, $Sposti, $Palautus);
                    $stmt->execute();
                    $stmt->close();
                }
                else
                {
                    echo "ERROR: Could not prepare SQL statement.";
                }           
}else{
if ($stmt = $mysqli->prepare("INSERT laitteet (tyyppi, malli, sarjanumero, paikka, kuvaus, lainassa) VALUES (?, ?, ?, ?, ?, ?)"))
                {
                    $stmt->bind_param("sssssi", $Tyyppi, $Malli, $Sarjanumero, $Paikka, $Kuvaus, $Lainassa);
                    $stmt->execute();
                    $stmt->close();
                }
                else
                {
                    echo "ERROR: Could not prepare SQL statement.";
                }   
}
mysqli_close($mysqli);
?>
Slyre
  • 39
  • 1
  • 1
  • 12
  • 1
    http://stackoverflow.com/questions/17377645/how-to-save-uploaded-image-in-database-with-php http://stackoverflow.com/questions/19529896/how-to-upload-image-and-save-path-to-database http://stackoverflow.com/questions/17717506/how-to-upload-images-into-mysql-database-using-php-code http://www.daniweb.com/web-development/php/threads/224758/using-php-to-upload-an-image-into-an-sql-database-and-then-displaying-on-a-profile-p – ɹɐqʞɐ zoɹǝɟ May 15 '14 at 09:01
  • You really should search for this question before asking. This has been asked a lot of times previously. – ggdx May 15 '14 at 09:17

3 Answers3

0

change your insert query.you are missing into

$mysqli->prepare("INSERT laitteet (tyyppi, malli, sarjanumero, paikka, kuvaus, lainassa) VALUES (?, ?, ?, ?, ?, ?)"))

To

$mysqli->prepare("INSERT into laitteet (tyyppi, malli, sarjanumero, paikka, kuvaus, lainassa) VALUES (?, ?, ?, ?, ?, ?)"))
Nagaraj S
  • 13,316
  • 6
  • 32
  • 53
  • I added INTO to my query and also added an additional value for an image and it still does not work, actually if I add another value to my code that I posted the whole adding function stops working. – Slyre May 15 '14 at 10:24
0

The right sytax for the INSERT statement is:

INSERT INTO tbl_name () VALUES();

here is the link: http://dev.mysql.com/doc/refman/5.6/en/insert.html

szpal
  • 647
  • 9
  • 27
0

Your query Syntex is not correct-you are missing 'INTO' replace your if statement as follows current- if ($stmt = $mysqli->prepare("INSERT laitteet (tyyppi, malli, sarjanumero, paikka, kuvaus, lainassa) VALUES (?, ?, ?, ?, ?, ?)"));

**After correction**- 
`if ($stmt = $mysqli->prepare("INSERT INTO laitteet (tyyppi, malli, sarjanumero, paikka, kuvaus, lainassa) VALUES (?, ?, ?, ?, ?, ?)"));`