473,883 Members | 1,687 Online
Bytes | Software Development & Data Engineering Community
+ 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 19302
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_quer y("select * from login");
while($log=mysq l_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_arr ay(): 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_arr ay(): 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_conn ect("localhost" ,"root","") or die("error".mys ql_error);
mysql_select_db ("asc",$con) ;
$sel=mysql_quer y("select * from login");
while($log=mysq l_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
6159
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 allready made the database with the neccesary tables, and I know how to connect to it ) but I really have no idea how I can transfer the data from the webform to
10
19369
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 able to fill that one out just fine. The second form is multipart/form-data. Unfortunately, I haven't been able to fill that out in a way that makes the server happy. I set up a copy of this form at my web site so that I could see exactly what a...
3
1922
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
4749
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 setup, i'm running an sql server locally, i've created the database, table and fields. I think what i'm missing is something that actually runs the sql query when i hit the submit button. Also, i'm aware i haven't made the data being inserted safe, i...
3
2403
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 use PHP to process the form data, but can someone tell me how? I've read about using MySQL, but I want to keep this as simple as possible. Can I just put the information directly into an excel database? Or do I have to put the information into a CSV...
3
6061
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 progress bar). Everything works great; except that currently I'm not decoding the POST in PERL; so the data file being written is the actual raw form data (multipart/form-data) with parameters and file content. I know that when you make a post to...
12
10660
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 completed document to a variable directory based on form data. What I need to code into it now is a button that creates an email. The email has the same basic text each time but just needs to draw a
1
1342
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 empty row. Here is my code. Add to database section ( i have removed the connectionstring for privacy reasons) <%@ Page aspcompat="true" Debug="true" %> <html> <head>
0
9933
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
9781
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11121
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10734
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10836
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5793
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5982
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4606
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4210
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.