简体   繁体   中英

I can't find cause error 1064 | MySQL

I wrote SQL commands. MySQL says there's an error #1064 at line 36(line 36 is empty space/divider). I Know basic MySQL, but I can't find cause.

// TRENUTNI MOD REGISTRACIJE
$_hsync_rezultat = $_hsync_konekcija->query("SELECT Registracija FROM $_hsync_srv");
$_hsync_podatci = $_hsync_rezultat->fetch_assoc();
$_hsync_registracija = $_hsync_podatci["Registracija"];
// LINE 36
// NOVI ID KORISNIKA
$_hsync_rezultat = $_hsync_konekcija->query("SELECT Korisnika FROM $_hsync_srv");
$_hsync_podatci = $_hsync_rezultat->fetch_assoc();
$_hsync_id = $_hsync_podatci["Korisnika"] + 1;
$_hsync_od = 'From: haswell.samp@hotmail.com' . "\r\n";

Maybe error is here? $_hsync_usr is table name.

        $_hsync_konekcija->query("INSERT INTO $_hsync_usr (
    Ime,
    ID,
    Registriran,
    Zaporka,
    ZaporkaMD5,
    IP,
    GPCI,
    Mail,
    Spol,
    Godine,
    Skin,
    MailNotf,
    Datum,
    Vrijeme,
    Visina,
    OstalaMasa,
    MisicnaMasa,
    MasaSala,
    Zeludac,
    Metabolizam,
    PotrebaH2O,
    Opijanje,
    Drogiranje,
    Udarac,
    RastDlaka,
    hEx) VALUES (
    '$_hsync_ime',
    $_hsync_id,
    $_hsync_reg,
    'nista',
    '$_hsync_zaporka_hash',
    'nista',
    'nista',
    '$_hsync_mail',
    $_hsync_spol,
    $_hsync_godine,
    $_hsync_skin,
    $_hsync_mail_notf,
    '$_hsync_datum',
    '$_hsync_vrijeme',
    $_hsync_visina,
    $_hsync_omasa,
    $_hsync_mmasa,
    $_hsync_msala,
    $_hsync_zeludac,
    $_hsync_metabolizam,
    $_hsync_potrebah2o,
    $_hsync_opijanje,
    $_hsync_drogiranje,
    $_hsync_udarac,
    $_hsync_rastdlaka,
    $_hsync_hEx)");

I check it. I'm a bit confused.

Contrary to popular belief:

hex is not a MySQL reserved word.

HEX() is a function used for Hexadecimal Literals

Additional reference http://dev.mysql.com/doc/refman/5.7/en/string-functions.html
"Return a hexadecimal representation of a decimal or string value"

You can use that word, but it needs to be wrapped in ticks if it is required .

Sidenote: But in this case it isn't since it is NOT used as a function.

For example:

RastDlaka,
`hEx`) VALUES (
'$_hsync_ime',

Plus, if you have any string values that are not quoted, then you will need to quote them just as you did for the other ones.

Ie:

$_hsync_rastdlaka,
'$_hsync_hEx')");

Additionally, your present code is open to an SQL injection . Use mysqli with prepared statements , or PDO with prepared statements .


Edit: as far as what the real problem was:

Lol, problem was in input field, I used id instead value for radio buttons. Thanks! I'll check link for prepared statments. It looks a bit complicated. – SilvioCro"

Note to OP: Please post all code relevant to a question's problem, it will leave out all the potential guesswork and others including myself, will be able (or at least help) find a full solution.

Add error reporting to the top of your file(s) which will help find errors.

<?php 
error_reporting(E_ALL);
ini_set('display_errors', 1);

// Then the rest of your code

Sidenote: Displaying errors should only be done in staging, and never production.

Also check for errors against queries:

It will help you during development as will var_dump() and looking at your HTML source (and your console if using JS/Ajax).

  • Remember; the more we have to work with, the less time it takes to provide a solution.

hEx is reserved word in MySQL. So it gives error #1064, as query can't contain reserved works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM