我还不熟悉PHP编程,我的目标是
从表到另一个表的-transfer数据
<html> <head> <title>Sending Application Form by Email</title> </head> <body>
<?PHP
include ("dbase.php");
if(isset($_COOKIE['ID_my_site']))
{
$username = $_COOKIE['ID_my_site'];
$query = mysql_query("SELECT * FROM employee_database WHERE Employee_Name= '$username'");
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result))
{
$insert = mysql_query ("INSERT INTO `leave_requested`
(`Employee_Name`,
`Employee_ID`,
`Designation`,
`Department`,
`Days_on_Leave`,
`Leave_Start_On`,
`Leave_End_On`,
`Reason for Leave`)
SELECT `Employee_Name`,
`Employee_ID`,
`Designation`,
`Department`,
'$Days',
'$Start',
'$End',
'$Reason'
FROM `employee_database`
WHERE `Employee_Name` = '$username'");
/*
("INSERT INTO leave_requested (Employee_Name, Employee_ID, Designation, Department, Days_on_Leave, Leave_Start_On, Leave_End_On, Reason for Leave)
SELECT Employee_Name, Employee_ID, Designation, Department FROM employee_database
VALUES ('$row[Employee_Name]','$row[Employee_ID]','$row[Designation]','$row[Department]','$_POST['No_Days']','$_POST['StartDate']','$_POST['EndDate']','$_POST['Leave_Reason']')");
*/
}
}
mysql_close ($qry);
?>
<?php
require("C:\AppServ\www\Project\PHPMailer_5.2.4\class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP();
//GMAIL config
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->SMTPSecure = "tls"; // Sets the prefix to the server
$mail->Host = "smtp.gmail.com"; // Sets GMAIL as the SMTP server
$mail->Port = '587'; // Sets the SMTP port for the GMAIL server
$mail->Username = ("my@gmail.com"); // SMTP UserName (Email Address)
$mail->Password = "******"; // SMTP PassWord (Email Address PassWord)
$mail->SMTPDebug = 2; // Enables SMTP debug information (for testing)## 1 = errors and messages ## 2 = messages only ##
$mail->From = $mail->Username; // Sender Email Account on Email
$mail->FromName = 'HR Management'; // Sender Name on Email
$mail->AddAddress('my@yahoo.com', 'JD'); // Add a recipient Email and Name
$mail->WordWrap = 50;
$mail->IsHTML(true);
$mail->Subject = '$username have added Leave Requested'; // Email Subject
$mail->Body = 'This is the HTML message body <b>in bold!</b>'; // HTML Plain Text
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; // HTML Function
if(!$mail->Send())
{
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
echo 'Message has been sent';
?>
</body>
</html>如果有人能够发送一个2 sql查询的示例,我会很高兴的。谢谢
我现在得到的错误是一个奇怪的错误,我以前从未遇到过这种错误。有没有人知道这个错误。请对此错误提出解决方案。谢谢
页错误
*You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #4' at line 1发布于 2014-01-02 13:05:41
$query = mysql_query("SELECT * FROM employee_database WHERE Employee_Name= '$username'");
$result = mysql_query($query) or die(mysql_error());在第一行中,mysql_query()返回一个资源。
在第二行中,将返回值传递回对mysql_query()的另一个调用。
mysql_query()需要一个SQL查询字符串作为参数。
容易修复:
$query = "SELECT * FROM employee_database WHERE Employee_Name= '$username'";
$result = mysql_query($query) or die(mysql_error());一些进一步的建议:
发布于 2014-01-02 08:43:19
首先,我必须告诉您,您的查询很容易使用SQL注入。第二,不再支持mysql_*函数,不再支持。
您可以使用sinle查询来完成它。您可以使用以下查询:
INSERT INTO `leave_requested` (`Employee_Name`,
`Employee_ID`,
`Designation`,
`Department`,
`Days_on_Leave`,
`Leave_Start_On`,
`Leave_End_On`,
`Reason for Leave`)
SELECT `Employee_Name`,
`Employee_ID`,
`Designation`,
`Department`,
'$_POST[\'No_Days\']',
'$_POST[\'StartDate\']',
'$_POST[\'EndDate\']',
'$_POST[\'Leave_Reason\']'
FROM `employee_database`
WHERE `Employee_Name` = '$username' 发布于 2014-01-02 08:43:26
有一种东西叫做插入选择。(我已经链接到MySQL文档,但据我所知,它是标准SQL。)
https://stackoverflow.com/questions/20879120
复制相似问题