GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 06-Jul-2003, 05:04
loon loon is offline
New Member
 
Join Date: Jul 2003
Posts: 2
loon is an unknown quantity at this point

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();
?>
  #2  
Old 06-Jul-2003, 08:28
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
Try :

PHP Code:

<?php
// this should be an integer?

$StaffID = intval( $value );

?>

  #3  
Old 06-Jul-2003, 08:33
loon loon is offline
New Member
 
Join Date: Jul 2003
Posts: 2
loon is an unknown quantity at this point
is not an integer, is a string
  #4  
Old 06-Jul-2003, 08:38
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
Oh OK, then...

PHP Code:

<?php

// add the quotes here
$result=mysql_query("select * from Payroll where StaffID = '$StaffID'");
?>

  #5  
Old 06-Jul-2003, 21:54
skyloon skyloon is offline
Junior Member
 
Join Date: Jun 2003
Posts: 53
skyloon is an unknown quantity at this point
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>
  #6  
Old 07-Jul-2003, 05:55
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
What does this mean, you just want to share the code or is there something still that doesn't work?
 
 

Recent GIDBlogProblems with the Navy (Enlisted) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Parsing PHP code that's stored in a database. JdS MySQL / PHP Forum 3 13-May-2004 09:15
problem with C code belludandy C Programming Language 1 26-Jan-2004 21:28
Save code option BobbyDouglas GIDForums™ 3 08-Nov-2003 23:48
strange compile error - code from reputable author!! newbie_cpp C++ Forum 0 06-Nov-2003 16:15
error handling code.. daveyp225 C++ Forum 0 26-Oct-2003 06:46

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 12:31.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.