0

For some reason I am having a really difficult time getting my PDO connection to work. I am entering the correct host, username and password that has allowed me to get into the same database, but other tables.

I have my connection setup like the following, other than the actual username, password and db entered in. I have checked it 10x and it is the correct information.

The latest error I have recieved in the error reporting file is this:

[25-Oct-2016 13:22:07 America/Chicago] PHP Parse error: syntax error, unexpected '$servernameCon' (T_VARIABLE)

I have changed localhost to the Dedicated IP Address, which I do not have to do for any other connection on my site, and even doing this still doesn't help.

I am at a loss for what I am doing wrong. Does anyone see anything I am missing?

    $servernameCon = 'localhost';
    $usernameCon = ' ';
    $passwordCon = ' ';

    $con = new PDO('mysql:host='.$servernameCon.';dbname= ', $usernameCon, $passwordCon);
    $con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

Before $servernameCon:

ini_set('display_errors', 1);
error_reporting(E_ALL);
require_once 'core/init.php';

if(Input::exists()) {
    if(Token::check(Input::get('token'))) {

        if(Input::exists()) {
            $validate = new Validate();
            $validation = $validate->check($_POST, array(
                'firstname' => array(
                    'required' => true,
                    'min' => 2,
                    'max' => 50
                ),
                'lastname' => array (
                    'required' => true,
                    'min' => 2,
                    'max' => 50
                ),
                'email' => array (
                    'required' => true,
                    'min' => 2,
                    'max' => 50
                ),
                'phone' => array (
                    'required' => true,
                    'min' => 7,
                    'max' => 12
                ),
                'network' => array (
                    'required' => true
                ),
                'birthday' => array (
                    'required' => true
                ),
                'username' => array(
                    'required' => true,
                    'min' => 4,
                    'max' => 20,
                    'unique' => 'users'
                ),
                'password' => array(
                    'required' => true,
                    'min' => 6
                ),
                'password_again' => array(
                    'required' => true,
                    'matches' => 'password'
                )

            ));
            if($validation->passed()) {
                $user = new User();

                $salt = Hash::salt(32);

                try {

                    $user->create(array(
                        'firstname' => Input::get('firstname'),
                        'lastname' => Input::get('lastname'),
                        'email' => Input::get('email'),
                        'phone' => Input::get('phone'),
                        'network' => Input::get('network'),
                        'birthday' => Input::get('birthday'),
                        'username' => Input::get('username'),
                        'password' => Hash::make(Input::get('password'), $salt),
                        'salt' => $salt,
                        'joined' => date('Y-m-d H:i:s'),
                        'group' => 1
                    ));

                    ($user->lastId);

                    //Add user to posts table
                    if(isset($_POST['submit'])){
                        $id = ( isset( $_SESSION['id'] ) ? $_SESSION['id'] : "" );
                        $user_id = $user->lastId;
                        $posts = 0;
                        $conversations = 0;
Paul
  • 3,348
  • 5
  • 32
  • 76
  • What is before line `$servernameCon = 'localhost';`? – u_mulder Oct 25 '16 at 18:58
  • as per the gazillions of dupes on this site: you forgot something on an EARLIER line, and the line number in your error is merely the first place where that missing something caused a parse error. – Marc B Oct 25 '16 at 18:59
  • Is php_pdo_sql extension enabled in php.ini? – Rehban Khatri Oct 25 '16 at 19:00
  • I added what was before the servernamecon variable. – Paul Oct 25 '16 at 19:00
  • I didn't forget anything on an earlier line, nor am I a dupe, get over yourself. How can I check it see if it is enabled? – Paul Oct 25 '16 at 19:02
  • Anyone?? I have no idea what I am doing wrong. – Paul Oct 25 '16 at 19:13
  • Just for your information: stack overflow is not a support forum. Here we can answer certain questions, like "how to do something". While questions "why my code doesn't work" are off topic. But yeah, sometimes you get that forum in the comments. Ok, did you fix your syntax error? – Your Common Sense Oct 25 '16 at 19:35
  • @YourCommonSense I know it isn't and I appreciate any help I receive from here. No, I didn't fix the syntax because I do not see where any syntax is wrong. – Paul Oct 25 '16 at 19:42

0 Answers0