I need your help with my script. What I’m trying t do is insert values into mysql, wereby $row[‘senatorial’] and $constituencys are entered simultaneously. The coe below is wa I’m trying to make work but it’s not working. No error i shown on the screen and nothing is entered into the database.
Please where am I going wrong
<?php
if (isset($_POST['action']) && $_POST['action'] == "submit") {
$state = mysql_real_escape_string(trim($_POST['state']));
$query = mysql_query("SELECT senatorial
FROM state
WHERE state = '".$state."'") or die (mysql_error());
$duplicates = mysql_num_rows($query);
if (isset($_POST['constituency']) && $_POST['action'] == "create") {
$constituencys = $_POST['constituency'];
foreach($constituencys as $constituency) {
$query = "
INSERT INTO `state` (
`state_id`,
`state`,
`senatorial`
`constituency`
) VALUES (
NULL,
'{$state}',
'{$row['senatorial']}',
'" . mysql_real_escape_string(trim($constituency)) . "'
)
";
mysql_query($query) or die (mysql_error());
}
} ?>
<form action="<?php echo $_SERVER['SCRIPT_NAME'] ?>" method="post">
<?php
while($row=mysql_fetch_assoc($query)){
echo strtoupper($row['senatorial']) ;?>
<input type='text' name='constituency[]' title='Federal Constituency' />
<?php } ;?>
<input type="hidden" name="create" value="create" />
<input type='submit' name='create' value='Create' />
</form>
<?php } ?>
<h2>Select State To show Senatorial Districts</h2>
<form action="<?php echo $_SERVER['SCRIPT_NAME'] ?>" method="post">
State:<select name="state" title='State' class='OpenInput_Select'>
<option value =""> </option>
<option value ="state1">state1</option></select>
<input type="hidden" name="action" value="submit" />
<input type='submit' name='submit' value='SHOW' />
</form>
This if statement:
is inside this if statement:
So, $_POST[‘action’] cannot be “submit” and “create” at the same time so you will never get to your INSERT.