0

我不是一个训练有素的程序员。我从网上学到的都是我自己。如果您发现我的代码和问题非常业余,请原谅。

我正在尝试根据数据库中的卖家数据调用买家的匹配项,并自动将他们的匹配项邮寄给他们。

当我使用 EasyPhp 在我的系统上运行此代码时,它显示“查询为空”。当我在服务器上运行此代码时,它显示"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 '1' at line 1 "我哪里出错了?

<?php

include('adminmaster.htm');

Echo "<center>Mail Matching Properties</center><br><br>";

mysql_connect("localhost", "username","password") or die(mysql_error()); 


mysql_select_db("database") or die(mysql_error()); 

$query= 'SELECT*FROM clientdata WHERE email != "  " AND Transaction="Buyer"';


$result=mysql_query($query);


echo mysql_error();


if (!$result){ die("No Buy results");}

$matchrows=mysql_num_rows($result);

if($matchrows==0){ die("No Buy results");}


while($info = mysql_fetch_array($result))


$Price1= $info['Price']+($info['Price']*10/100);

$Price2 = $info['Price']-($info['Price']*10/100);

$una=$info['username'];

$query2='SELECT*FROM clientdata WHERE email!=" " AND Transaction="Seller"';


$result2=mysql_query($query2);


echo mysql_error();


$matchrows2=mysql_num_rows($result2);


if($matchrows2==0){ die("Sell Data Not Found");}


if(!$result2)

{die("Sell Data Not Found");}

while($info2=mysql_fetch_array($result2))

