Parse error: syntax error, unexpected end of file [closed] - php

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
My code looks like this and on my page (w-o-l.ml/login.php) it displays this message
Parse error: syntax error, unexpected end of file in /home/u536535282/public_html/includes/config.php on line 36
<?php
ob_start();
session_start();
//set timezone
date_default_timezone_set('America/New_York');
//database credentials
define('DBHOST','mysql.hostinger.co.uk');
define('DBUSER','u536535282_evan7');
define('DBPASS','anaavcnM9t7');
define('DBNAME','u536535282_dbsql');
//application address
define('DIR','http://w-o-l.ml/');
define('SITEEMAIL','it#w-o-l.ml');
try {
//create PDO connection
$db = new PDO("mysql:host=".DBHOST.";port=8889;dbname=".DBNAME, DBUSER, DBPASS.");
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
//show error
echo '<p>'.$e->getMessage().'</p>';
exit;
}
//include the user class, pass in the database connection
include('classes/user.php');
include('classes/phpmailer/mail.php');
$user = new User($db);
?>
if someone could point me to what is wrong i would appreciate it

Looking at how SO parsed your code, I would say that
$db = new PDO("mysql:host=".DBHOST.";port=8889;dbname=".DBNAME, DBUSER, DBPASS.");
should be
$db = new PDO("mysql:host=".DBHOST.";port=8889;dbname=".DBNAME, DBUSER, DBPASS);

Related

how do i fix this error PHP log in error user not found [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 days ago.
Improve this question
Im new to php and im building a login and registration form.
Everything works except when i click log in with a user credentials that are in my database my error for "user not found is showing.
I've included the code snippet for my error to see if i have typed something wrong.
protected function getUser($email, $pwd)
{
$stmt = $this->connect()->prepare("SELECT pwd FROM web WHERE lName = ? OR Email = ?;");
if (!$stmt->execute(array($email, $pwd))) {
$stmt = null;
header("location: ../index.php?error=stmtfailed");
exit();
}
if ($stmt->rowCount() == 0) {
$stmt = null;
header("location: ../index.php?error=usernotfound");
exit();
}
$pwdHashed = $stmt->fetchAll(PDO::FETCH_ASSOC);
$checkPwd = password_verify($pwd, $pwdHashed[0]["pwd"]);
if you need any more info let me know!

Same connection file works for 1 script but not the other [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I have a directory with 2 php files in it. One is using an old way of querying a DB and the other can't even tell me if the connection exists.
the connection file: (I've left out the actual credentials for obvious reasons)
<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_student_dirR = "some_hostname";
$database_student_dirR = "some_db_name";
$username_student_dirR = "some_username";
$password_student_dirR = "some_password";
$student_dirR = new mysqli($hostname_student_dirR, $username_student_dirR, $password_student_dirR, $database_student_dirR) or trigger_error(mysqli_error(),E_USER_ERROR);
?>
file that successfully connects:
<?php require_once('../Connections/student_diriR.php'); ?>
<?php
mysqli_select_db($student_dirR, $database_student_dirR);
$query_rs_get = "SELECT some_column FROM directory";
$rs_get = mysqli_query($student_dirR, $query_rs_get) or die(mysqli_error($student_dirR));
$row_rs_get = mysqli_fetch_assoc($rs_get);
$totalRows_rs_get = mysqli_num_rows($rs_get);
?>
file that does NOT connect: (in the exact same directory as the file that does connect, so that path can't be the issue)
<?php require_once("../Connections/student_dirR.php"); ?>
<?php
if($student_dirR) echo "we're connected!";
else echo "we're NOT connected!"; exit;
?>
The error message I get says "Fatal error: Uncaught Error: Call to undefined function mysql_connect() in Connections/student_dirR.php:9"
Line 9 uses new mysqli() not mysql_connect(), so I don't know what that's talking about.
See you have the spelling mistake in your directory name student_diriR.php and
student_driR.php that's why the error says Call to undefined function mysql_connect().
see the difference below
file that successfully connects:
<?php require_once('../Connections/student_diriR.php'); ?>
file that does NOT connect:
<?php require_once("../Connections/student_dirR.php"); ?>

fatal error - cannot connect to database [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I'm trying to create a simple php blog and downloaded demo files from here - https://daveismyname.com/creating-a-blog-from-scratch-with-php-bp.
Creating database (named blog01) and tables was sucessful.
On index.php I have an error:
Fatal error: Uncaught exception 'PDOException' with message ' in D:\localhost\blog-01\includes\config.php on line 11
config.php:
define('DBHOST','localhost');
define('DBUSER','username');
define('DBPASS','password');
define('DBNAME','blog01');
$db = new PDO("mysql:host=".DBHOST.";port=8889;dbname=".DBNAME, DBUSER, DBPASS);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
I tried all combinations of username and password (demo, admin...) without success.
Also tried without port=8889.
php version - 5.6.14
Any help.
You can add a try and a catch to see the message of the exception:
try {
$db = new PDO("mysql:host=".DBHOST.";port=8889;dbname=".DBNAME, DBUSER, DBPASS);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
echo $e->getMessage();
exit;
}
The port is only needed when the port is not the same as the default port (3306 for mysql)
If that is the case then the connection is:
$db = new PDO("mysql:host=".DBHOST.";dbname=".DBNAME, DBUSER, DBPASS);

Hi am new to hostgator cpanel.I get this database connection error when testing my website [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I have hidden other details for security purposes
SQLSTATE[28000] [1045] Access denied for user 'cPanelUsername_databaseUsername'#'localhost' (using password: YES) Fatal error: Call to a member function prepare() on a non-object in /home3/username/public_html/domai/AppINIT.php on line 25
appINIT.php configuration settings
<?php
$db_host = "localhost";
$db_port = "80";
$db_user = "cPanelUsername_databaseUsername";
$db_password = "xxxxxxx";
$db_name = "cPanelUsername_databaseName";
define("EXT", '.php');
$licensekey = ""; #License Key
$secret = "yyyy"; #Secuirity Salt
?>
//prepared statement
$stmt = $dbh->prepare("select * from appconfig"); $stmt->execute(); $result = $stmt->fetchAll();
thanks in advance
There is no $dbh variable, so you can't call prepare() on it.

Not able to connect to MySQL server using PDO [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I have a PHP script which I use to connect to a MySQL database. Connection through mysql_connect works perfectly, but when trying with PDO I get the following error:
SQLSTATE[HY000] [2005] Unknown MySQL server host 'hostname' (3)
the code I use to connect is below:
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
$hostname_localhost ="hostname";
$database_localhost ="dbname";
$username_localhost ="user";
$password_localhost ="pass";
$user = $_GET['user'];
$pass = $_GET['pass'];
try{
$dbh = new PDO("mysql:host=$hostname_localhost;dbname=$database_localhost",$username_localhost,$password_localhost);
echo 'Connected to DB';
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $dbh->prepare("SELECT check_user_company(:user,:pass)");
$stmt = $dbh->bindParam(':user',$user,PDO::PARAM_STR, 16);
$stmt = $dbh->bindParam(':pass',$pass,PDO::PARAM_STR, 32);
$stmt->execute();
$result = $stmt->fetchAll();
foreach($result as $row)
{
echo $row['company_id'].'<br />';
}
$dbh = null;
}
catch(PDOException $e)
{
echo $e->getMessage();
}
?>
Thanks in advance
Got the same problem. Mine solution was another database port. I wrote localhost:1234 and got this error.
Fixed with:
mysql:host=$hostname_localhost;port=1234;dbname=$database_localhost",$username_localhost,$password_localhost);
echo 'Connected to DB';
It does seem pretty straightforward, here is what I use to build my PDO connectors(noticed your dbname and host are done differently than mine, dunno if that's relevant, but worth a check):
PDO Creation function
require_once('config.inc.php');
function buildDBConnector(){
$dsn = 'mysql:dbname='.C_BASE.';host='.C_HOST;
$dbh = new PDO($dsn, C_USER, C_PASS);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return $dbh;
}
config.inc.php
define('C_HOST','localhost');// MySQL host name (usually:localhost)
define('C_USER','sweetUsername');// MySQL username
define('C_PASS','sweetPassword');// MySQL password
define('C_BASE','superGreatDatabase');// MySQL database
And while it makes no sense, when I tried to declare $dsn inline including variables during the newPDO call, I kept getting failures too. I broke it apart and used the $dsn variable to do so. And haven't had an issue since.
Wondering if you're in shared hosting by chance?
NOTE:
If you don't have a dedicated IP, and instead are going through a NAT, your IP won't properly translate to your actual server.
That help at all?
UPDATE:
Just thought of another thing. Are you trying to connect to a mysql database that is on a different IP than you are running your scripts from? If so, you will likely need to enable remoteSQL access for the ip you are calling the database from. Fairly easy to do, but CRITICAL if you are not accessing localhost.
You dont seem to specify the database host dns details or IP address. Adding that will solve the problem

Categories