我的数据没有通过PHP发送到数据库

时间:2016-08-09 18:20:46

标签: php html

我在网站上有一张表格。我需要将我的信息保存到数据库中。我在localhost中创建了一个数据库,但是当我点击提交时,它会在同一页面中显示register.php的整个代码,并且没有数据存储在数据库中,我已将所有文件放在htdocs中。我在index.html中有表单,register.php文件是单独的。这里是php文件:

<?php 
    mysql_connect('localhost','root','');
    if(!$link){
        die('could not connect: ' . mysql_error());
    }
    echo 'connected successfully';
    mysql_select_db(learnqurandb);

        $name = $_post['fullname'];
        $email = $_post['email'];
        $mobile = $_post['mobile'];
        $country = $_post['country'];
        $course = $_post['course'];
        $skype_id = $_post['skype'];

     if($name == ""){
        echo "<script>alert('please enter your name')</script>";
        exit();
    }
    if($email == ""){
        echo "<script>alert('please enter your E-mail')</script>";
        exit();
    }
    if($mobile == ""){
        echo "<script>alert('please enter your Mobile Numbet')</script>";
        exit();
    }
    if($country == ""){
        echo "<script>alert('please enter your country name')</script>";
        exit();
    }
    if($course == ""){
        echo "<script>alert('please select your desire course')</script>";
        exit();
    }
    if($skype_id == ""){
        echo "<script>alert('please enter your Skype ID')</script>";
        exit();
    }

    $check_skype_id = "select * from learnquran where skype = '$skype_id";
    $count = mysql_query('$check_skype_id');

    if(mysql_num_rows ($count) > 0){

        echo"<script>alert('Skype_id $skype_id is already exists, please try another one.')</script>";
        exit();
    }

    $query = "INSERT INTO registration (fullname,email,mobile,country,course,skype) values('$name','$email','$mobile','$country','$course','$skype_id')";

    if(mysql_query ($query)){

        echo "<script>alert('Registration Successfull')</script>";
    }
}
?>

我的html表单就是这个

<div id="form_div">
        <h2>Quick Registration</h2>
        <form name="Form1" method="post" action="register.php" />
        <label for="name">Name:</label>
        <input type="text" name="fullname" id="fname" /><br><br>
        <label for="email">Email:</label>
        <input type="text" name="email" id="user_email" /><br><br>
        <label for="mobile">Mobile:</label>
        <input type="text" name="mobile" id="user_mobile" /><br><br>
        <label for="country">Country:</label>
        <input type="text" name="country" id="user_country" /><br><br>
        <label for="skype">Skype ID:</label>
        <input type="text" name="skype" id="skype_id" /><br><br>
        <label for="course">Course:</label>
        <select name="course" id="desired_course" ><br><br>
        <option value="Select course..." selected>Select course</option><br>
        <option value="Quran Reading">Quran Reading</option>
        <option value="Memorizing the Holy Quran">Memorizing Holy      Quran</option>
        </select><br><br>
        <input type="submit" class="submit" id="button1" value=""/>
        </form>
    </div>

1 个答案:

答案 0 :(得分:0)

您应该使用PDO而不是mysql_connect,因为自PHP 5.5.0起已弃用。请查看本教程,了解如何使用PDO。以下是有关它的更多信息:http://php.net/manual/en/function.mysql-connect.php

https://www.youtube.com/watch?v=QtCdk459NFg&list=PLfdtiltiRHWHkDwEoZ29Q9FKtWVjA46HC

至于您的代码只是在屏幕上显示,请确保您的服务器已启用php。