473,473 Members | 1,477 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Compare Form Data to Database

5 New Member
Hi

I am trying to write a (very) basic script to compare data retrieved from a form with a mySQL database. In this case it is a simple name and password entry - if there is a corresponding entry in the database, then it prints a simple sucess message, and if not a failure messge.....

The script looks like this, and I get ' parse error, line 25,( somewhere after $query)

Any ideas?


<?php>

// compares values entered in login page form with mySQL database, and then directs either to protected page or to a failure page

$fn = trim($_POST['nameone']);
$pw = trim($_POST['password']);

$link = mysql_connect ('localhost', 'root', 'purple');
mysql_select_db ("phptest");


// if $fn and $pw match a record, then display page, else display failure page

$query = "SELECT firstname, password FROM mailinglist WHERE (firstname = '$fn' AND password = '$pw')";

$result = mysql_query ($query, $link);
if (mysql_num_rows($result) == 1) {
print 'Good to go' ;
} else {
print 'Sorry, this login is invalid' ;
}
Aug 10 '06 #1
7 18980
ronverdonk
4,258 Recognized Expert Specialist
Copied that code to my editor and it runs fine.

Ronald :cool:
Aug 10 '06 #2
Banfa
9,065 Recognized Expert Moderator Expert
<?php>

is wrong

should be

<?php

/* Your code here */

?>
Aug 10 '06 #3
hemashiki
34 New Member
i think you went wrong with the AND keyword in the select query.It must be &&
try this.

$sel=mysql_query("select * from login");
while($log=mysql_fetch_array($sel))
{

if($_POST['uname']==$log['uname'] && $_POST['pword']==$log['pword'])
{
echo"success";
}
}
Aug 12 '06 #4
ronverdonk
4,258 Recognized Expert Specialist
That is not correct Hemashiki. You can use either the && or the AND in these expressions (also || or OR, etc.).

Ronald :cool:
Aug 12 '06 #5
dubdave
5 New Member
OK

1) Yes <?php> is wrong - slapped wrist! - ( and I left the ?> off....) but removing the extra bracket still produces the same parse error

2) Hemashiki's script produces this error:_

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource.

3) Ronverdonk - could I ask you what OS and version of php you are running? - I am on Apple OSX 10.3.9, and php version 4.3.10


All help is gratefully received and acknowledged - this is as simple as it gets, and really ought to work. All the scripts inputting or retrieving data from mySQL are fine -i t's just this comparison of HTML form data to the mySQL database......
Aug 14 '06 #6
hemashiki
34 New Member
OK

1) Yes <?php> is wrong - slapped wrist! - ( and I left the ?> off....) but removing the extra bracket still produces the same parse error

2) Hemashiki's script produces this error:_

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource.

3) Ronverdonk - could I ask you what OS and version of php you are running? - I am on Apple OSX 10.3.9, and php version 4.3.10


All help is gratefully received and acknowledged - this is as simple as it gets, and really ought to work. All the scripts inputting or retrieving data from mySQL are fine -i t's just this comparison of HTML form data to the mySQL database......
For this warning u have to first create a table called "login" with two fields namely uname and pword.and then execute it. Surely u will not get warning
eg:

$con=mysql_connect("localhost","root","") or die("error".mysql_error);
mysql_select_db("asc",$con);
$sel=mysql_query("select * from login");
while($log=mysql_fetch_array($sel))
{
if($_POST['uname']==$log['uname'] && $_POST['pword']==$log['pword'])
{
echo"Success";
}
else
{
echo"login failed";
}
}
Aug 14 '06 #7
dubdave
5 New Member
Thanks for that - the script is now returning messages nicely. ;)
Aug 14 '06 #8

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

Similar topics

12
by: Pete..... | last post by:
Hi all. I have made a webpage where there is a webform where people can fill in their personel information: The code is below: I want to transfer the data to a postgreSQL database ( I have...
10
by: Gregory A Greenman | last post by:
I'm trying to write a program in vb.net to automate filling out a series of forms on a website. There are three forms I need to fill out in sequence. The first one is urlencoded. My program is...
3
by: POLILOP | last post by:
I have a form (which is multipart/form-data) it has a file field and a select. When i submit this form i can get the file but i can't get the value of the select????? any ideas??? Thx
3
by: andrewtayloruk | last post by:
I'm a newbie when it come to things php and i'm having a bit of trouble. I'm trying to insert data from an html form into a mysql database and can't get it to work. Just a few bits about my...
3
by: roseredphoenix | last post by:
Can anyone help me with a form I'm trying to make? I'm trying to make a submission form for my school's literary magazine. I need to put the submitted information into a database. I know I need to...
3
by: jeremy.gehring | last post by:
Hey all, OK I'm not much of a PHP programmer; but needs must as they say. I have written AJAX file upload system that uses a PERL CGI script so that a PHP script can get the progress (nifty...
12
by: DeZZar | last post by:
Hi all, I'll explain my database first. Users input customer details that are required to complete a company document. The document merge etc is all working - the database saves the...
1
by: mattjmacdonald | last post by:
I have a form that i want to be saved to my database. The form is adding a new record to my sql server 2005 database but it is not bringing the text over with it. The new record in my db is just an...
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
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
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,...
1
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.