How to send a date after posting a job?

Hello, I am creating an admin page where he can add Job positions to display on the website. Everything is going great, I can do the CRUD. But there is something I don’t know how to do.

I want when the admin posts a job a date will be sent to the database, just to show when that job position was added.

Here are my colums in the DB:

    $jobID = $_POST['jobID'];
    $title = $_POST['jobTitle'];
    $desc = $_POST['jobDesc'];

as for the date what do I do exactly in here:

    $date = date("d-m-Y");
    $publishDate = $_POST['publishDate'];

Thank you

Most, if not all, database engines will do this for you, either with a default value in the field, or by explicitly defining the value when you do your insert.

Most commonly, the latter is done in the form

"INSERT INTO .... (....) VALUES .... `mydatefield` = NOW() ...."

I got it:
In the CRUD I just added this

$jobDate = $_POST['jobDate'];
    $db->update('job_ads',array('jobTitle'=>"$title",'jobDesc'=>"$desc",'publishDate'=>"$jobDate"),'jobID="'.$jobID.'"'); // Table name, column names and values, WHERE conditions

In the HTML:

<input type="hidden" value="<?php echo date('Y-m-d')?>" name="jobDate"/>

The Create-job.php submits the date the post was sent
and the update changes the date to the day the post was updated.

Why would…you update the date? A posting date is the date the entry was created, and should never be updated?

And even if the intention is to have a “last updated” date/time, why not have MySQL do that, rather than pass it into the form, and then back out again? *

It’s good that the OP has come back and updated the thread now that they have it working - so few people do that. But it seems strange to hand-code something where there is no need.

*ETA - unless the OP doesn’t have the access to change the database config, of course.

1 Like

I’m a beginner in php, so I wouldn’t know…I apologize

and thanks for the link!

True, but that’s what the website owner wants…so I’m doing it as he please.

1 Like

I got an idea, create another column in the DB and call it “last updated”.
So when the user sees the job post on the bottom right it will display:
“Last updated” and “job posted:” or keep the last updated for the admin to see. <3

1 Like

I like to have separate “created” and “last updated” dates where I have a need to sort things by date. Apart from anything else, a “created” date/time may be better than relying on sorting by an id field if you want to see the order things are created.


Or just offering the client some new data.

“Here’s when your posting was created, here’s when you last made a change to it, and here’s when you closed it. Your total time from post-to-close was … (How long has my job search gone on), your total time from last-update-to-close was … (How long did it take me to actually find a candidate i liked), your total time between post-to-update was …” (This, to the customer, is ‘how long did it take me to get my job posting correct’)

1 Like

On this

   $jobID = $_POST['jobID'];

unless I’m jumping to conclusions, normally you’d allow the database again to create an automatically-incrementing id for each new row you create, whether it’s a job or anything else. That’s normally referred to as the id and would be unique. By putting it into a form field, I’m presuming you are asking the user to provide it, which opens up all sorts of trouble or, if there’s only one user adding jobs, gives them the task of keeping a record of the next ID to use, which is something the database can do automatically. You can create an id column as auto-incrementing, don’t refer to it in your ‘insert’ query, and it will automatically have the next id when you insert a new row.

In MySQL you can use default values and on update to set the created and updated time for a row. See my example below.

  `sites_id` bigint(20) unsigned NOT NULL,
  `cache_name` varchar(128) NOT NULL,
  `pkg` varchar(128) NOT NULL DEFAULT '',
  `cache_value` longblob,
  `flush_cache` tinyint(3) unsigned NOT NULL DEFAULT '0',
  `serialized` tinyint(3) unsigned NOT NULL DEFAULT '0',
  `created_on_timestamp` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`sites_id`,`cache_name`,`pkg`),
  KEY `sites_id` (`sites_id`,`cache_name`,`pkg`,`flush_cache`),
  KEY `sites_id_2` (`sites_id`),
  CONSTRAINT `mcp_cached_data_ibfk_1` FOREIGN KEY (`sites_id`) REFERENCES `mcp_sites` (`sites_id`)

Unless you are using GUIDs this looks incorrect. The database should be responsible for generating the primary key using auto increment in MySQL.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.