Reloading a form for data entry in php

At the very bottom of your page add this for a test.

<?php
print_r($_SESSION);
?>

On refresh are values still available?
IF NOT, make sure there is no space before opening php tag or after a closing ?> tag (if you have one) in you connect file. In other words, nothing can be sent to browser, line returns etc.

Also are you viewing the page on its own? Not within some kind of program that might send something to the screen?

this is what I get

Array ( [employerid] => 2 [jobtitleid] => 2 )

as expected I presume

no, I am running the page on its own. there is nothing else running with it. my appvars include file is only two Constant for my picture upload path and the maximum size of hte file to be uploaded. Beside that all of my include file are only html. no php

Hmmm and viewing source in your browser, do you see selected=“selected” on those options?

not 100% sure what you are asking. when I select a value from the drop down the value gets selected and saved to the database.

AHHHHHH edit mistake. I didn’t notice you were missing the equal sign on your original version when you had <option type"input".

echo '<option class="input".....

You are probably getting a php error which is keeping session from starting.

hahaha no I have corrected that type=“input” first thing when I started talking with you a few days ago lol. I have found something thoughin the firefox inspect element:

Warning:  mysqli_query(): Couldn't fetch mysqli in C:\xampp\htdocs\SFDB\form\employee\add_update_employee.php on line 179

Warning:  mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in C:\xampp\htdocs\SFDB\form\employee\add_update_employee.php on line 180

Are you seeing this query in that location?

                    $employer = "SELECT employerid,employer FROM employer";
                    $empresult= mysqli_query($dbc, $employer);
                    while($optionemp = mysqli_fetch_array($empresult)){

Do you see a problem with the field or table names?

no all of them looks good. I wouldn’t be able to upload any data into the database if any of the field names were wrong. I have 100% success on all field being upload and have 100% success at populating my select boxes with everything that is sitting in my database.

I also get the same result for the jobtitle select tag: (not fire fox but Chrome inspect element, but same thing in firefox)

Warning:  mysqli_query(): Couldn't fetch mysqli in C:\xampp\htdocs\SFDB\form\employee\add_update_employee.php on line 167

Warning:  mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in C:\xampp\htdocs\SFDB\form\employee\add_update_employee.php on line 168

Not sure I am following, you are saying both select fields are populated, yet you are getting errors on those lines? I’m not sure how that can be possible.

hahahaha indeed!!! and also, I do not get the error message on my form and I made sure to comment
//error_reporting (E_ALL ^ E_NOTICE); so it shows all errors

Does adding the error section here print an error?

<?php
$employer = "SELECT employerid,employer FROM employer";
$empresult= mysqli_query($dbc, $employer);
if (!$empresult) {
    printf("Error: %s\n", mysqli_error($dbc));
    exit();
}
while($optionemp = mysqli_fetch_array($empresult)){                    
    $selectedemployerid = (isset($_SESSION['employerid']) && $_SESSION['employerid'] == $optionemp['employerid'] ? ' selected="selected"' : ''); 
    echo '<option class="input" value="' . $optionemp['employerid'] . '"' . $selectedemployerid .'>' . $optionemp['employer'] . '</option>'."\r";
}
?>

no. no error message and record gets uploaded 100% success all fields

I have to call it the night. I have to get up in 4 hours to go to work. thank you for all your hard work tonight, much appreciated. Cheers Alan

I invite anyone following this topic to jump in if you can see why query works before submit but not after. The only thing I can think of at this point is to change variable name of sql statement so it is unique on the page.

$employersql = "SELECT employerid,employer FROM employer";

Huh? There’s both a field and a table with the exact same name? That would be enough to confuse me.

1 Like

DAAAAA

mysqli_close($dbc);

after inserts!!!

After testing I also got undefined $employee_pic error, so I set the variable as empty at the beginning of processing.

//Variables for employee form//      
$employee_pic = '';
1 Like

Unbeleivable!!! That’s it! that’s what the problem was… Awesome! tanks a million man, I hope one day be able to return the favor.

1 Like

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