Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php MYSQL读取和写入不同的表_Php_Mysql_Forms - Fatal编程技术网

Php MYSQL读取和写入不同的表

Php MYSQL读取和写入不同的表,php,mysql,forms,Php,Mysql,Forms,我有一个表单,它通过电子邮件将表单数据发送到一个电子邮件地址。我也想将这些信息存储到数据库中。我遇到的问题是,我从一个表中提取信息,即在线租赁数据库,以便将其中的信息发送给我们。我还想将表单信息存储到另一个在线表格中 <?php $rentID = $_POST['current_id']; $db=mysql_connect ("localhost","test","test") or die(mysql_error()); mysql_select_db("rentals");

我有一个表单,它通过电子邮件将表单数据发送到一个电子邮件地址。我也想将这些信息存储到数据库中。我遇到的问题是,我从一个表中提取信息,即在线租赁数据库,以便将其中的信息发送给我们。我还想将表单信息存储到另一个在线表格中

<?php

$rentID = $_POST['current_id'];

$db=mysql_connect ("localhost","test","test") or die(mysql_error());
mysql_select_db("rentals");

$table="online_rental_db";
$sql = "SELECT * FROM $table WHERE ID=$rentID";
$query = mysql_query($sql) or die(mysql_error());
$rentals = mysql_fetch_assoc($query);
$description = ucwords(strtolower($rentals['Description']));
$image = $rentals['Image'];
$download = $rentals['PDF'];
$bytes =  filesize($rentals['PDF']);
$ID = $rentals['ID'];
$CTGID = $rentals['CTGID'];
$category = $rentals['Category'];
$model = $rentals['model'];
但是它给了我一个sql错误

怎么样

$sql = "INSERT INTO online_rental_request (name, email, id, description, model, category) SELECT '$_POST[name]','$_POST[email]', id, description, model, category  FROM $table WHERE ID=$rentID ";
因此,它的格式是:

INSERT INTO online_rental_request (name, email, id, description, model, category) 
SELECT 
   '$_POST[name]',
   '$_POST[email]', 
   id, 
   description, 
   model, 
   category 
FROM $table 
WHERE ID=$rentID 

通过这种方式,您可以指定名称和电子邮件,还可以从$table中插入信息并将其插入在线租赁请求。

如果您想直接从在线租赁数据库表插入在线租赁请求表,您应该执行以下操作:

$name = mysql_escape_string($_POST['name']);
$email = mysql_escape_string($_POST['email']);
$sql = "INSERT INTO online_rental_request (name, email, id, description, model, category) SELECT '$name', '$email', id, description, model, category FROM $table WHERE ID=$rentID";
顺便说一下,您不应该忘记转义用户提交的值。您应该这样做:

$rentID = mysql_escape_string($_POST['current_id']);
或者更好
$rentID=int$_POST['current_id']

从$sql中删除$table中的SELECT*,其中ID=$rentID,因此它以INSERT INTO开头,应该可以插入。那么您的意思是$sql=插入在线租赁请求名称、电子邮件、id、描述、模型、类别值“$\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\;我知道仅仅使用INSERT是可行的,但我需要其他表中的信息,如描述、类别、模型等。
$rentID = mysql_escape_string($_POST['current_id']);