Form submition, implementing php, and sql connect to access database, beginner

I am trying to do a few things in html and php, I have run into a problem though, when I launch the HTML page it renders correctly, but when I click the search button it asks me if I want to open the .php file, I am a little confused at what I am doing wrong, I have not connected it to the database yet, but I should still output the built in error message the code for the HTML page is:

Database Interface

Adjust Points

First Name: Last Name: Work Code: Select... Lateback from Lunch/Break Late 1-15 minutes Late 16-59 minutes Leave Early Late 1 hour or more Call Off Call Off-Monday/Weekend shift Call off/holiday No call, No show Date: Points

New Month?

Lookup Points

First Name: Last Name: Date:

The PHP code for the searcdb.php is:

<?php $sfname = $_Post['sfname']; $slname = $_Post['slname']; $sdate = $_Post['sdate']; //defining variable brought in from form

$sfname = 0;
$slname = 0;
$sdate = 0;
$TP = 0;
//all variables set to a default value of 0

$db = mysql_connect("");
mysql_select_db (“timecard”, $db);
$sql = "Select [First Name], [Last Name], [Total Points] "
. “From employees”
. “Where [First Name] = $sfname and [Last Name] = $slname”;

$rows = mysql_query($sql, $db);

if(!$rows) {
$error = "SQL error: " . mysql_error();
} elseif(mysql_num_rows($rows) == 0) {
$error = “No such user name found”;
} else {
$error = FALSE;
$sfname = mysql_result($rows, 0, ‘First Name’);
$slname = mysql_result($rows, 0, ‘Last Name’);
$TP = mysql_result($rows, ‘Total Points’)
}
if($error) {
echo “

Error accessing user information

\n”;
echo “

$error

\n”;
} else {
echo “

Information about $sfname $slname

\n”;
echo “

First Name: $sfname

\n”;
echo “

Last name: $slname

\n”;
echo “

Total Points: $TP

\n”;
}

I started learning php 3 days ago to get this done for my work. If this looks awful I am sorry.

Did you install PHP and Apache yet? ;D

I installed php, but not apache, lol, I feel a little stupid. I am installing apache now.

I decided to go with WAMP because I only need this to run on 1 machine, but I thank you for your help PHP, It is finally giving me the correct error message.

I don’t get the way you are querying the database and all. I’ll make a code for it as soon as I can…

Sponsor our Newsletter | Privacy Policy | Terms of Service