By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,967 Members | 1,183 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,967 IT Pros & Developers. It's quick & easy.

stuck

P: n/a
how can i resolve this:

Warning: mysql_connect() [function.mysql-connect]: Lost connection to
MySQL server during query in /home/fhlinux169/c/clashoff.co.uk/user/
htdocs/checklogin.php on line 9
cannot connect

this is the script. please help.very stuck

<?php
$host="localhost"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name="test"; // Database name
$tbl_name="members"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot
connect");
mysql_select_db("$db_name")or die("cannot select DB");

// username and password sent from signup form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];

$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and
password='$mypassword'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1
row

if($count==1){
// Register $myusername, $mypassword and redirect to file
"login_success.php"
session_register("myusername");
session_register("mypassword");
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
}
?>

Aug 8 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On Aug 8, 5:44 pm, Reggie <joelregisfo...@hotmail.comwrote:
how can i resolve this:

Warning: mysql_connect() [function.mysql-connect]: Lost connection to
MySQL server during query in /home/fhlinux169/c/clashoff.co.uk/user/
htdocs/checklogin.php on line 9
cannot connect

this is the script. please help.very stuck

<?php
$host="localhost"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name="test"; // Database name
$tbl_name="members"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot
connect");
mysql_select_db("$db_name")or die("cannot select DB");

// username and password sent from signup form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];

$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and
password='$mypassword'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1
row

if($count==1){
// Register $myusername, $mypassword and redirect to file
"login_success.php"
session_register("myusername");
session_register("mypassword");
header("location:login_success.php");}

else {
echo "Wrong Username or Password";}

?>
I can't really see anything obviously wrong...although I like to
specify my link handles ie. $db = mysqlconnect() and specify $db
throughout
run mysqladmin...what is the connect_timeout set to?

Aug 8 '07 #2

P: n/a
Give username as root and password as null and then check

Aug 9 '07 #3

P: n/a
al**********@gmail.com wrote:
Give username as root and password as null and then check
Not his problem - he's connecting just fine.

And username of root with no password is about as insecure as you can get.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Aug 9 '07 #4

P: n/a
On Aug 8, 5:44 pm, Reggie <joelregisfo...@hotmail.comwrote:
how can i resolve this:

Warning: mysql_connect() [function.mysql-connect]: Lost connection to
MySQL server during query in /home/fhlinux169/c/clashoff.co.uk/user/
htdocs/checklogin.php on line 9
cannot connect

Does your user have privileges in MySQL to do the operation on line 9
of your code (SELECT database?) I believe you get disconnected if you
are not authorized to execute a query.

Aug 9 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.