I am very very disappointed this time. I wasted my whole day and I couldn't help me out. Here is the problem:
I need accept or delete the pending jobs. If I accept, only then it will publish on my site. Please look at the image.
Here I am trying this code to handle this matter. Firstly if anyone post a new job, I pass a hidden value=0 according to the job.
<input type="hidden" name="pending" value=0/>
Then I store it in my database.
INSERT INTO job (Pending) VALUES ('$_POST[pending]');
Then I go to the image(above) page to accept or delete.
echo "<a href='accept.php?accept=1'>ACCEPT</a> Or ";
echo "<a href='accept.php?accept=0'>DELETE</a>";
After accepting Pending column will be replaced from 0 to 1 and thus it will be published. Or deleting time, the job will be simply be deleted from database.
$accept=$_GET['accept'];
if($accept==1){
mysql_query("UPDATE job SET Pending='$accept'
WHERE ID='5'");
}
else{
mysql_query("DELETE FROM job WHERE ID='5'");
}
In the 'job' table, I use a primary auto increment column named ID. I put 5 for ID. So this code will work only for the pending job which ID is 5. So my problem is here. How can I alternate this 5 with a dynamic variable?
FOR MORE ASSISTANCE HERE IS the CODE OF 'PENDING JOBS' PAGE;
$result1 = mysql_query("SELECT * FROM job ORDER BY ID DESC");
while($row1 = mysql_fetch_array($result1))
{
$id=$row1['ID'];
$cat=$row1['Category'];
$title=$row1['Title'];
$type=$row1['Type'];
$desp=$row1['Description'];
$salary=$row1['Salary'];
$day=$row1['Day'];
$month=$row1['Month'];
$year=$row1['Year'];
$info=$row1['Contact'];
$pending=$row1['Pending'];
$now = time();
$last_date = strtotime("$year-$month-$day");
$datediff = $last_date - $now;
$day_left=ceil($datediff/(60*60*24));
if($day_left>=0&&$pending==0){
echo "<div class=cat>Job field: $cat<br/></div>";
echo "<div class=yel2>";
echo "This is a <b>$type time</b> job and we are looking for <b>$title</b>. $desp<br/>";
if ($salary!=0) echo "Salary: $salary<br/>";
echo "Contact info: $info<br/>Last date: $day-$month-$year";
if($day_left==0)
echo "<br/><span class=ash><i>Today is the last day to apply</i><br/>";
else
echo "<br/><span class=ash><i>$day_left day(s) left</i></span><br/>";
echo "<span class=acc><a href='accept.php?accept=1'>ACCEPT</a><span> Or ";
echo "<span class=del><a href='accept.php?accept=0'>DELETE</a></span>";
Just pass the id along with the accept url.
echo "<span class=acc><a href='accept.php?id=$id&accept=1'>ACCEPT</a><span> Or ";
You can grab the id inside the accept.php script using
$post_id = $_GET['id'];
The code would require little change
$accept = intval($_GET['accept']); // safe against sql-injections
$post_id = intval($_GET['id']);
if($accept==1){
mysql_query("UPDATE job SET Pending='$accept'
WHERE ID='$post_id'");
}
else{
mysql_query("DELETE FROM job WHERE ID='$post_id'");
}