Website code

I’m pretty new to PHP but i understand the basics but ive encountered a problem.

My website is using php and html base on a page named index.php the main problem is the checklogin.php page which the index.php submits to, i get this error on my server: Remote server or file not found

Check that the address is spelled correctly, or try searching for the site.

here is the checklogin.php code:

[php]<?php

session_start();

$username = $_POST[‘username’];
$password = $_POST[‘password’];

if ($username&&$password)
{
$connect = mysql_connect(“localhost”,“accessroot”,“hydrocarbon12345”); or die (“Couldn’t connect to database”)
mysql_select_db(“Members”) or die (“Couldn’t find database”)

$query = mysql_query(“SELECT * FROM Main WHERE username=’$username’”);
$numrows = mysql_num_rows($query);

if($numrows !=0)

{

while ($rows = mysql_fetch_assoc($query))

{

$dbusername = $row [‘username’]
$dbpassword = $row [‘password’]

}
if ($username==$dbusername&&$password==$dbpassword)
{
echo “Login successful. index.php</a”";

$_SESSION['username']=$dbusername;

}

else
die (Login Unsuccessful":wink:

}
else
die (“LogiN Unsuccessful”)

}
echo
die (“please enter user and pass”)
}

?>[/php]

Cheers
Chris.

First XXXXX out your passwords and usernames in database connections… Second try 127.0.0.1 instead of localhost.

is your database local or on another machine

Thank you, i assumed that it didn’t matter, ill hide them in the future, the database is stored on a cloud host :slight_smile:

[php] if ($username==$dbusername&&$password==$dbpassword)
{
echo “Login successful. index.php</a”";

$_SESSION['username']=$dbusername;

}

