无法在php中将数据插入数据库

时间:2015-12-31 15:12:49

标签: php html mysql sql

这是我的连接代码和查询:

$conn = new mysqli('localhost' , 'root' , '#PASSWORD_HERE#' , 'NSEG');

    if($conn->connect_error)
    {
        die("Unable to connect!");
    }

    $Query = "INSERT INTO professors(id , Username , FirstName , LastName , Gender , Email) VALUES (NULL , '$username' , '$fname' , '$lname' , '$Gender' , '$Email')";
    $conn->query($Query);

    $conn->close();

但是当我提交并且我转到php我的管理员时,它并没有显示任何" prfessors"表! 我该怎么办?!

3 个答案:

答案 0 :(得分:1)

假设您的ID列为removeplayer()而不是PK,因为它应该自动增量,请尝试以下操作:

NULL

答案 1 :(得分:1)

./manage.py migrate

在尝试下面的PHP代码段之前。请确保以下几点。

  1. 确保<?php $con = mysqli_connect("localhost", "root", "1379Mohammad", "NSEG"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } // Perform queries $query = "INSERT INTO professors(id , Username , FirstName , LastName , Gender , Email) VALUES (NULL , '$username' , '$fname' , '$lname' , '$Gender' , '$Email')"; if (!mysqli_query($con, $query)) { echo ("Error description: " . mysqli_error($con)); } mysqli_close($con); 表存在。
  2. 确保professors字段为主键并自动增加。
  3. 打印SQL查询并确保所有值都为非空。
  4. 检查mysqli_error,如果有任何其他错误。
  5.   

    使用主键和自动增量创建表的SQL,根据需要更改其他内容。

    id

答案 2 :(得分:1)

function download_image($image_url){
    $ch = curl_init($image_url);
    // curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // enable if you want
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 1000);      // some large value to allow curl to run for a long time
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0');
    curl_setopt($ch, CURLOPT_WRITEFUNCTION, "curl_callback");
    curl_setopt($ch, CURLOPT_VERBOSE, true);   // Enable this line to see debug prints
    curl_exec($ch);

    curl_close($ch);                              // closing curl handle
}

/** callback function for curl */
function curl_callback($ch, $bytes){
    global $fp;
    $len = fwrite($fp, $bytes);
    // if you want, you can use any progress printing here
    return $len;
}

$image_file = "ram.png";
$fp = fopen ($image_file, 'w+');              // open file handle
download_image("http://chart.apis.google.com/chart?chl=30%&amp;chs=300x120&amp;cht=gm&amp;chco=77AB10,FFFF00|FF0000&amp;chd=t:30&amp;chf=bg,s,232526");
fclose($fp);