Current location: Hot Scripts Forums » Programming Languages » PHP » something wrong with this code


something wrong with this code

Reply
  #1 (permalink)  
Old 07-06-03, 06:04 AM
superman's Avatar
superman superman is offline
Newbie Coder
 
Join Date: Jun 2003
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
something wrong with this code

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();
?>
Reply With Quote
  #2 (permalink)  
Old 07-06-03, 06:10 AM
BdSBB BdSBB is offline
Newbie Coder
 
Join Date: Jun 2003
Location: Georgetown, TX
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
$number_of_array is the number of rows found. Use $row = mysql_fetch_array() so you won't get confused.

Are there any errors outputted to the browser?
__________________
-- BdSBB

Last edited by BdSBB; 07-06-03 at 06:51 AM.
Reply With Quote
  #3 (permalink)  
Old 07-06-03, 06:10 AM
Chris Boulton Chris Boulton is offline
Wannabe Coder
 
Join Date: Jun 2003
Location: Sydney, Australia
Posts: 208
Thanks: 0
Thanked 0 Times in 0 Posts
If StaffID is not a numerical value it has to be enclosed in ''s..

eg

$result = mysql_query("SELECT * FROM Payroll WHERE StaffID='$StaffID'");

If StaffID is a unique value, you also shouldnt have to have the while in there..just do one mysql_fetch_array.

Chris
__________________
Chris Boulton
SurfiOnline!
MyBulletinBoard
Reply With Quote
  #4 (permalink)  
Old 07-06-03, 10:55 PM
superman's Avatar
superman superman is offline
Newbie Coder
 
Join Date: Jun 2003
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
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">&nbsp;</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>
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP code to edit a text file mdhall Script Requests 12 12-23-10 04:03 AM
protecting code in PHP ckb PHP 12 01-02-04 08:53 AM
Help trim code down TheLaughingBandit JavaScript 0 09-02-03 09:50 AM
Validation code for site membership kNIGits The Lounge 1 07-28-03 02:41 AM
Gnome Code Factory & Programers Guild tai fu General Advertisements 0 07-11-03 08:23 AM


All times are GMT -5. The time now is 10:19 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.