Jump to content

Recommended Posts

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

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]
<?php
function 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]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.