Jump to content

php add to mysql doesnt work


loxfear
Go to solution Solved by jazzman1,

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
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);
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.