如何从php到sql数据库显示数组?

时间:2015-02-06 10:41:10

标签: php sql arrays

注册后,信息应该存储在sql中。但是,兴趣会显示“数组”而不是勾选的项目。对于这个数组,我想打印出数组的名称,而不是显示单词“array”

php文件中的代码是:

<?php

    if(!empty($_POST['userid'])){
    $userid=$_POST['userid'];
    }
    else
    {
    $userid=null;
    echo "<b><font color='red'>Please enter your userid</font></b></p>";
    }

    if(!empty($_POST['pwd'])){
    $password=$_POST['pwd'];
    }
    else 
    { 
    $password=null;
    echo "<b><font color='red'>Please enter your password</font></b></p>";
    }

    if(!empty($_POST['name'])){

    $name=$_POST['name']; 
    //name passed from the registerVistor.html
    //is stored in variable $name
    }
    else
    {
    $name=null;
    echo "<b><font color='red'>Please enter your name</font></b></p>";
    }

    if(!empty($_POST['gender'])){
    $gender=$_POST['gender'];
    }
    else
    {
    $gender=null;
    echo "<b><font color='red'>Please enter your gender</font></b></p>";
    }

    $day = $_POST['day'];
    $month = $_POST['month'];
    $year = $_POST['year'];
    if(checkdate($month,$day,$year)==true){
    $dateOfBirth = $day . '/' . $month . '/' . $year;





 echo "<b><font color='red'>Please enter your date of birth</font></b></p>";



    //checkbox
    if(isset($_POST['interests'])){
    $interests=$_POST['interests'];

    }
    else
    {
    $interests=null;
    echo "<b><font color='red'>Please enter your categories of interests</font></b></p>";
    }


    if($name && $userid && $password && $gender && $interests  && $dateOfBirth)
    {
    echo "Thank you for registering with us, <b>$name </b><br> <br>";
    echo "You have entered the following details: <br>";
    echo "UserID:$userid<br>";
    echo "Status:$gender <br>"; 
    echo "Date Of Birth:$dateOfBirth<br>";
    echo "Interests : <br>";
        foreach($interests as $value)
          {
              echo "$value </br>";
          }

   }
   else
   {

   echo "<br> <br> ";
   echo "<font color='red'>Please go back and fill out the form again. </font></p>";
   }

$mysqli=new mysqli("localhost","root",null,"recipedb");

$stmt=$mysqli->
prepare("INSERT INTO recipeuser (userid, password, name, gender, address, dateOfBirth, interests)
VALUES ('$userid','$password','$name','$gender',null,'$dateOfBirth','$interests')");


$stmt->execute();

    $stmt->fetch();

        $stmt->close();

        $mysqli->close();

?>  

0 个答案:

没有答案