|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
*problem Solved*
PI've been trying to create a form that retrieves info from a database into a dropdown box so that users can select an option from the drop down box, then the form is to return the selected option, as well as the data entered in other fields and enter it as a new record in the database.
here is my code: <?php $title = "Enter New Series"; include("headerinclude.php"); ?> if ($submit) { // process form $sql = "INSERT INTO dvdcat_features (featurepres_name,featurepres_imdbid,country_id) VALUES ('$featurepres_name','$featurepres_imdbid','$count ry_id')"; $result = mysql_query($sql); echo "Thank you! Information entered.\n"; echo "<a href=\"http://www.univinus.com/firstphp.php\">Enter Another</a>\n"; } else { // show form ?> <h1>Enter New Series Details</h1> <form action="<?php echo $PHP_SELF?>" method="post"> <p>Name of series: <input type="text" name="featurepres_name" /></p> <p>IMDB URL: http://www.imdb.com/title/<input type="text" name="featurepres_imdbid" /></p> <?php // list of countries for drop box $countryresult = mysql_query("SELECT * FROM dvdcat_country",$db); echo "<p>Country of origin<select>\n"; if ($myrow = mysql_fetch_array($countryresult)) { do { printf("<option value=\"%s\">%s</option>\n", $myrow["country_id"], $myrow["country_name"]); } while ($myrow = mysql_fetch_array($countryresult)); echo "</select></p>\n"; } else { echo "Sorry, no records were found!"; } ?> <input type="Submit" name="submit" value="Enter information" /> </form> <?php } ?> the form without the countries drop box works fine, and the dropbox without the rest of the form works fine. The problem seems to be that the original if/else statement is divided into two <?php> tags with more php tags and if else statements in between. I tried removing the if/else statement from the country dropbox code but then the compiler seemed to have issues with the do/while statement. Is this the problem? Any way around it? All help is much appreciated ![]() ~magda~ Last edited by univinus : September 17th, 2004 at 11:52 AM. Reason: Problem solved |
|
#2
|
|||
|
|||
|
aaargh, ok, the problem with my code that caused it not to compile was simply because i left out a silly little opening tag
![]() so now, the form is displaying properly, fields can have data entered in them and a selection can be made from the drop box. and when the submit button is pressed, everything appears to go as planned. The correct echo statement appears. However, the data does not actually turn up in the database. here is my revised code: <?php $title = "Enter New Series"; include("headerinclude.php"); ?> <?php if ($submit) { // process form $sql = "INSERT INTO dvdcat_features (featurepres_name,featurepres_imdbid,country_id) VALUES ('$featurepres_name','$featurepres_imdbid','$count ry_id')"; $result = mysql_query($sql); echo "Thank you! Information entered.\n"; echo "<a href=\"http://www.univinus.com/firstphp.php\">Enter Another</a>\n"; } else { ?> <h1>Enter New Series Details</h1> <form action="<?php echo $PHP_SELF?>" method="post"> <p>Name of series: <input type="text" name="featurepres_name" /></p> <p>IMDB URL: http://www.imdb.com/title/<input type="text" name="featurepres_imdbid" /></p> <?php $countryresult = mysql_query("SELECT * FROM dvdcat_country",$db); echo "<p>Country of origin<select>\n"; if ($myrow = mysql_fetch_array($countryresult)) { do { printf("<option value=\"%s\">%s</option>\n", $myrow["country_id"], $myrow["country_name"]); } while ($myrow = mysql_fetch_array($countryresult)); echo "</select></p>\n"; } else { echo "Sorry, no records were found!"; } ?> <input type="Submit" name="submit" value="Enter information" /> </form> <?php } ?> once again, all help appreciated ![]() ~magda~ |
|
#3
|
|||
|
|||
|
Problem is now solved, thanks. Just some mistyping.
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > PHP Development > PHP with mysql in Forms |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|