Jump to content

Recommended Posts

This works when a user enters thier first and last name and chooses there requested date and hits delete.

 

my problem is if i take out the query with SELECT statement it does not show the form at all.

 

My goal for this php code is to be able to enter say first and last name and it will show all that is associated with it. I do not understand how to get it to show what is already there and i would like to have check boxes next to the rows seen and user be able to delete the ones they want. That is do that they don't have to do it the way the code is written now.

 

any help would be great.

 

<?php
if(isset($_POST['action'])){$action=$_POST['action'];}else{$action="";}
if( $action == 'updated' )
{
  extract ($_POST);
  $todaysDate = date("Y-m-d",time());
  $requestedDate=$yearRequest.'-'.$monthRequest.'-'.$dayRequest;
  $rescheduleDate=$yearRescheduled.'-'.$monthRescheduled.'-'.$dayRescheduled;      

//	Need to query database to see if this request is valid

$query = "SELECT *  FROM timeoff WHERE  requestedDate = '$requestedDate' AND last = '$last' AND first = '$first'";

$queryresult = mysql_query($query) or die("Query failed : " . mysql_error());
$rowcount = mysql_num_rows($queryresult);
if( $rowcount > 3 )

{
//echo "<p>Shift full...Please see Lisa or Robbie.</p>";
echo "<p>To delete another day off.<a href='delete.php'>Click here</a>";
}
else
{
$query ="DELETE FROM timeoff WHERE  requestedDate = '$requestedDate' AND last = '$last' AND first = '$first'";
//$result = myswql_query($query) or die("Query failed: " .mysql_error());

 echo "Your Date has been Deleted";
}

$action="";
}
else{
?>

  <form name='timeOffForm' method='post' action='delete.php'> 
<table width="500" border="0">
    <tr>   
    <td>First Name </td>
    <td><input name="first" type="text" size="20" maxlength="20"></td>
  </tr>
  <tr>
    <td>Last Name </td>
    <td><input name="last" type="text" size="30" maxlength="30"></td>
  </tr>
  
    
  <tr><td><b>Todays Date:</b></td>
  <td>
   <?php
$todaysDate = date("m-d-Y",time());
echo "$todaysDate";	
?> 
  </td>
  </tr>
<tr><td><b>Requested Day Off:</b></td>
<td><select size='1' name='monthRequest'>     
  <?php
	$todaysDate = date("Y-m-d",time());
  	list($year, $month, $day) = split('[-]', $todaysDate);  
for( $i = 1; $i <= 12; $i++ )
{ 
  $myMonth = getmonth( $i );
  echo "<option value='$i'";
  if( $i == $month )
  {
   echo "selected";
  }
  echo ">$myMonth</option>";
}
?>
</select> </td>
<td><select size='1' name='dayRequest'> 
<?php
for( $i = 1; $i <= 31; $i++ )
{
   echo "<option value='$i'";
   if( $i == $day )
   {
    echo "selected";
   }
   echo ">$i</option>";
}
?>
</select></td>
<td><select size='1' name='yearRequest'>   
<?php
for( $i = 2007; $i <= 2009; $i++ )
{
  echo "<option value='$i'";
  if( $i == $year )
  {
   echo "selected";
  }
  echo ">$i</option>";
   }
  ?> 
  </select></td></tr>
          
<tr><td colspan="2" align="center">
<input type= 'hidden' name= 'action' value= 'updated'>					
  		<input type = "submit" name = "submit" value= "Delete">
  </td></tr></table>
</form>
<?php
}
?>



Link to comment
https://forums.phpfreaks.com/topic/66255-delete/
Share on other sites

here is an edited code for this problem i can get it to now show everything related to that person but can not figure out how to get a delete function in there to work.


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<?php
/*this program was designed to eliminate paper work for the sift supervisors and the csps that work at Sitel here at loring.
  this program was written and developed by Amy Coppola on July 2007	
*/	
?>
<?php 
include'mysqlconnectsitel.inc.php'; 
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Request Time Off</title>
<link href= "links.css" rel="stylesheet" type="text/css"/>
<link href= "general.css" rel="stylesheet" type="text/css"/>

<?php 
function getmonth($m=0) {
return (($m==0 ) ? date('F') : date('F', mktime(0,0,0,$m)));
}
?>
</head>
<body>
<br>

<img src="33720001.jpg" alt="sitel" width="300" height="100" />

<?php
if(isset($_POST['action'])){$action=$_POST['action'];}else{$action="";}
if( $action == 'updated' )
{
  extract ($_POST);
  $todaysDate = date("Y-m-d",time());
  
        

//	Need to query database to see if this request is valid


echo "<p><strong>These are the dates that you have requested off!!!!</strong></p>";


$sql ="SELECT first, last, requestedDate FROM timeoff WHERE last = '$last' AND first = '$first'";
$query=mysql_query($sql) or die("Query failed : " . mysql_error());

while($row = mysql_fetch_assoc($query))
{

echo $row['first'];
echo $row['last'];
echo $row['requestedDate'];
}

$action="";
}
else
{

?>

  <form name='timeOffForm' method='post' action='delete.php'> 
<table width="500" border="0">
    <tr>   
    <td>First Name </td>
    <td><input name="first" type="text" size="20" maxlength="20"></td>
  </tr>
  <tr>
    <td>Last Name </td>
    <td><input name="last" type="text" size="30" maxlength="30"></td>
  </tr>    
  <tr><td><b>Todays Date:</b></td>
  <td>
   <?php
$todaysDate = date("m-d-Y",time());
echo "$todaysDate";	
?> 
  </td>
</tr> 
          
<tr><td colspan="2" align="center">
<input type= 'hidden' name= 'action' value= 'updated'>					
  		<input type = "submit" name = "submit" value= "Submit">
  </td></tr></table>
  
</form>
<?php
}
?>
</body>
</html>



Link to comment
https://forums.phpfreaks.com/topic/66255-delete/#findComment-332102
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.