Perad Posted October 17, 2006 Share Posted October 17, 2006 I have a dropdown box where the options are called directly from the database.I need this line at the top of the form.[code]<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">[/code]I have come up with this...[code] function add_article () { echo "<form action=\"<?php echo \$_SERVER['PHP_SELF']; ?>\" method=\"post\">"; echo "<select name=\"category\">"; $query = "SELECT category_id, category_name FROM article_category ORDER BY category_id"; $result = mysql_query ($query) or die("Problem with the query: $query on line:" . __LINE__ . "<br>" . mysql_error()); while ($row = mysql_fetch_assoc ($result)) {[/code]The form works, but doesn't loop back to the original page. Does anyone know a way around this? Link to comment https://forums.phpfreaks.com/topic/24183-embedding-php-in-an-echo-statement/ Share on other sites More sharing options...
HuggieBear Posted October 17, 2006 Share Posted October 17, 2006 That code looks good to me...When the form loads, right click and view source and see what's being put in the 'action' parameter.RegardsHuggie Link to comment https://forums.phpfreaks.com/topic/24183-embedding-php-in-an-echo-statement/#findComment-109914 Share on other sites More sharing options...
radar Posted October 17, 2006 Share Posted October 17, 2006 I did just one quick edit -- but might possibly work... when working with PHP there is aboslutely no reason to have <?php tags within it.. just a waste of space and gives you the chance of getting hung up.... so try this code in your function and see if it works.... though why you're not using a templating engine to seperate html from php i dunno (since i switched -- im loving my job as a developer)...[code]<?phpfunction add_article () { echo "<form action=\"".$_SERVER['PHP_SELF']."\" method=\"post\">"; echo "<select name=\"category\">"; $query = "SELECT category_id, category_name FROM article_category ORDER BY category_id"; $result = mysql_query ($query) or die("Problem with the query: $query on line:" . __LINE__ . "<br>" . mysql_error()); while ($row = mysql_fetch_assoc ($result)) {?>[/code] Link to comment https://forums.phpfreaks.com/topic/24183-embedding-php-in-an-echo-statement/#findComment-109922 Share on other sites More sharing options...
Perad Posted October 17, 2006 Author Share Posted October 17, 2006 I'm new to php... whats a templating engine?As for the problem itself I rewrote my form and changed my php function to get it working. Link to comment https://forums.phpfreaks.com/topic/24183-embedding-php-in-an-echo-statement/#findComment-109926 Share on other sites More sharing options...
radar Posted October 17, 2006 Share Posted October 17, 2006 templating engine is like smarty -- which is the one i use... makes life easy -- though if you're new to php hold off on it a while... and look into it when you start to build a large site... Link to comment https://forums.phpfreaks.com/topic/24183-embedding-php-in-an-echo-statement/#findComment-109932 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.