PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old September 17th, 2004, 10:59 AM
univinus univinus is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 22 univinus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 43 m 48 sec
Reputation Power: 0
*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

Reply With Quote
  #2  
Old September 17th, 2004, 11:24 AM
univinus univinus is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 22 univinus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 43 m 48 sec
Reputation Power: 0
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~

Reply With Quote
  #3  
Old September 17th, 2004, 11:53 AM
univinus univinus is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 22 univinus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 43 m 48 sec
Reputation Power: 0
Problem is now solved, thanks. Just some mistyping.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > PHP with mysql in Forms


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT