sql >> Database teknologi >  >> RDS >> Mysql

Indsæt afkrydsningsfeltdata til mysql

    # Please Try again below code. #  

      <?php 
    if($_SERVER['HTTP_HOST'] == 'localhost:8080') {
        $servername = "localhost";
        $username = "root";
        $password = "";
        $db = 'test';
    }

    $conn = mysql_connect($servername, $username, $password);
    if ($conn) {
        mysql_select_db($db, $conn) or die('Could not select database.');
    }

    if(isset($_POST['submit'])){
        $monday = isset($_POST['day_name']['monday']) ? $_POST['day_name']['monday'] : 0;
        $tuesday = isset($_POST['day_name']['tuesday']) ? $_POST['day_name']['tuesday'] : 0;
        $wednesday = isset($_POST['day_name']['wednesday']) ? $_POST['day_name']['wednesday'] : 0;
        $thursday = isset($_POST['day_name']['thursday']) ? $_POST['day_name']['thursday'] : 0;
        $friday = isset($_POST['day_name']['friday']) ? $_POST['day_name']['friday'] : 0;

        //echo "INSERT INTO `available_day` (`monday`, `tuesday`, `wednesday`, `thursday`, `friday`) VALUES ('".$monday."', '".$tuesday."', '".$wednesday."', '".$thursday."', '".$friday."')"; 

        $sql_add = mysql_query("INSERT INTO `available_day` (`monday`, `tuesday`, `wednesday`, `thursday`, `friday`) VALUES ('".$monday."', '".$tuesday."', '".$wednesday."', '".$thursday."', '".$friday."')");

        if(!$sql_add)
        {
            die('could not add data'.mysql_error());
        }

        $message="Successfully Added ID No: ".mysql_insert_id();
        echo "<script type='text/javascript'>alert('$message');   window.location.href='index6.php';</script>";

    }

?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="contact_form" enctype='multipart/form-data'>
  <div class="form-group" >
       <input type="checkbox" name="day_name[monday]" value="1">Mon<br>
       <input type="checkbox" name="day_name[tuesday]" value="1"> Tues<br>
       <input type="checkbox" name="day_name[wednesday]" value="1"> Wed<br>
       <input type="checkbox" name="day_name[thursday]" value="1"> Thu<br>
       <input type="checkbox" name="day_name[friday]" value="1"> Fri<br>

    <input name="submit" type ="submit" class="btn btn-default" style="border-radius: 0px; background-color: midnightblue; box-shadow: 2px 2px 2px #888888; color: white;">
  </div> 

</form>


  1. mysql pivoting - hvordan kan jeg hente data fra den samme tabel til forskellige kolonner?

  2. Udbedring af huller i mysql-tabellens række-id, efter at vi har slettet nogle af dem

  3. Sådan eksporteres forespørgselsresultat til .csv eller tabulatorsepareret fil i SQL Server Management Studio(SSMS) - SQL Server / TSQL Selvstudium Del 23

  4. Brug to tabeller på én php-side (mysql)