I am on the PostgreSQL system. I’ve used it before and have not had this issue, but that was for basic select querying.
Now I am trying to insert data through an HTML form and php.
I do not get an error back when I fill out the data (even when I input all fields on the form) so I assume it should be inserted….
Here is my php/html:
<div id='insert_form'>
<form method='POST' action='insert.php' onsubmit='return checkSubmit()'>
<label id='lbl_header'><b>Bold</b> fields are required.</label>
<br /><br />
<label class='required' for='code1' id='lbl_code1'>* Country code</label>
<input type='text' name='code1' id='code1' maxlength='3' size='3'/>
<br /><br />
<label class='required' for='code2' id='lbl_code2'>* Country code (abbr.)</label>
<input type='text' name='code2' id='code2' maxlength='2' size='2'/>
<br /><br />
<label class='required' for='country_name' id='lbl_name'>* Country name</label>
<input type='text' name='country_name' id='country_name' maxlength='52'/>
<br /><br />
<label class='required' for='continent' id='lbl_continent'>* Continent</label>
<select name='continent' id='continent'>
<option value='Africa'>Africa</option>
<option value='Antarctica'>Antarctica</option>
<option value='Asia'>Asia</option>
<option value='Europe'>Europe</option>
<option value='North America'>North America</option>
<option value='Oceania'>Oceania</option>
<option value='South America'>South America</option>
</select>
<br /><br />
<label class='required' for='region' id='lbl_region'>* Region</label>
<input type='text' name='region' id='region' maxlength='26' />
<br /><br />
<label class='required' for='area' id='lbl_area'>* Surface area</label>
<input type='text' name='area' id='area' />
<br /><br />
<label for='indepYear' id='lbl_year'>Year of independence</label>
<input type='text' name='indepYear' id='indepYear' />
<br /><br />
<label class='required' for='population' id='lbl_pop'>* Population</label>
<input type='text' name='population' id='population' />
<br /><br />
<label for='lifeExp' id='lbl_lifeExp'>Life expectancy</label>
<input type='text' name='lifeExp' id='lifeExp' />
<br /><br />
<label for='gnp' id='lbl_gnp'>GNP</label>
<input type='text' name='gnp' id='gnp' />
<br /><br />
<label for='gnp_old' id='lbl_gnp_old'>GNP (old)</label>
<input type='text' name='gnp_old' id='gnp_old' />
<br /><br />
<label class='required' for='local_name' id='lbl_local_name'>* Local name</label>
<input type='text' name='local_name' id='local_name' maxlength='45' />
<br /><br />
<label class='required' for='govt' id='lbl_govt'>* Form of government</label>
<input type='text' name='govt' id='govt' maxlength='45' />
<br /><br />
<label for='HoS' id='lbl_HoS'>Head of state</label>
<input type='text' name='HoS' id='HoS' maxlength='60' />
<br /><br />
<label for='capital' id='lbl_capital'>Capital code</label>
<input type='text' name='capital' id='capital' />
<br /><br />
<label><a href='index.php'>Return to Selection Page</a></label>
<input type='submit' name='submit' value='Insert row' />
</form>
?>
The connect file has already been proven to work in my past projects so I know that’s not the issue. I’ve compiled it and it also says thats not the issue. Any idea why it would not be inserting into the database? Or maybe a function I could add on to the end with an if statement that could check if it had actually been inserted?
Using INSERT in the fashion that you are, you must ensure that the contents of the VALUES () clause exactly match the number and order of columns in the table. If there are any columns that you are not including, even if they have default values or are autonumbered, the command will fail. Since you don’t show any information about your table I don’t know whether this is the source of your problem or not.
If it is the problem, you can use the full form of INSERT:
This form is highly recommended in any event as it makes no assumptions about the table (other than the names of the columns) and guards against the command failing from structural changes to the table later on.