我的注册页面php无法输入到我的数据库 [英] My registration page php can't input to my Database

查看:97
本文介绍了我的注册页面php无法输入到我的数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法从我的php页面输入任何数据到我的数据库。我已经创建了一个同样的sql数据库,但是仍然无法在我的数据库中输入。



这是我的PHP代码:

<?php //开始php标记
//包含连接数据库连接的connect.php页面
$ hostname =localhost:3306; //本地服务器名称default localhost
$ username =root; // mysql的用户名默认是root。
$ password =heng0711; //如果没有为mysql设置密码,则为空。
$ database ='student'; //你创建的数据库名称
$ con = mysqli_connect($ hostname,$ username,$ password,$ database);

if(!$ con)
{
die('Connection Failed'.mysqli_error());
}
else
{
echoconnected;
}
if(isset($ _ REQUEST)){
$ complete = true;
/ *这更可读* /
$ reqParams = array(
'studentid',
'email',
'password',
'bssword',
'streetaddress',
'postalcode',
'city',
'state',
'DOB',
'contact ',
'性别',
'学校',
'程序',
'学期',
'角色'
);
foreach($ reqParams as $ key){
if($ _ REQUEST [$ key] ==''){
$ complete = false;
休息;
}
}
if(!$ complete){
echo'请填写空白字段。
}
else {
$ studentid = $ _ REQUEST ['studentid'];
$ fname = $ _ REQUEST ['fname'];
$ lname = $ _ REQUEST ['lname'];
$ email = $ _ REQUEST ['email'];
$ password = $ _ REQUEST ['password'];
$ repassword = $ _ REQUEST ['repassword'];
$ streetaddress = $ _ REQUEST ['streetaddress'];
$ postalcode = $ _ REQUEST ['postalcode'];
$ city = $ _ REQUEST ['city'];
$ state = $ _ REQUEST ['state'];
$ DOB = $ _ REQUEST ['DOB'];
$ email = $ _REQUEST ['email'];
$ contact = $ _ REQUEST ['contact'];
$ gender = $ _ REQUEST ['gender'];
$ school = $ _ REQUEST ['school'];
$ program = $ _ REQUEST ['program'];
$ semester = $ _ REQUEST ['semester'];
$ role = $ _ REQUEST ['role'];
$ sql =INSERT INTO student(student_ID,student_fName,student_lName,student_password,student_repassword,
student_StreetAddress,student_PostalCode,student_City,student_State,student_DOB,student_Email,student_Contact,student_Gender,student_School,student_Programme,student_Semester,student_Role, student_ShinePoint)VALUES('$ studentid','$ fname','$ lname','$ email','$ password','$ repassword','$ streetaddress','$ postalcode','$ city',' $ state','$ DOB','$ email','$ contact','$ gender','$ school','$ program','$ semester','$ role','0');
$ res = mysqli_query($ con,$ sql);
如果($ res)
{
echo记录插入成功;
}
else
{
echo插入记录时存在一些问题;
}
}
}
?>

我的Html代码:

 <!DOCTYPE html PUBLIC -  // W3C // DTD XHTML 1.0 Transitional // ENhttp://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd > 
< html xmlns =http://www.w3.org/1999/xhtml>

< head>
< link href =SSCdesign.css =stylesheettype =text / css>
< script src =script.js> < /脚本>
< title>注册< / title>
< / head>

< body>
< header id =SSClogo>< img src =SSC_logo_v2.pngstyle =width:200px; height:200px>< / header>
< form id =form1name =form1method =postaction =Registration.php>
< table width =453border =0cellpadding =6align =center>
< tr>
< th width =222scope =row> StudentID< / th>
< td width =195>< input type =textname =studentidid =studentid/>< / td>
< / tr>
< tr>
< th scope =row>名字< / th>
< td>< input type =textname =fnameid =fname/>< / td>
< / tr>
< tr>
< th scope =row> Last Name< / th>
< td>< input type =textname =lnameid =lname/>< / td>
< / tr>
< tr>
< td>< input type =passwordname =passwordid =password/>< / td>
< / tr>
< tr>
< th scope =row> Comfirm-Password *< / th>
< td>< input type =passwordname =repasswordid =repassword/>< / td>
< / tr>
< tr>
< th scope =row> StreetAddress< / th>
< td>< input type =textname =streetaddressid =streetaddress/>< / td>
< / tr>
< tr>
< th scope =row> PostalCode< / th>
< td>< input type =textname =postalcodeid =postalcode/>< / td>
< / tr>

< tr>
< th width =222scope =row> City< / th>
< td width =195>< input type =textname =cityid =city/>< / td>
< / tr>

< tr>
< td>< input type =textname =stateid =state/>< / td>
< / tr>
< tr>
< td>< input type =textname =DOBid =DOB/>< / td>
< / tr>
< tr>
< th scope =row>电子邮件< / th>
< td>< input type =textname =emailid =email/>< / td>
< / tr>
< tr>
< td>< input type =textname =contactid =contact/>< / td>
< / tr>
< tr>
< th scope =row>性别< / th>
< td>< input type =radioname =genderid =gendervalue =male/>
男性
< input type =radioname =genderid =gendervalue =female/>
女性< / td>
< / tr>
< tr>
< th scope =row>学校< / th>
< td>< input type =textname =schoolid =school/>< / td>
< / tr>
< tr>
< td>< input type =textname =programid =program/>< / td>
< / tr>
< tr>
< td>< input type =textname =semesterid =semester/>< / td>
< / tr>
< tr>
< td>< input type =textname =roleid =role/>< / td>
< / tr>
< tr>
< td> < button type =resetvalue =Reset>取消< /按钮>< / td>
< / tr>
< / table>
< blockquote>
< p>已经有一个帐户? < a href =Login.html>登录< / a>

< / p>
< / form>
< / body>
< / html>


解决方案

在插入查询中,字段数为18,您将插入带有19个值的记录。



计数不匹配。

先删除 $来自您的SQL的电子邮件



它意外添加了两次。


I can't input any data from my php page to my database. I have create a same sql database also still cant input in my database.

Here is my Php code:

<?php     //start php tag
//include connect.php page for database connection
$hostname="localhost:3306"; //local server name default localhost
$username="root";  //mysql username default is root.
$password="heng0711";       //blank if no password is set for mysql.
$database='student';  //database name which you created
$con=mysqli_connect($hostname,$username,$password,$database);

if(! $con)
    {
        die('Connection Failed'.mysqli_error());
    }
else
    {
        echo "connected ";
    }
if (isset($_REQUEST)) {
    $complete = true;
    /* this is much more readable */
    $reqParams = array(
            'studentid',
            'email',
            'password',
            'repassword',
            'streetaddress',
            'postalcode',
            'city',
            'state',
            'DOB',
            'contact',
            'gender',
            'school',
            'programme',
            'semester',
            'role'
    );
    foreach ($reqParams as $key) {
            if($_REQUEST[$key] == '') {
                    $complete = false;
                    break;
            }   
    }
    if(!$complete) {
            echo 'Please fill the empty fields.';
    }
    else {
          $studentid=$_REQUEST['studentid'];
          $fname=$_REQUEST['fname'];
          $lname=$_REQUEST['lname'];
          $email=$_REQUEST['email'];
          $password=$_REQUEST['password'];
          $repassword=$_REQUEST['repassword'];
          $streetaddress=$_REQUEST['streetaddress'];
          $postalcode=$_REQUEST['postalcode'];
          $city=$_REQUEST['city'];
          $state=$_REQUEST['state'];
          $DOB=$_REQUEST['DOB'];
          $email = $_REQUEST['email'];
          $contact=$_REQUEST['contact'];
          $gender=$_REQUEST['gender'];
          $school=$_REQUEST['school'];
          $programme=$_REQUEST['programme'];
          $semester=$_REQUEST['semester'];
          $role=$_REQUEST['role'];
          $sql="INSERT INTO student(student_ID, student_fName, student_lName,student_password, student_repassword ,
student_StreetAddress, student_PostalCode, student_City, student_State, student_DOB, student_Email, student_Contact, student_Gender, student_School, student_Programme, student_Semester, student_Role, student_ShinePoint)VALUES('$studentid','$fname','$lname', '$email', '$password', '$repassword', '$streetaddress', '$postalcode', '$city', '$state','$DOB', '$email', '$contact', '$gender', '$school', '$programme', '$semester', '$role','0')";
$res=mysqli_query($con,$sql);
        If($res)
        {
            echo "Record successfully inserted";
        }
    else
    {
        echo "There is some problem in inserting record";
    }
    }
}
?>

