473,411 Members | 1,937 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

Help with login script

Hi everyone

i am having errors with my code to login to a webpage i keep getting errors and when i fix the errors i encounter another problem which keeps saying wrong username or password but the username and password i used to test are correct

here is my code and the table which it is trying to read from contains the fields:
Username
Pword
Email
ID

any help would be greatly apprietiated thanks!

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>

<body>

<?php

// Connect to server and select databse.
$con = mysql_connect('localhost','southpaw','spawboxing') ;
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("$southpawboxing", $con);

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

$query = mysql_query("SELECT * FROM onlinedetails WHERE Username='$myusername' AND Pword='$mypassword'");
$result=mysql_query($query);

// 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:loginsuccess.php");
}
else {
echo "Wrong Username or Password";
}
?>


</body>
</html>
Mar 20 '07 #1
2 1262
code green
1,726 Expert 1GB
$_POST is an array containing values within HTML entities from a submitted web form. You have no HTML form in the body text therefore $_POST is empty.
This would not have happened if your code didn't assume far too much and had error checking.
Mar 21 '07 #2
i have added some more to my code but i am now recievig this error and my username and password are correct (any help would be appreciated thanks)

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\wamp\www\Practice\Login\checklogin.php on line 27
Wrong Username or Password

line 27 is in bold:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<?php
// Connect to server and select databse.
$con = mysql_connect('localhost','southpaw','spawboxing') ;
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("$southpawboxing", $con);
// username and password sent from signup form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];

$query = mysql_query("SELECT * FROM onlinedetails WHERE Username='$myusername' AND Pword='$mypassword'");
$result=mysql_query($query);
// 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:loginsuccess.php");
}
else {
echo "Wrong Username or Password";
}
?>
<table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form method="post">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td colspan="3"><strong>Member Login </strong></td>
</tr>
<tr>
<td width="78">Username</td>
<td width="6">:</td>
<td width="294"><input name="myusername" type="text" id="myusername"></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input name="mypassword" type="text" id="mypassword"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><input type="submit" name="Submit" value="Login"></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
</body>
</html>

Read the Posting guidelines, especially the part about enclosing shown code within code or php tags before you post any further in the forum!!

moderator
Mar 23 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Ralph Freshour | last post by:
I bought the PHP and MySQL For Dummies book and I'm having trouble understanding how I use PHP to verify and check forms input text data - the book shows snippets of code so I know how to do the...
6
by: Dal | last post by:
Help! I'm trying to get a login script to work. I get this error message MySQL Login Error: You have an error in your SQL syntax near ''jvsd0001_customers` WHERE cust_name='testuser' AND...
3
by: f700b | last post by:
I have the bellow javascript code. I know the username and the password , and I like to modify this code for login without press intro. It is possible?. Thanks --------------------------------...
0
by: Joe | last post by:
i posted similar to vb forum but without success. Can anyone help here I have been wrestling with a problem for days. The solution is probably simple but i am not that experienced with html. I...
23
by: casper christensen | last post by:
Hi I run a directory, where programs are listed based on the number of clicks they have recieved. The program with most clicks are placed on top and so on. Now I would like people to be apple to...
5
eragon
by: eragon | last post by:
I am making a password script, i have most of it done, ill show you, but i hit a brick wall.... lol, I have it so when you log in it takes you to your main page, that works, but when you enter the...
1
by: Tarcetial | last post by:
Im trying to make a personal website with a log in/registration system. I found some help with the log in and now i just need some help with the registration. This is the coding im already using: ...
5
by: silmana | last post by:
hello, i have this problem that i cannot bound the registration script to the login script, what i mean is that when i register, i cannot login in the login script although the information comes to...
6
by: KDawg44 | last post by:
Hi, My responseXML is always null on my AJAX call. When I browse directly to the PHP script I am calling, the XML file shows up just fine. I have read that if a returned XML file is not...
0
by: richard12345 | last post by:
Hi Guys I have problem with site I am building. The sidebar with menu and other thinks is overlapping footer. The footer move with the content and but it dos it dos not move with the sidebar. ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.