sql >> データベース >  >> RDS >> Mysql

チェックボックスデータを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テーブルをJSON形式に

    2. 解析エラー:構文エラー、予期しない''(T_ENCAPSED_AND_WHITESPACE)

    3. なぜAndroidSQLiteでこのテーブルを作成できないのですか?

    4. PHPを使用してMySQLデータベーステーブルの最後のレコードをフェッチするにはどうすればよいですか?