My Html code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<link href="SSCdesign.css" rel="stylesheet" type="text/css">
<script src="script.js"> </script>
<title>Register</title>
</head>

<body>
<header id="SSClogo"><img src="SSC_logo_v2.png" style="width:200px;height:200px"></header>
<form id="form1" name="form1" method="post" action="Registration.php">
  <table width="453" border="0" cellpadding="6" align="center">
    <tr>
      <th width="222" scope="row">StudentID</th>
      <td width="195"><input type="text" name="studentid" id="studentid" /></td>
    </tr>
    <tr>
      <th scope="row">First Name</th>
      <td><input type="text" name="fname" id="fname" /></td>
    </tr>
    <tr>
      <th scope="row">Last Name</th>
      <td><input type="text" name="lname" id="lname" /></td>
    </tr>
       <tr>
      <th scope="row">Password*</th>
      <td><input type="password" name="password" id="password" /></td>
    </tr>
    <tr>
      <th scope="row">Comfirm-Password*</th>
      <td><input type="password" name="repassword" id="repassword" /></td>
    </tr>
    <tr>
      <th scope="row">StreetAddress</th>
      <td><input type="text" name="streetaddress" id="streetaddress" /></td>
    </tr>
    <tr>
      <th scope="row">PostalCode</th>
      <td><input type="text" name="postalcode" id="postalcode" /></td>
    </tr>

    <tr>
      <th width="222" scope="row">City</th>
      <td width="195"><input type="text" name="city" id="city" /></td>
    </tr>

    <tr>
      <th scope="row">State</th>
      <td><input type="text" name="state" id="state" /></td>
    </tr>
    <tr>
      <th scope="row">Date of Birth</th>
      <td><input type="text" name="DOB" id="DOB" /></td>
    </tr>
        <tr>
      <th scope="row">Email</th>
      <td><input type="text" name="email" id="email" /></td>
    </tr>
    <tr>
      <th scope="row">Contact</th>
      <td><input type="text" name="contact" id="contact" /></td>
    </tr>
    <tr>
      <th scope="row">Gender</th>
      <td><input type="radio" name="gender" id="gender" value="male" />
      Male
        <input type="radio" name="gender" id="gender" value="female" />
      Female</td>
    </tr>
    <tr>
      <th scope="row">School</th>
      <td><input type="text" name="school" id="school" /></td>
    </tr>
    <tr>
      <th scope="row">Programme</th>
      <td><input type="text" name="programme" id="programme" /></td>
    </tr>
    <tr>
      <th scope="row">Semester</th>
      <td><input type="text" name="semester" id="semester" /></td>
    </tr>
    <tr>
      <th scope="row">Role</th>
      <td><input type="text" name="role" id="role" /></td>
    </tr> 
    <tr>
      <th scope="row"><button type="submit" name="submit" value="submit">Submit</th>
      <td> <button type="reset" value="Reset">Cancel</button></td>
    </tr>      
  </table>
  <blockquote>
    <p>    Already have a account ? <a href="Login.html"> Login </a>

    </p>
</form>
</body>
</html>

解决方案

In your insert query, number of field is 18 and you are inserting record with 19 values.

Counts mismatch.

remove first $email from your SQL.

Its accidentally added twice.

这篇关于我的注册页面php无法输入到我的数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