0

Hello,
I have started learning php and mysql recently, and I have run into problems. I received this code: *
Parse error: syntax error, unexpected 'average_user' (T_STRING)* and the problem is that I granted SELECT to average_user in the databse, but it is coming up with an error. What is with it? The code looked like this : <?php $dsn= 'mysql :host=localhost; dbname=my_store"; $username='average_user'; $password='password'; try{ $db=new PDO ($dsn,$username,$password)} catch (PDOexception $e){$error_message=$e->get_message(); include (database_error.php); exit();}?>
Anything stick out? Thanks

3
Contributors
6
Replies
8
Views
4 Years
Discussion Span
Last Post by vivosmith
0

@vivosmith

Parse error: syntax error, unexpected 'average_user' (T_STRING)* and the problem is that I granted SELECT to average_user in the databse, but it is coming up with an error. What is with it?

<?php 
$dsn= 'mysql:host=localhost; 
dbname=my_store"; 
$username='average_user'; 
$password='password'; 
try{ $db=new PDO ($dsn,$username,$password)} 
catch (PDOexception $e){$error_message=$e->get_message();include (database_error.php); exit();}
?>

On your first line:

$dsn= 'mysql:host=localhost;

you are missing a qoute at the end '

It should be this:

$dsn= 'mysql:host=localhost';

Please read this if you are using PDO.

http://www.daniweb.com/web-development/php/code/435142/using-phppdo-with-error-checking

It's a nice tutorial about PDO. Much more organized.

Edited by LastMitch: grammer

0

So because average_user is connected to localhost, and localhost is not registered properly, it won't show up?

0

The error indicated that the string was not terminated correctly. It has nothing to do with the actual user in MySQL.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.