简体   繁体   中英

PHP MySQL Form Insert

I'm creating a task management list for a project. I've created a form to add each task and echo it into a list.

I want to add a select tag to the form that will allow the user to select the size of the task (small, medium, large or extra large).

My database is set up with 3 columns a unique key that auto increments, description and status.

I want to manipulate the value of the the status at the same time I enter the description. For example selecting "small" from the drop down will give the task entered a value of "1" and a different appearance in the list than a description with a status of "2".

Any feedback is greatly appreciated!!

Here is the code I have:

<?php
    mysql_connect('localhost', 'root', 'root');
    $query = "INSERT INTO `project1`.`tasklist` (
    `key` ,
    `description` ,
    `status`    
    )
    VALUES (
    NULL , '".$_GET["newToDo"]."', '".$_GET["status"]."'    
        );";
    mysql_query($query);
    header('Location: index.php');
?>

<?php
    mysql_connect('localhost', 'root', 'root');
    foreach($_GET['toDone'] as $toDoKey) {
        $query = "UPDATE `project1`.`practice` SET `status` = '0' WHERE `tasklist`.`key` =".$toDoKey.";";
        mysql_query($query);
    }
        header('Location: index.php');
?>

<h1>Get stuff done!</h1>

<form action = "secondary.php" method="GET">
    <label for="newToDo">New To Do:</label>
    <input type="text" name="newToDo" id="newToDo" />

    <select name="taskSize">
    <option value="small" selected="selected">Small</option>
    <option value="medium">Medium</option>
    <option value="large">Large</option>
    <option value="extraLarge">X-Large</option>
    </select>


    <input type="submit" />
    </form>



<h2>to do</h2>
<form action="toDone.php" method="GET">
<ul>    
   <?php 
    mysql_connect('localhost', 'root', 'root');
    $query = "SELECT * FROM  `project1`.`tasklist` WHERE `status` = 1";
    $result = mysql_query($query);
    while ($row = mysql_fetch_assoc($result)) {
        echo $row['description'];
        echo "</li>";
    }
   ?>
    </ul>
<input type="submit" />


    <h2>done</h2>

    <ul id="dunzo"> 
       <?php 
        $query = "SELECT * FROM  `project1`.`tasklist` WHERE `status` = 0";
        $result = mysql_query($query);
        while ($row = mysql_fetch_assoc($result)) {
            echo "<li>";
            echo $row['description'];
            echo "</li>";
        }
       ?>
        </ul>

What I want is to change how each new row in the list looks based on what is selected in the dropdown.

Dude just one thing to add to your code..

Deprecation of mysql_ functions

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM