Forum Moderators: coopster
if(!isset($job_ID)) {
$job_ID = create_job_ID();
}
I have set it variously as if($job_ID == 0) and if($job_ID < 1) but the function still executes each time and increments the job_ID which is set, is an integer and indisputably exists!
The called function operates thus:
function create_job_ID()
{
$db = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD) or die('Unable to connect to the server. Check your connection parameters.');
mysql_select_db(MYSQL_DB, $db) or die(mysql_error($db));
$query = 'INSERT IGNORE INTO ww_job (job_ID)
VALUES (NULL)';
mysql_query($query, $db) or die(mysql_error($db));
$job = mysql_insert_id($db);
return $job;
}
Hoping someone can tell me where I'm going wrong - regards Sam.
Is this conditional inside a function?
function some_func() {
global $job_ID; // may be the problem
if(!isset($job_ID)) {
$job_ID = create_job_ID();
}
.....
Better yet, if this is the case,
$verified_job_id = some_func($job_ID);
//
//
function some_func($id) {
if(!isset($id)) {
$id = create_job_ID();
}
//.....
return $id;
}
Personally in these cases if I expect a number, this does the trick,
if (! ($job_ID > 0)) {
.....
But any of yours should have too. I'm voting "inside a function . . . "
if(!isset($_POST['job_ID'])) {
$_SESSION['job_ID'] = create_job_ID();
}
this means a job_ID is created for retrieving from the db but not destroyed each time the page submits back to itself (building a list of choices and echoing them out for the user to see).
I guess I'll have to clear the session variable within the session later if I want the user to be able to create two jobs in a single session.