English 中文(简体)
在数据库中插入已张贴的详细信息 [关闭]
原标题:inserted posted details into database [closed]
  • 时间:2012-05-25 14:55:55
  •  标签:
  • php
  • mysql

当用户在我的网站上注册时, 他们必须输入个人细节 。 输入的细节将被添加到我的 Datbase 的个人细节表格中 。 我有以下代码, 但是它不起作用, 我无法找到原因 。 有人能帮忙吗? 我得到错误信息: query was empty

    $myusername=$_POST[ username ];
    $mypassword=$_SESSION[ mypassword ];
    $firstname = $_POST[ firstname ];
    $surname = $_POST[ surname ];
    $dob = $_POST[ dob ];
    $totalwins = $_POST[ totalwins ];
    $totalloses = $_POST[ totalloses ];
    $email = $_POST[ email ];
    $country = $_POST[ country ];
    $info = $_POST[ info ];

    // Connect to server and select database.
    mysql_connect("$host", "$username", "$password")or die("cannot connect");
    mysql_select_db("$db_name")or die("cannot select DB");

    $queryreg = mysql_query("

                INSERT INTO $tbl_name VALUES(  ,  , $myusername , $mypassword  $firstname , $surname , $totalwins , $totalloses , $email , $country , $info , $dob  )
        ");

if (!mysql_query($sql))
      {
     die( Error:   . mysql_error());
      }
      else  {
      echo "<br><br>Your details have been successfully updated. Go back to the                 personal details page to view your updated information.";
    }
最佳回答

首先, 您会用代码被 SQL 注射 。 请准备并跳出您的日志数据 。 这对防止 SQL 输入攻击非常重要 。 请仔细阅读它 。

然后,误差就由此而发生

if (!mysql_query($sql))
  {
 die( Error:   . mysql_error());
  }
  else  {
  echo "<br><br>Your details have been successfully updated. Go back to the                 personal details page to view your updated information.";
}

您似乎没有名为$sql 的变量, 您正在执行两个查询!

请做以下工作并发布反馈

$sql = "INSERT INTO $tbl_name VALUES(  ,  , $myusername , $mypassword  $firstname , $surname , $totalwins , $totalloses , $email , $country , $info , $dob  )";

if (!mysql_query($sql))
  {
 die( Error:   . mysql_error());
  }
  else  {
  echo "<br><br>Your details have been successfully updated. Go back to the                 personal details page to view your updated information.";
}
问题回答

如果您使用带有自动递增的主要字段, 您应该指定字段名称 :

$queryreg = mysql_query("INSERT INTO $tbl_name (field1,field2,field3 ecc) VALUES( ... )");

还有你的密码是注射用的,我们是PDO

查询为空, 原因是您在行中对 $sql 有任何指定值

if (!mysql_query($sql))

要解决问题,你必须把它分配为:

  $sql = "update  $tbl_name set ...";
  if (!mysql_query($sql))

有很多东西让我害怕 你的代码...

更改如下(在 $mypassword $sql 未设置正确之后,您缺少了一个逗号) 。

$sql = "INSERT INTO $tbl_name ( [list columns here besides autoincrement ] ) 
    VALUES 
    (  ,  $myusername ,  $mypassword ,  $firstname ,  $surname , 
     $totalwins ,  $totalloses ,  $email ,  $country ,  $info ,  $dob  )");

if (!mysql_query($sql)) {




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签