Log in

View Full Version : Newbie Question - connecting to MySQL with PHP



Transentient
10-15-2011, 09:12 PM
Hi all

I am trying to create a simple login to a webpage. From watching you tube tutorials I have put together the basics, and i understand the processing. However when i run my login processing script i get the following error from the php script:

Parse error: syntax error, unexpected ';'

My code PHP code is, the error occurs at $con = msql_connect("****","*****","****");


$username = $_POST["username"];
$password = $_POST["password"];
$login = $_GET["login"];

if($login=='yes')(

$con = msql_connect("****","*****","****");

msql_select_db("Login");

$get = msql_query("select count(id) FROM Login WHERE user='$username' and pass='$password'");

$result = msql_result($get,0);

if($result!=1}(

echo "Invalid Login";
)Else(
echo "Login Sucessfull";
)
)

Cannot understand the problem when all the examples i have seen show a semi colon at the end of the line as shown?

Am i wrong somewhere else?.....any help would be greatly appreciated

Note I have omitted the actual login details for my SQL database from the line and replaced with stars

thanks

JasonDFR
10-15-2011, 10:29 PM
Pay attention to your parenthesis and brackets. They are different from one another.

Also, it might be a good idea to get used to using tabs, spaces, and line spacing to improve the readability of your code.

This should work:



$username = $_POST["username"];
$password = $_POST["password"];
$login = $_GET["login"];

if($login == 'yes') {

$con = msql_connect("****", "*****", "****");

msql_select_db("Login");

$get = msql_query("select count(id) FROM Login WHERE user='$username' and pass='$password'");

$result = msql_result($get, 0);

if($result != 1) {

echo "Invalid Login";

} else {

echo "Login Sucessfull";

}

}

Transentient
10-15-2011, 11:47 PM
Hi Jason

Many thanks for your help

But i now get this error Fatal error: Call to undefined function msql_connect()

From this line of the previous code $con = msql_connect("mysql19.streamline.net", "homenetne1", "*****");

I have double checked, the server name where the MySQL is hosted is correct, details provided by my host, the Database name is correct, generated by my host, and the password, although not shown here is also correct.

My host also gave me an ip address for the MySQL server, tried this also same error.

Your help is greatly appreciated

Thanks

JasonDFR
10-16-2011, 12:12 AM
Use: mysql_connect(); NOT msql_connect();

if you are using a MySQL database.

Although msql_connect() is a valid function.