Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5

Thread: PHP Forms

  1. #1
    New Coder
    Join Date
    Jun 2007
    Posts
    60
    Thanks
    7
    Thanked 0 Times in 0 Posts

    PHP Forms

    PHP Code:
    <?php

    // Last Modified 18th August 2007

    ob_start();
    session_start();

    include(
    'templates/header.php'); // Header template
    include('../config/config.php'); // Includes configuration files
    include('../lib/functions.php'); // Load all functions from Library

    if(!session_is_registered("username")){
    header('Location: index.php');
    exit();
    }
    else {

    $submit_delete $_POST['delete'];
    if(isset(
    $submit_delete)){

    $sql mysql_query('SELECT * FROM questions') or die(mysql_error());

    $selected_question $_POST['selected_question_array'];
    foreach (
    $selected_question as $qID){
        
    mysql_query("DELETE FROM questions WHERE id='$qID'") or die(mysql_error());
        echo 
    "Questions".$qID."deleted!<br/>";
    }

    }

    $submit_edit $_POST['edit'];
    if(isset(
    $submit_edit)){
        echo 
    "<form method=\"POST\">";
        echo 
    "Enter new question: <input type=\"text\" name=\"new_question\">";
        echo 
    "<input type=\"submit\" name=\"submit_new_question\" value=\"Edit\">";
        echo 
    "</form>";
        
    $submit_new_question $_POST['submit_new_question'];
        
    $new_question $_POST['new_question'];
        if(isset(
    $submit_new_question)){
            echo 
    $_POST['new_question'];
        }
    }

    include(
    'templates/footer.php'); // Footer Template

    }

    ?>
    Yup, the form under $submit_edit is not working.It is not echoing the question $_POST['new_question'];

    The form is being processed from
    PHP Code:
    <?php

    // Last Modified 18th August 2007

    ob_start();
    session_start(); // Loads session

    include('templates/header.php'); // Header Template
    include('../config/config.php'); // Includes configuration files
    include('../lib/functions.php'); // Load all functions from Library

    if(!session_is_registered("username")){
    header('Location: index.php');
    exit();
    }
    else {

    include(
    'templates/questions.php'); // Add new question form

    $submit $_POST['submit'];
    $question sql_safe($_POST['question']);

    if(isset(
    $submit)){
    mysql_query("INSERT INTO questions(question) VALUES('$question')") or die(mysql_error());

    $newly_created_question mysql_query("SELECT * FROM questions ORDER BY `id` desc LIMIT 1");
    while (
    $row mysql_fetch_array($newly_created_question)){
    $qID $row['id'];
    }

    $result mysql_query("SELECT id FROM candidates");
    while (
    $row mysql_fetch_array($resultMYSQL_NUM)) {
    $cID=$row[0];
    $query "INSERT INTO answers(answer,candidate_id,question_id) VALUES('1','$cID','$qID')";
    mysql_query($query)or die(mysql_error());

    }

    }

    $sql mysql_query('SELECT * FROM questions') or die(mysql_error());
    echo 
    "<form method=\"post\" action=\"delete_edit_question.php\">";
    while(
    $row mysql_fetch_array($sql)){
        
    $qID $row['id'];
        echo 
    "<b>Question #</b>".$row['id']." - ".$row['question']."?";
        echo 
    "<br/>Delete:<input type=\"checkbox\" name=\"selected_question_array[]\" value=\"".$qID."\"><br/>";
        echo 
    "Edit:<input type=\"radio\" name=\"selected_edit_question\" value=\"".$qID."\"><br/>";
        echo 
    "<br />";
    }
    echo 
    "<input type=\"submit\" name=\"delete\" value=\"Delete\">";
    echo 
    "<input type=\"submit\" name=\"edit\" value=\"Edit\">";
    echo 
    "</form>";

    mysql_close(); // Closes DB connection
    }

    include(
    'templates/footer.php'); // Footer Template

    ?>

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    $submit_edit/$_POST['edit'] is empty because there's nothing in the form called "edit". Use a hidden form variable or change $_POST['edit'] to $_POST['submit_new_question'] or whatever you want to use for that page.

  • #3
    New Coder
    Join Date
    Jun 2007
    Posts
    60
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Inigoesdr View Post
    $submit_edit/$_POST['edit'] is empty because there's nothing in the form called "edit". Use a hidden form variable or change $_POST['edit'] to $_POST['submit_new_question'] or whatever you want to use for that page.
    There's a button.

    PHP Code:
    echo "<input type=\"submit\" name=\"edit\" value=\"Edit\">"
    The problem is with
    PHP Code:
        $submit_new_question $_POST['submit_new_question'];
        
    $new_question $_POST['new_question'];
        if(isset(
    $submit_new_question)){
            echo 
    $_POST['new_question'];
        } 

  • #4
    New Coder
    Join Date
    Jun 2007
    Posts
    60
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Any ideas?

  • #5
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    Since this form doesn't have an "action" it has to post to itself. The elements in the form are: new_question & submit_new_question. However, they aren't set until after the form is submitted, and since this form doesn't contain anything named "edit" for the first and second lines, it doesn't ever get to your echo.
    PHP Code:
    $submit_edit $_POST['edit'];
    if(isset(
    $submit_edit)){
        echo 
    "<form method=\"POST\">";
        echo 
    "Enter new question: <input type=\"text\" name=\"new_question\">";
        echo 
    "<input type=\"submit\" name=\"submit_new_question\" value=\"Edit\">";
        echo 
    "</form>";
        
    $submit_new_question $_POST['submit_new_question'];
        
    $new_question $_POST['new_question'];
        if(isset(
    $submit_new_question)){
            echo 
    $_POST['new_question'];
        }



  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •