PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
g3ckO
Forum Contributor
Posts: 117 Joined: Mon Jul 12, 2004 2:57 am
Location: Malaysia
Contact:
Post
by g3ckO » Tue Aug 17, 2004 4:15 am
check this code:
Code: Select all
<?php
session_start();
include("database.php");
$user=addslashes($_SESSION[username]);
$query="SELECT * FROM `leave` a INNER JOIN `employee` b ON b.`StaffNo` = a.`Super` WHERE b.`username` = '$user'AND a.`Status` = 'Pending
Review'";
$result=mysql_query($query) or die(mysql_error());
?>
<div align="left">
<table border="0" cellpadding="2" cellspacing="1" width="100%">
<tr>
<td align="left" valign="bottom" width="2%"
bgcolor="lightskyblue" valign="TOP" marginwidth="12" marginheight="12">
</td>
<td align="left" valign="bottom" width="25%"
bgcolor="lightskyblue" valign="TOP" marginwidth="12" marginheight="12">
<b>NAMA</b>
</td>
<td align="left" valign="top" width="18%"
bgcolor="lightskyblue" marginwidth="12" marginheight="12">
<b>REF. ID</b>
</td>
<td align="left" valign="top" width="17%"
bgcolor="lightskyblue" marginwidth="12" marginheight="12">
<b>TARIKH PERMOHONAN</b>
</td>
<td align="left" valign="top" width="20%"
bgcolor="lightskyblue" marginwidth="12" marginheight="12">
<b>TARIKH CUTI</b>
</td>
<td align="left" valign="top" width="18%"
bgcolor="lightskyblue" marginwidth="12" marginheight="12">
<b>STATUS</b>
</td>
</tr>
</table>
</div>
<?
while ($row = mysql_fetch_array($result))
{
$refid=$row["RefID"];
$nama = $row["Nama"];
$jawatan = $row["Jawatan"];
$jenis = $row["Jenis"];
$mula = $row["DateMula"];
$tamat = $row["DateTamat"];
$mohon = $row["DateMohon"];
$refid = $row["RefID"];
$status = $row["Status"];
$access = $row["AccType"];
$ack_by = $row["EmpName"];
echo"<form action=leave_app_2.php?$approved method=POST>";
?>
<div align="left">
<table border="0" cellpadding="2" cellspacing="1" width="100%">
<tr>
<td align="left" valign="bottom" width="2%"
bgcolor="lightskyblue" valign="TOP" marginwidth="12" marginheight="12">
<?echo"<input type=checkbox name=approved[] value=$refid>";?>
</td>
<td align="left" valign="bottom" width="25%"
bgcolor="lightskyblue" valign="TOP" marginwidth="12" marginheight="12">
<?echo"$nama";?>
</td>
<td align="left" valign="top" width="18%"
bgcolor="lightskyblue" marginwidth="12" marginheight="12">
<?echo"$refid";?>
</td>
<td align="left" valign="top" width="17%"
bgcolor="lightskyblue" marginwidth="12" marginheight="12">
<?echo"$mohon";?>
</td>
<td align="left" valign="top" width="20%"
bgcolor="lightskyblue" marginwidth="12" marginheight="12">
<?echo"$mula";?> hingga <?echo"$tamat"?>
</td>
<td align="left" valign="top" width="18%"
bgcolor="lightskyblue" marginwidth="12" marginheight="12">
<?echo"$status";?>
</td>
</tr>
</table>
</div>
<?
}
?>
<input type="hidden" name="statusby" value="<? echo $ack_by; ?>" >
<br>
<div align="left">
<table width="100%">
<tr>
<td align="right" width="50%">
<input type="submit" value="APPROVED" name="app">
</td>
<td align="left" width="50%">
<input type="submit" value="NOT APPROVED" name="notapp">
</td>
</tr>
</table>
</div>
</form>
?>
I got the display like I want it to be.. But now how to pass the value of the checkbox.
When the
approved button is clicked. I want the value of status in table leave to change from
pending review to
approved .
When the not
approved button is clicked. I want the value of status in table leave to change from
pending review to not
approved .
Just want to know what variable should I pass to the update query to update data in table
leave ?
Last edited by
g3ckO on Tue Aug 17, 2004 11:30 pm, edited 1 time in total.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Aug 17, 2004 10:17 am
flip it off of $_POST['app']/$_POST['notapp'] ... just be aware that neither will exist if the person hit enter to submit it from a field..
[edit: removed double negative]
Last edited by
feyd on Tue Aug 17, 2004 9:43 pm, edited 1 time in total.
g3ckO
Forum Contributor
Posts: 117 Joined: Mon Jul 12, 2004 2:57 am
Location: Malaysia
Contact:
Post
by g3ckO » Tue Aug 17, 2004 9:25 pm
Is the query code like this?
Code: Select all
<?php
session_start();
include("database.php");
global $conn;
$statusby = $_POST['statusby'];
if ($_POST['app'])
{
$query = UPDATE leave SET
Status = 'Approved', StatusBy = '$statusby'
WHERE
mysql_query($query, $conn);
}
if($_POST['notapp'])
{
$query = UPDATE leave SET
Status = 'Not Approved', StatusBy = '$statusby'
WHERE
mysql_query($query, $conn);
}
?>
What should I put in the
WHERE ??
WHERE is for the checked checkbox.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Aug 17, 2004 9:33 pm
the id number of it..
g3ckO
Forum Contributor
Posts: 117 Joined: Mon Jul 12, 2004 2:57 am
Location: Malaysia
Contact:
Post
by g3ckO » Tue Aug 17, 2004 9:39 pm
the id number of it..
Don't get it...
tim
DevNet Resident
Posts: 1165 Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio
Post
by tim » Tue Aug 17, 2004 9:40 pm
$refid = $row["RefID"];
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Aug 17, 2004 9:45 pm
$_POST['approved'][X ] actually..
g3ckO
Forum Contributor
Posts: 117 Joined: Mon Jul 12, 2004 2:57 am
Location: Malaysia
Contact:
Post
by g3ckO » Tue Aug 17, 2004 10:06 pm
Code: Select all
<?php<?
session_start();
include("database.php");
global $conn;
$statusby = $_POST['statusby'];
if ($_POST['app'])
{
$query = UPDATE leave SET
Status = 'Approved', StatusBy = '$statusby'
WHERE $refid = $row["RefID"];
mysql_query($query, $conn);
}
if($_POST['notapp'])
{
$query = UPDATE leave SET
Status = 'Not Approved', StatusBy = '$statusby'
WHERE $refid = $row["RefID"];
mysql_query($query, $conn);
}
?>
?>
Error message> Parse error: parse error, unexpected T_STRING in c:\apache\htdocs\leave_app_2.php on line 12.
??
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Aug 17, 2004 10:10 pm
you kinda need to put the sql string into an actual string...
g3ckO
Forum Contributor
Posts: 117 Joined: Mon Jul 12, 2004 2:57 am
Location: Malaysia
Contact:
Post
by g3ckO » Tue Aug 17, 2004 10:22 pm
Code: Select all
<?php
<?
session_start();
include("database.php");
global $conn;
$statusby = $_POST['statusby'];
if ($_POST['app'])
{
$query = "UPDATE leave SET
Status = 'Approved', StatusBy = '$statusby'
WHERE $refid = $row["RefID"]";
mysql_query($query, $conn);
}
if($_POST['notapp'])
{
$query = "UPDATE leave SET
Status = 'Not Approved', StatusBy = '$statusby'
WHERE $refid = $row["RefID"]";
mysql_query($query, $conn);
}
?>
?>
Parse error: parse error, unexpected '"', expecting T_STRING or T_VARIABLE or T_NUM_STRING in c:\apache\htdocs\leave_app_2.php on line 14
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Aug 17, 2004 10:56 pm
look at the highlighted code of your post there.. you should see what's wrong..
hint: the string syntax needs a few escapes for the variables..
g3ckO
Forum Contributor
Posts: 117 Joined: Mon Jul 12, 2004 2:57 am
Location: Malaysia
Contact:
Post
by g3ckO » Tue Aug 17, 2004 11:00 pm
hmm.. how should I write it??
Code: Select all
<?php
$query = "UPDATE leave SET
Status = 'Approved', StatusBy = '$statusby'
WHERE $refid = $row['RefID']";
?>
also get error..
Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in c:\apache\htdocs\leave_app_2.php on line 14
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Aug 17, 2004 11:10 pm
RefID = {$row['RefID']}
although that assumes you have $row['RefID'] set on the processing script's end..
g3ckO
Forum Contributor
Posts: 117 Joined: Mon Jul 12, 2004 2:57 am
Location: Malaysia
Contact:
Post
by g3ckO » Tue Aug 17, 2004 11:21 pm
Code: Select all
<?php
session_start();
include("database.php");
global $conn;
$statusby = $_POST['statusby'];
if ($_POST['app'])
{
$query = "UPDATE leave SET
Status = 'Approved', StatusBy = '$statusby'
WHERE RefID = {$row['RefID']}";
mysql_query($query, $conn);
}
if($_POST['notapp'])
{
$query = "UPDATE leave SET
Status = 'Not Approved', StatusBy = '$statusby'
WHERE RefID = {$row['RefID']}";
mysql_query($query, $conn);
}
?>
No error but the data in database is not update...
headache already...
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Aug 17, 2004 11:27 pm
$row['RefID'] probably isn't set... need to pull it from the posted data... should be inside $_POST['approved']
print_r($_POST['approved']) to look at the data