473,390 Members | 917 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,390 software developers and data experts.

Compare Form Data to Database

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 18955
ronverdonk
4,258 Expert 4TB
Copied that code to my editor and it runs fine.

Ronald :cool:
Aug 10 '06 #2
Banfa
9,065 Expert Mod 8TB
<?php>

is wrong

should be

<?php

/* Your code here */

?>
Aug 10 '06 #3
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 Expert 4TB
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
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
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
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
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...
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...

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.