简体   繁体   English

插入语句不起作用。 从一张桌子转移到另一张桌子

[英]Insert statement not working. transfer from one table to another

Pretty new to PHP and MySQL. PHP和MySQL的新手。

I have created an insert statement in my php script, to transfer a row of data from one table to the next for certain fields. 我已经在php脚本中创建了一条insert语句,用于将某些表中的一行数据从一个表传输到下一个表。 Only thing is, it doesn't seem to be working? 唯一的事情是,它似乎不起作用?

Can anybody see where the issue is? 有人可以看到问题出在哪里吗?

<?php

require_once('auth.php');

$host=""; // Host name 
$username=""; // Mysql username
$password=""; // Mysql password 
$db_name=""; // Database name 
$tbl_name="Instruction"; // Table name 


// 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");

 $Reference=$_REQUEST['Reference'];
 $Forename=$_REQUEST['Forename'];
     $surname=$_REQUEST['surname'];
 $DOB=$_REQUEST['DOB'];
 $Mobile=$_REQUEST['Mobile'];
 $Home=$_REQUEST['Home'];
 $Address=$_REQUEST['Address'];
 $Postcode=$_REQUEST['Postcode1'];
 $Email=$_REQUEST['Email'];
 $Accident=$_REQUEST['Accident'];
 $Details=$_REQUEST['Details'];


//semi colon removed  
$sql="INSERT INTO Triage (Reference,Forename,surname,D.O.B,Mobile Number,Home Number,Address,Postcode1,Email,Accident,Details)
 VALUES('.$Reference.','.$Forename.','.$surname.','.$DOB.','.$Mobile.','.$Home.','.$Address.','.$Postcode1.','.$Email.','.$Accident.','.$Details.')";
 $result=mysql_query($sql);


 echo "Successful";
 echo "<BR>";
 echo "<a href='list_records.php'>View result</a>";


 ?> 

You have column names like Mobile Numbe etc, you need to use `` for them also the concatenation does not look correct you should have something as 您有诸如Mobile Numbe之类的列名,您需要使用``,它们的串联也看起来不正确,您应该有以下内容

sql="INSERT INTO 
     Triage 
     (
       Reference, 
       Forename,
       surname,
       `D.O.B`,
       `Mobile Number`,
       `Home Number`,
       Address,
       Postcode1,
       Email,
       Accident,
       Details
      )
     VALUES
  (
    '".$Reference."',
    '".$Forename."',
    '".$surname."',
    '".$DOB."',
    '".$Mobile."',
    '".$Home."',
    '".$Address."',
    '".$Postcode1."',
    '".$Email."',
    '".$Accident."',
    '".$Details."'
 )";

In addition you should use mysql_real_escape_string() for all the request data something as 另外,您应该对所有请求数据使用mysql_real_escape_string(),例如

$Reference=mysql_real_escape_string($_REQUEST['Reference']);

and so on for others 对其他人等等

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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