{

if ($info['Detail']==$info2['Detail'])

{

if ($info['Location']==$info2['Location'])

{

if ($Price1 >= $info2['Price'])
{

if ($Price2 <= $info2['Price'])

{

if ($info['username']!=$info2['username'])

{

echo mysql_error();

echo "<table width=600 border = 1 style='text-align:left';>

<tr>
<td><b>Clients</b></td>
<td><b><font color='maroon'>BUYER</font></b></td>
<td><b><font color='maroon'>SELLER</font></b></td>
</tr>

<tr>
<td><b>Date Posted:</b></td>
<td>$info[Date]</td>
<td>$info2[Date]</td>
</tr>

<tr>
<td><b>Title:</b></td>
<td>$info[propheading]</td>
<td>$info2[propheading]</td>
</tr>

<tr>
<td><b>Transaction:</b></td>
<td>$info[Transaction]</td>
<td>$info2[Transaction]</td>
</tr>
<tr>
<td style='background-color:lightgrey'><b>Detail:</b></td>
<td style='background-color:lightgrey'>$info[Detail]</td>
<td style='background-color:lightgrey'>$info2[Detail]</td>
</tr>
<tr>
<td style='background-color:lightgrey'><b>Price:</b></td>
<td style='background-color:lightgrey'>$info[Price]</td>
<td style='background-color:lightgrey'>$info2[Price]</td>
</tr>

<tr>
<td><b>Additional Data:</b></td>
<td>$info[AdditionalData]</td>
<td>$info2[AdditionalData]</td>
</tr>


<tr>
<td><b>Location:</b></td>
<td>$info[Location]</td>
<td>$info2[Location]</td>
</tr>
<tr>
<td><b>Agent/Individual:</b></td>
<td>$info[Agent_Ind]</td>
<td>$info2[Agent_Ind]</td>
</tr>
<tr>
<td><b>Name:</b></td>
<td>$info[Title] $info[firstname] $info[lastname]</td>
<td>$info2[Title] $info2[firstname] $info2[lastname]</td>
</tr>
<tr>
<td><b>Phone:</b></td>
<td>$info[Phone]</td>
<td>$info2[Phone]</td>
</tr>
<tr>
<td><b>Email:</b></td>
<td>$info[Email]</td>
<td>$info2[Email]</td></tr>

</table>";

$tomail=$info2['Email'];

if   ($tomail=="anitgopinath@gmail.com"|$tomail=="anit@landshoppe.com"|$tomail=="info@landshoppe.com")  {continue;}

$headers ="From:info@landshoppe.com"."\r\n";

$headers .='Bcc:anit@landshoppe.com'."\n";
$headers .= 'MIME-Version: 1.0'."\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1'."\r\n";
$subject ="You have a Property Match !";

$message="<html></head><body>

<table width=600 border = 1 style='text-align:left';>

<caption><b><font color='maroon'>YOUR PROPERTY MATCH!</font></b></caption>

<tr>
<td><b>Date Posted:</b></td>
<td>$info[Date]</td>
</tr>

<tr>
<td><b>Title:</b></td>
<td>$info[propheading]</td>
</tr>
<tr>
<td><b>Transaction:</b></td>
<td>$info[Transaction]</td>
</tr>
<tr>
<td style='background-color:lightgrey'><b>Detail:</b></td>
<td style='background-color:lightgrey'>$info[Detail]</td>
</tr>
<tr>
<td style='background-color:lightgrey'><b>Price:</b></td>
<td style='background-color:lightgrey'>$info[Price]</td>
</tr>

<tr><td><b>Additional Data:</b></td><td>$info[AdditionalData]</td></tr>
<tr><td><b>Location:</b></td><td>$info[Location]</td></tr>
<tr><td><b>Agent/Individual:</b></td><td>$info[Agent_Ind]</td></tr>
<tr><td><b>Name:</b></td><td>$info[Title] $info[firstname] $info[lastname]</td></tr>
<tr><td><b>Phone:</b></td><td>$info[Phone]</td></tr>
<tr><td><b>Email:</b></td><td>$info[Email]</td></tr>

</table></body><html>";

echo $tomail."<br>";
echo "$message"."<br>";

$mailresult=mysql_query(mail($tomail,$subject,$message,$headers));

if ($mailresult){echo "Mailed<br>";}else{echo "Not Mailed !<br>";}

echo "**********************************Seller Match**************************************************<br>";


$tomail2=$info['Email'];

if   ($tomail2=="anitgopinath@gmail.com"|$tomail2=="anit@landshoppe.com"|$tomail2=="info@landshoppe.com"){continue;}

$headers ="From:info@landshoppe.com"."\r\n";

$headers .='Bcc:anit@landshoppe.com'."\n";
$headers .= 'MIME-Version: 1.0'."\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1'."\r\n";
$subject ="You have a Property Match !";

$message="<html></head><body>

<table width=600 border = 1 style='text-align:left';>

<caption><b><font color='maroon'>YOUR PROPERTY MATCH!</font></b></caption>

<tr>
<td><b>Date Posted:</b></td>
<td>$info2[Date]</td>
</tr>

<tr>
<td><b>Title:</b></td>
<td>$info2[propheading]</td>
</tr>

<tr>
<td><b>Transaction:</b></td>
<td>$info2[Transaction]</td>
</tr>
<tr>
<td style='background-color:lightgrey'><b>Detail:</b></td>
<td style='background-color:lightgrey'>$info2[Detail]</td>
</tr>
<tr>
<td style='background-color:lightgrey'><b>Price:</b></td>
<td style='background-color:lightgrey'>$info2[Price]</td>
</tr>

<tr>
<td><b>Additional Data:</b></td>
<td>$info2[AdditionalData]</td>
</tr>

<tr>
<td><b>Location:</b></td>
<td>$info2[Location]</td>
</tr>
<tr>
<td><b>Agent/Individual:</b></td>
<td>$info2[Agent_Ind]</td>
</tr>
<tr>
<td><b>Name:</b></td>
<td>$info2[Title] $info2[firstname] $info2[lastname]</td>
</tr>
<tr>
<td><b>Phone:</b></td>
<td>$info2[Phone]</td>
</tr>
<tr>
<td><b>Email:</b></td>
<td>$info2[Email]</td>
</tr>

</table></body><html>";

echo $tomail2."<br>";
echo "$message"."<br>";

$mailresult2=mysql_query(mail($tomail2,$subject,$message,$headers));

if ($mailresult2){echo "Mailed<br>";}else{echo "Not Mailed !<br>";}

echo "**********************************Buyer Match**************************************************<br>";

}
}
}
}
}
}
}
?>
4

2 回答 2

0

不想听起来粗鲁,但你最好重新设计你的代码,现在一团糟。从一个简单的“分而治之”方法开始:标记每个只做一件事的代码块 - 并分成一个函数(只在主脚本中保留它的调用)。您会立即注意到它在阅读和更新代码方面的不同。

您所说的错误是由这一行引起的:

$mailresult=mysql_query(mail($tomail,$subject,$message,$headers));

...因为mailfunction 的结果是boolean。当被mysql_query转换成字符串时,要么是空字符串,要么是'1'; 当然,它们都不是有效的查询。如果你需要检查结果,那只是......

$mailresult=mail($tomail,$subject,$message,$headers);

再一次,错误本身很简单——但它隐藏在你的代码中是如此之好,以至于五个或更多的 SO 用户未能找到它。) 这就是代码需要重组的原因。

于 2012-05-21T10:16:42.633 回答
0

首先,在 SQL 请求中指定字符串文字时,您应该使用单个 qoutes:

$query= "SELECT*FROM clientdata WHERE email != '  ' AND Transaction='Buyer'";
于 2012-05-21T10:07:19.680 回答