Board index   FAQ   Search  
Register  Login
Board index PHP PHP General

something wrong with this code

General discussions related to php

Moderators: macek, egami, gesf

something wrong with this code

Postby loon » Sun Jul 06, 2003 2:59 am

Why this code can't select the StaffID, if I delete 'where StaffID = $StaffID', this will show all the result, but I want the selected StaffID only. Something wrong with this code?
Thank you for your help!

<?
$Connect = mysql_connect("localhost","root","");
mysql_select_db("mw");
$StaffID = "$value";
$result=mysql_query("select * from Payroll where StaffID = $StaffID");
$number_of_array = mysql_num_rows($result);
while ($number_of_array = mysql_fetch_array($result)){
echo "$number_of_array[PayrollNumber]";
}
mysql_close();
?>
loon
New php-forum User
New php-forum User
 
Posts: 4
Joined: Sun Jul 06, 2003 2:51 am

try this

Postby ruturajv » Sun Jul 06, 2003 8:48 am

$the_query = "select * from tablename where staffid = " . $staffid;
be sure there is a variable staffid defined

and if the column typeof staffid is char then

$the_query = "select * from tablename where staffid = '" . $staffid . "'";
should be the query
User avatar
ruturajv
php-forum Super User
php-forum Super User
 
Posts: 1280
Joined: Sat Mar 22, 2003 9:42 am
Location: Mumbai, India

Postby bezmond » Sun Jul 06, 2003 10:47 am

Please don't cross-post. See this page also for my own response:

http://www.php-forum.com/p/viewtopic.php?t=2448
User avatar
bezmond
Moderator
Moderator
 
Posts: 312
Joined: Sat Apr 05, 2003 4:33 am
Location: Mansfield, UK

Postby loon » Sun Jul 06, 2003 7:46 pm

Here is the complete code. Thank you!!


create table Payroll
(PayrollNumber int(5) not null,
StaffID varchar(25),
GrossPay float,
HourlyRate float,
YearToDateEarnings float,
IncomeTax float,
EPFNumber varchar(25),
SOCSONumber varchar(25));

insert into Payroll
values (10001, 'Ken', 12000.10, 160, 36000.50, 200.30, 'A12121212', 'B23232323');


----------------------------------------------------------------------------------
----------------------------------------------------------------------------------


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

<body bgcolor="#FFFFFF" text="#000000">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="2"><font size="2">Welcome
<?php
foreach ($HTTP_COOKIE_VARS as $value)
print ("$value"); ?>
! </font></td>
</tr>
<tr>
<td colspan="2">&</td>
</tr>
<tr>
<td width="33%">Payroll Number :</td>
<td width="67%">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<? $Connect = mysql_connect("localhost","root","");
mysql_select_db("mw");
$StaffID = "$value";
$result=mysql_query("select * from Payroll where StaffID = '$StaffID'") ;
$number_of_array = mysql_num_rows($result);
while ($number_of_array = mysql_fetch_array($result)){
echo "$number_of_array[PayrollNumber]";
}
mysql_close();
?>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="33%">Staff ID :</td>
<td width="67%">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<? echo $value ?>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="33%">Gross Pay :</td>
<td width="67%">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<? $Connect = mysql_connect("localhost","root","");
mysql_select_db("mw");
$StaffID = "$value";
$result=mysql_query("select * from Payroll where StaffID = '$StaffID'") ;
$number_of_array = mysql_num_rows($result);
while ($number_of_array = mysql_fetch_array($result)){
echo "$number_of_array[GrossPay]";
}
mysql_close();
?>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="33%">Hourly Rate :</td>
<td width="67%">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<? $Connect = mysql_connect("localhost","root","");
mysql_select_db("mw");
$StaffID = "$value";
$result=mysql_query("select * from Payroll where StaffID = '$StaffID'") ;
$number_of_array = mysql_num_rows($result);
while ($number_of_array = mysql_fetch_array($result)){
echo "$number_of_array[HourlyRate]";
}
mysql_close();
?>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="33%">Year To Date Earnings :</td>
<td width="67%">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<? $Connect = mysql_connect("localhost","root","");
mysql_select_db("mw");
$StaffID = "$value";
$result=mysql_query("select * from Payroll where StaffID = '$StaffID'") ;
$number_of_array = mysql_num_rows($result);
while ($number_of_array = mysql_fetch_array($result)){
echo "$number_of_array[YearToDateEarnings]";
}
mysql_close();
?>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="33%">Income Tax :</td>
<td width="67%">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<? $Connect = mysql_connect("localhost","root","");
mysql_select_db("mw");
$StaffID = "$value";
$result=mysql_query("select * from Payroll where StaffID = '$StaffID'") ;
$number_of_array = mysql_num_rows($result);
while ($number_of_array = mysql_fetch_array($result)){
echo "$number_of_array[IncomeTax]";
}
mysql_close();
?>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="33%">EPF Number :</td>
<td width="67%">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<? $Connect = mysql_connect("localhost","root","");
mysql_select_db("mw");
$StaffID = "$value";
$result=mysql_query("select * from Payroll where StaffID = '$StaffID'") ;
$number_of_array = mysql_num_rows($result);
while ($number_of_array = mysql_fetch_array($result)){
echo "$number_of_array[EPFNumber]";
}
mysql_close();
?>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="33%">SOCSO Number : </td>
<td width="67%">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<? $Connect = mysql_connect("localhost","root","");
mysql_select_db("mw");
$StaffID = "$value";
$result=mysql_query("select * from Payroll where StaffID = '$StaffID'") ;
$number_of_array = mysql_num_rows($result);
while ($number_of_array = mysql_fetch_array($result)){
echo "$number_of_array[SOCSONumber]";
}
mysql_close();
?>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
loon
New php-forum User
New php-forum User
 
Posts: 4
Joined: Sun Jul 06, 2003 2:51 am

Postby bezmond » Mon Jul 07, 2003 1:02 am

again, see my post on the other page and you will hopefully find there are no remaining errors.

Andrew
User avatar
bezmond
Moderator
Moderator
 
Posts: 312
Joined: Sat Apr 05, 2003 4:33 am
Location: Mansfield, UK


Return to PHP General

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.