Jump to content

php add to mysql doesnt work


loxfear

Recommended Posts

i made a submitter, that workes:

<?php
include 'sqlconnect.php';

 
$sql = sprintf(
       "INSERT INTO aktiviteter
            (`title`, `firma`, `beskrivelse`, `information`, `pris`, `rabat`,
             `adresse`, `by`, `postnummer`, `telefon`, `hjemmeside`)
        VALUES
            ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",
        mysqli_real_escape_string($con, $_POST['title']),
        mysqli_real_escape_string($con, $_POST['firma']),
        mysqli_real_escape_string($con, $_POST['beskrivelse']),
        mysqli_real_escape_string($con, $_POST['information']),
        mysqli_real_escape_string($con, $_POST['pris']),
        mysqli_real_escape_string($con, $_POST['rabat']),
        mysqli_real_escape_string($con, $_POST['adresse']),
        mysqli_real_escape_string($con, $_POST['by']),
        mysqli_real_escape_string($con, $_POST['postnummer']),
        mysqli_real_escape_string($con, $_POST['telefon']),
        mysqli_real_escape_string($con, $_POST['hjemmeside'])
        );
 
if (!mysqli_query($con, $sql))
{
    die('Error: ' . mysqli_error($con));
}
echo "Aktiviteten er uploaded";
 
mysqli_close($con);

but then i changed a few parameters and now it doesnt. i cant figure out why

<?php
include 'sqlconnect.php';

$sql = sprintf(
       "INSERT INTO menus
            (`navn`, `kommentar`, `pris`, `target`)
        VALUES
            ('%s', '%s', '%s', '%s')",
        mysqli_real_escape_string($con, $_POST['navn']),
        mysqli_real_escape_string($con, $_POST['kommentar']),
        mysqli_real_escape_string($con, $_POST['pris']),
        mysqli_real_escape_string($con, $_POST['target']),
        );
 
if (!mysqli_query($con, $sql))
{
    die('Error: ' . mysqli_error($con));
}
echo "menuen er uploaded";
 
mysqli_close($con);

can anyone spot the mistake i made?

Link to comment
https://forums.phpfreaks.com/topic/290514-php-add-to-mysql-doesnt-work/
Share on other sites

 

 

but then i changed a few parameters and now it doesnt. i cant figure out why

What output are you getting? Do you get any errors? If you do post them here in full.

 

What steps have you taken to debug your code? Also make sure you error reporting enabled in your php.ini configuration or add the following two lines at the top of your script

ini_set('display_errors', 1);
error_reporting(E_ALL);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.