Bandyleg Posted December 25, 2012 Share Posted December 25, 2012 Hi everyone, Please could you help me in understanding why this code wont work, If i am right in what i have been trying the problem is with my sql statement, But i have only been doing this for a few weeks and some of the information i have been reading isnt always helpful as i do not fully understand how everything works yet, This is for a college assignment i have been given.I have not just got stuck and gone someone do this for me, I have looked into my problems but lack the knowledge to fully understand and fix it. All help is greatly received anything you see with // in front of it is for info purpose for myself and will hopefully help make things a little cleared for you guys when offering your help <?php$host="localhost"; // Host name$username="root"; // Mysql username$password=""; // Mysql password$db_name="assignment"; // Database name$tbl_name="customers"; // Table name$session="CustomerId";// session// 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 form.$myusername=$_POST['myusername'];$mypassword=$_POST['mypassword'];// To protect MySQL injection.$myusername = stripslashes($myusername);$mypassword = stripslashes($mypassword);$myusername = mysql_real_escape_string($myusername);$mypassword = mysql_real_escape_string($mypassword);$sql= "SELECT FirstName and Password FROM '£tbl_name' WHERE FirstName= ('$myusername'), Password=('$mypassword')";$result=mysql_query($sql);// Mysql_num_row is counting table row$count=mysql_num_rows($result) or die;// If result matched $myusername and $mypassword, table row must be 1 rowif($count=1){// Register $myusername, $mypassword and redirect to file "login_success.php"session_start();$_SESSION=$_POST['CustomerId'];echo "Login Successful<p> Click here <a href= 'customerhomepage.php'> to continue to your account</a></p>";}else {echo "Wrong Username or Password";}?> This is the complete error Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\martins_assignment\Images\login2.php on line 23 Link to comment Share on other sites More sharing options...
thescientist Posted December 25, 2012 Share Posted December 25, 2012 you should look at the top most pinned thread in this (PHP) forum.http://w3schools.invisionzone.com/index.php?showtopic=44106 Link to comment Share on other sites More sharing options...
Bandyleg Posted December 25, 2012 Author Share Posted December 25, 2012 Hi and thankyou for the reply, I had previously looked at the link you have provided, but had misunderstood it, as i said i am very new to this. I have managed to remove all the syntax errors that i was whining about. It has now fired this at me Operand should contain 1 column(s)I will go and try to find out this problem but if u know of a specific location that is useful it would be appreciated. Thankyou. Link to comment Share on other sites More sharing options...
Ingolme Posted December 26, 2012 Share Posted December 26, 2012 I think that's probably the comma in the WHERE clause. That should be an AND. And the "and" after SELECT should actually be a comma. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now