insert data into $db
Posted: Sun Aug 22, 2004 10:28 pm
hello.
pls help with the following problem.
I have a form (2 dynamic dropdowns) that after i select data in both, and press submit, the values should be inserted into $db.
When I chhose the Country, the page refreshes, and according to the Country i choosed the Cities are loaded into dropdown Cityes.
The problem is after the page refreshes, because the data is automaticaly inserted into $db, and I want that data to be inserted in the $db only when I click "Submit"
here is the script (short version) but this is the data that refers to what I want.
i hope you wont have troubles understanding what i want. I have dificulties explaining in english, but I hope I'll make you understand.
THX in advance
pls help with the following problem.
I have a form (2 dynamic dropdowns) that after i select data in both, and press submit, the values should be inserted into $db.
When I chhose the Country, the page refreshes, and according to the Country i choosed the Cities are loaded into dropdown Cityes.
The problem is after the page refreshes, because the data is automaticaly inserted into $db, and I want that data to be inserted in the $db only when I click "Submit"
here is the script (short version) but this is the data that refers to what I want.
Code: Select all
<form name="form1" action="<? $PHP_SELF; ?>" method="post">
<b>Country</b><br>
<select name="selCountry" onChange="document.formsї0].submit();">
<option value="0">Choose Country</option>Code: Select all
$sqlCountry = "SELECT * FROM Country ORDER BY nume_Country ASC";
$resultCountry = mysql_query($sqlCountry);
while($row = mysql_fetch_array($resultCountry)) {
print "<option value='".$row['id']."'";
if($_POST['selCountry']==$row['id']) echo "selected";
print "> - ".$row['nume_Country']."</option>";
}Code: Select all
</select>
<br><br>
<b>City</b><br>
<select name="selCity" class="form1">
<option selected value="0">Choose City</option>Code: Select all
$sqlCity = "SELECT * FROM City WHERE id_Country='".$_POST['selCountry']."'";
$resultCity = mysql_query($sqlCity);
while($row = mysql_fetch_array($resultCity)) {
print "<option value='".$row['id']."'> - ".$row['nume_City']."</option>";
}Code: Select all
</select>
<br><br>
<input type="submit" name="add_Country_City">
</form>Code: Select all
$message = "";
if(isset($_POST['add_Country_City'])) {
$message = "error";
} else {
$sql = "INSERT INTO o_gen(id_Country, id_City) VALUES('".$_POST['selCountry']."', '".$_POST['selCity']."')";
mysql_query($sql);
$message = "Added succesfully";
}THX in advance