-1

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.

Pararera
  • 363
  • 3
  • 15
  • `$_hsync_srv` is what, a string? Your question's unclear. and did you Google that error? Too many possible reasons. – Funk Forty Niner Apr 30 '16 at 23:16
  • `$_hsync_srv = "_HRP_SRV"` It's table name. – Pararera Apr 30 '16 at 23:17
  • 2
    http://stackoverflow.com/questions/23515347/how-can-i-fix-mysql-error-1064 – Funk Forty Niner Apr 30 '16 at 23:23
  • That person who gave you that answer is giving you false information and did not put much effort into research. Plus, he didn't tell you "how" to use it. I've no idea why you accepted it. TBH, that `hex` had me thinking earlier, but I didn't have the time to "research" it (till now), and have spent the "time" to do it in their place. – Funk Forty Niner May 01 '16 at 00:17

2 Answers2

1

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.

I.e.:

$_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.
Community
  • 1
  • 1
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
  • Error is still here - http://i.imgur.com/pyc71bn.png It's between Godine and MasaSala. – Pararera May 01 '16 at 11:03
  • I echo whole query, and `$_hsync_spol` needs to be 0 or 1, but it's on(word on). Why? Here's core for `$_hsync_spol` - `$_hsync_spol = $_POST['_hsync_spol'];` HTML part `
    `
    – Pararera May 01 '16 at 11:09
  • 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. – Pararera May 01 '16 at 11:28
  • 1
    @SilvioCro ah, so there was an empty value going in the query then. I had a feeling about that from the beginning. I'm glad this was resolved to 100%, *cheers* and you're welcome. – Funk Forty Niner May 01 '16 at 12:56
  • @SilvioCro I noticed you unaccepted my answer and posted a new question http://stackoverflow.com/q/36966979/ why is that? – Funk Forty Niner May 01 '16 at 13:05
  • @SilvioCro I've made an edit to further outline how to debug code during development and have included your comment. This I feel has fulfilled the question's issues. – Funk Forty Niner May 01 '16 at 14:16
0

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

Atul Jindal
  • 946
  • 8
  • 8
  • Thanks! So I need put hEx into [ and ] ? – Pararera Apr 30 '16 at 23:52
  • https://dev.mysql.com/doc/refman/5.5/en/keywords.html I don't see `hex` in there as being a MySQL reserved word. Why did you accept this answer? @SilvioCro `HEX()` is a function used for Hexadecimal Literals https://dev.mysql.com/doc/refman/5.7/en/hexadecimal-literals.html not a reserved word. Additional reference http://dev.mysql.com/doc/refman/5.7/en/string-functions.html *"Return a hexadecimal representation of a decimal or string value"* – Funk Forty Niner May 01 '16 at 00:13
  • I didn't knew that's a function. Thanks! – Pararera May 01 '16 at 10:44