else
die (Login Unsuccessful";)[/php]

there is an error in this statement. you have two “” in the echo line

try

[php] if ($username==$dbusername&&$password==$dbpassword)
{
echo “Login successful. index.php”;

$_SESSION['username']=$dbusername;

}

else
die (“Login Unsuccessful”);[/php]

along with those errors Andrew pointed out
do you and if not have the remote host address in the config and the right privileges and you also have to on the cloud server allow the ip that the website is on to get to the cloud server

The same error is appearing, here is the updated code:

[php]<?php

session_start();

$username = $_POST[‘username’];
$password = $_POST[‘password’];

if ($username&&$password)
{
$con = mysql_connect(“XXXX”,“XXXXX”,“XXXX”);
echo
if (!$con)
{
die('Could not connect: ’ . mysql_error());
}

$query = mysql_query(“SELECT * FROM Main WHERE username=’$username’”);
$numrows = mysql_num_rows($query);

if($numrows !=0)

while ($rows = mysql_fetch_assoc($query))
}

$dbusername = $row [‘username’]
$dbpassword = $row [‘password’]

}
{

if ($username==$dbusername&&$password==$dbpassword)
{
echo “Login successful. index.php”;

$_SESSION['username']=$dbusername;

}

else
die (Login Unsuccessful":wink:

}
{
echo
die (“please enter user and pass”)
}
?>[/php]

I don’t understand what you mean by remote host address? the website and database is located on the cloud server i simply upload via ftp and change the database properties remotely.

Cheers
Chris.

Your connecting to localhost in your connection line you will need to place the server address there instead. I can copy my DB connection script here if you like. It uses OOP and functions to do all the database connections and queries.

The db and website are all located on thier servers tho?

and yea your code will be helpfull :slight_smile:

Cheers
Chris

i don’t know if this is anyhelp but i ran my code through an online checker for common mistakes and got these errors?

Error: There is 1 more closing curly braces ‘}’ than expected
PHP Syntax Check: Parse error: syntax error, unexpected T_IF in your code on line 12

Cheers
Chris

A lot of the time your database/site is not the only one on a given server. Godaddy for example uses multiple webhosts on a single server so you would need to get your database address from your host. using localhost or 127.0.0.1 directs the user to the local machine in a shared hosting environment that is not practical so each host is granted an address. If you need help finding your database address let me know. Below is my database connection script.

[php]<?php

class database {
var $host = “127.0.0.1”;
var $databaseName = “development”;
var $user = “XXXXXXX”;
var $password = ‘XXXXXXXXX’;
var $connectID = 0;
var $queryID = 0;
var $record = array();
var $row;
var $loginError = “”;
var $errorNo = 0;
var $error = “”;

function connect() {
	if ($this -> connectID == 0){
		$this -> connectID = mysql_connect($this -> host, $this -> user, $this -> password);
	}
	if (!$this -> connectID) {
		$this -> disconnect("Connection ID returned \"False\", Host Connection Failed ");
	}
	if (!mysql_query(sprintf("use %s ", $this -> databaseName), $this -> connectID)) {
		$this -> disconnect("Coud not connect to database. ".$this -> databaseName);
	} 
}

function query($queryString) {
	$this -> connect();
    $this -> connectID = mysql_query($queryString, $this -> connectID);
    $this -> row = 0;
    $this -> errorNo = mysql_errno();
    $this -> error = mysql_error();
    if(!$this -> connectID) {
        $this -> disconnect( "Invalid SQL: ".$queryString);
    }
    return $this -> queryID;
}

function disconnect($message) {
	printf("<strong>Database Error:</strong> %s ", $message);
	printf("<strong>MySQL Error:</strong> %s (%s) ", $this -> errorNo, $this -> error);
	die("Session Disconnected.");
}

function nextRecord() {
	@ $this -> record = mysql_fetch_array($this -> queryID);
	$this -> row += 1;
	$this -> errorNo = mysql_errno();
	$this -> error = mysql_error();
	$stat = is_array($this -> record);
	if (!$stat) {
		@ mysql_free_result($this -> queryID);
		$this -> queryID = 0;
	}
	return $stat;
}

function singleRecord() {
	$this -> record = mysql_fetch_array($this -> queryID);
	$stat = is_array($this -> record);
	return $stat;
}

function numRows() {
	return mysql_num_rows($this -> queryID);
}

function lastID() {
	return mysql_insert_id();
}

function affectedRows() {
	return mysql_affected_rows();
}

function numFields() {
	return mysql_num_fields($this -> queryID);
}

}

?>[/php]

AHHH! of course! thank you! i will need help finding that, ive looked all over the myphp ‘panels’ will i need to email them for it? or can i find it? the host gives Plesk Panels to its clients.

Try looking on the panel where you access the database directly for more information or the address. There is a good chance it is listed there. If all else fails email them.

They’ve replied to my email and are 100% it is local host. I don’t know what else to try now D:

ok copy the exact text of the error you receive. Is it possible that you typoed the file name in the form.

index.php page code:
[php]

[/php]

and the checklogin.php page code:

[php]<?php

session_start();

$username = $_POST[‘username’];
$password = $_POST[‘password’];

if ($username&&$password)
{
$con = mysql_connect(“127.0.0.1”,“AdminChris”,“Delta3753ASL”);
echo
if (!$con)
{
die('Could not connect: ’ . mysql_error());
}

$query = mysql_query(“SELECT * FROM Main WHERE username=’$username’”);
$numrows = mysql_num_rows($query);

if($numrows !=0)

while ($rows = mysql_fetch_assoc($query))
}

$dbusername = $row [‘username’]
$dbpassword = $row [‘password’]

}
{

if ($username==$dbusername&&$password==$dbpassword)
{
echo “Login successful. index.php”;

$_SESSION['username']=$dbusername;

}

else
die (Login Unsuccessful":wink:

}
{
echo
die (“please enter user and pass”)
}
?>[/php]

And the recieved error when i enter a username and password on the index and submit it which leads to the checklogin.php page, this error shows but no page:
[b]
Remote server or file not found

Check that the address is spelled correctly, or try searching for the site.[/b]

Login
Username :
Password :
   

i keep forgetting to remove my login info, ill change it again once it hath been resolved xD

Ok so that is not a database error or a PHP error. Your form is not able to find the checklogin.php file and is giving you this error. make sure the paths to the files are correct in the HTML.

also fix the Die line on the checklogin.php file your missing a "

I can remove the posts with your login info if you would like but if you change it it should not be an issue down the road.

Sponsor our Newsletter | Privacy Policy | Terms of Service