0

I'm rather new with sql statements in PHP and got following error:

Parse error: syntax error, unexpected '$POST_' (T_VARIABLE) in /home/u544596746/public_html/cobrahd/register.php on line 19

I looked the error up on the Internet, but only found other guys with the same problem for other code.

I would be happy if you could solve my problem.

<?php

        define('DB_HOST', '****');
        define('DB_NAME', '****');
        define('DB_USER','****');
        define('DB_PASSWORD','****');


        $con=mysql_connect(DB_HOST,DB_USER,DB_PASSWORD) or die("Failed to connect to MySQL: " . mysql_error());
        $db=mysql_select_db(DB_NAME,$con) or die("Failed to connect to MySQL: " . mysql_error());

        function register()
        {

            session_start();
            if($_POST["email"]!="" and $_POST["password"]!="" and $_POST["username"]!="" and $_POST["password"]== $_POST["password_confirm"])
            {
                $sql = "INSERT INTO `tblUser`(`UserName`, `Vorname`, `Nachname`, `EMail`, `Geschlecht`, `Geburtsdatum`, `RegestrierungDate`, `Password`, `FKRole`) VALUES ('" .$POST_['username']. "','"$POST_['vorname']. "','" .$POST_['nachname']. "','" .$POST_['email']. "','" .$POST_['geschlecht']. "','" .$POST_['geburtsdatum']. "',Curdate(),'" .$POST_['password']. "',2)";
                echo $sql;

                header('Location: index.php');
            }
            else
            {
                header('Location: 404.html');
            }
        }
        if(isset    ($_POST['submit']))
        {
            register();
        }


    ?>
mega6382
  • 9,211
  • 17
  • 48
  • 69

2 Answers2

2

change the:

            $sql = "INSERT INTO `tblUser`(`UserName`, `Vorname`, `Nachname`, `EMail`, `Geschlecht`, `Geburtsdatum`, `RegestrierungDate`, `Password`, `FKRole`) VALUES ('" .$POST_['username']. "','"$POST_['vorname']. "','" .$POST_['nachname']. "','" .$POST_['email']. "','" .$POST_['geschlecht']. "','" .$POST_['geburtsdatum']. "',Curdate(),'" .$POST_['password']. "',2)";
            echo $sql;

to this:

 $sql = "INSERT INTO `tblUser`(`UserName`, `Vorname`, `Nachname`, `EMail`, `Geschlecht`, `Geburtsdatum`, `RegestrierungDate`, `Password`, `FKRole`) VALUES ('" .$_POST['username']. "','"$_POST['vorname']. "','" .$_POST['nachname']. "','" .$_POST['email']. "','" .$_POST['geschlecht']. "','" .$_POST['geburtsdatum']. "',Curdate(),'" .$_POST['password']. "',2)";
                echo $sql;

there are typographic errors in your code. you are writing POST_ instead of _POST. And also you mysqli_ instead of mysql_ it is deprecated.

EDIT:

There was another error:

you didn't concatenated correctly. Use following

 $sql = "INSERT INTO `tblUser`(`UserName`, `Vorname`, `Nachname`, `EMail`, `Geschlecht`, `Geburtsdatum`, `RegestrierungDate`, `Password`, `FKRole`) VALUES ('" .$_POST['username']. "','" . $_POST['vorname']. "','" .$_POST['nachname']. "','" .$_POST['email']. "','" .$_POST['geschlecht']. "','" .$_POST['geburtsdatum']. "',Curdate(),'" .$_POST['password']. "',2)";
mega6382
  • 9,211
  • 17
  • 48
  • 69
  • I see my mistake and changed it in the code. But now i get another Parse error: Parse error: syntax error, unexpected '$_POST' (T_VARIABLE) in /home/u544596746/public_html/register.php on line 18 this is line 18: ```$sql = "INSERT INTO `tblUser`(`UserName`, `Vorname`, `Nachname`, `EMail`, `Geschlecht`, `Geburtsdatum`, `RegestrierungDate`, `Password`, `FKRole`) VALUES ('" .$_POST['username']. "','"$_POST['vorname']. "','" .$_POST['nachname']. "','" .$_POST['email']. "','" .$_POST['geschlecht']. "','" .$_POST['geburtsdatum']. "',Curdate(),'" .$_POST['password']. "',2)";``` – Benjamin Pössenberger Jan 14 '16 at 08:13
  • @BenjaminPössenberger check edit in my answer. – mega6382 Jan 14 '16 at 08:23
0

Change

$POST_  

to

$_POST

The valid syntax is $_POST

Danyal Sandeelo
  • 12,196
  • 10
  • 47
  • 78