2

I'm trying to get a button to work , I'm not allowed to use Javascript and here's my code:

     <form id="form1" name="form1" method="post" action="course_man.php">

   for($i=0; $i <= $numcourses; $i++){
echo '<div class="new'.$i.'" id="new'.$i.'"><label>'.$course_names[$i].'</label>
    <input name="edit'.$i.'" type="submit" value="Edit" />
    <input name="delete'.$i.'" type="submit" value="Delete" /><br /></div>';

    $name= "'edit".$i."'";
    if (isset($_POST[$name])){
    echo '<input name="text" type="text" value="'.$course_names[$i].'" />';
        }
    }
   ?></form>

Now the buttons gets created and no errors are displayed, but the edit button doesnt create the textfield when clicked, what am I doing wrong?

3
  • By "dynamically created" do you mean without another page load? Because that's impossible without JavaScript. Commented May 2, 2012 at 20:30
  • Where is your form (and what's it's action)? Commented May 2, 2012 at 20:31
  • I want the page to reload and display the textbox when edit is clicked, edited my question title and code Commented May 2, 2012 at 20:35

2 Answers 2

3
$name= "edit".$i;
if (isset($_POST[$name])){

not: $name= "'edit".$i."'";

Sign up to request clarification or add additional context in comments.

1 Comment

Ok it works,it just had too many 's, now I feel stupid, thanx.
1
<form id="form1" name="form1" method="post" action="">
<?php

$course_names = array('maths','english','science','history');

$numcourses = count($course_names);

for($i=0; $i < $numcourses; $i++){

    echo '<div class="new'.$i.'" id="new'.$i.'">';

        echo '<label>'.$course_names[$i].'</label>';
        echo '<input name="edit'.$i.'" type="submit" value="Edit" />';
        echo '<input name="delete'.$i.'" type="submit" value="Delete" /><br />';

    echo '</div>';

    $name = 'edit'.$i;

    if (isset($_POST[$name])){
        echo '<input name="text" type="text" value="'.$course_names[$i].'" />';
    }
}
?>
</form>

Hope this helps, Ive tested and seems to work fine )

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.