您好我创建了一个表,但是当我尝试从中获取数据时,我发现很多问题,所以我创建了另一个表,我尝试将第一个表中的列t1m1和t1m2从第二个表中cpy到列loc_awa并将它们分开用' _'和rt1m1 rt1m2成绩等等 但是当我运行php页面时,我收到此错误
"致命错误:未捕获的异常' PDOException'与消息 ' SQLSTATE [42000]:语法错误或访问冲突:1064您有 SQL语法错误;查看与您的手册相对应的手册 MySQL服务器版本使用正确的语法来匹配VALUES (' 1'' IRT_MAS'' 2_0')'在第1行'在C:\ wamp \ www \ fantasy \ temp.php上 第19行"
- 表1 -
--Table1--
<style type="text/css">
table.tableizer-table {
border: 1px solid #CCC; font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
}
.tableizer-table td {
padding: 4px;
margin: 3px;
border: 1px solid #ccc;
}
.tableizer-table th {
background-color: #104E8B;
color: #FFF;
font-weight: bold;
}
</style><table class="tableizer-table">
<tr class="tableizer-firstrow"><th>jawla_id Croissant </th><th>m1t1 </th><th>rm1t1 </th><th>m1t2 </th><th>rm1t2 </th><th>m2t1 </th><th>rm2t1 </th><th>m2t2 </th><th>rm2t2 </th><th>m3t1 </th><th>rm3t1 </th><th>m3t2 </th><th>rm3t2 </th><th>m4t1 </th><th>rm4t1 </th><th>m4t2 </th><th>rm4t2 </th><th>m5t1 </th><th>rm5t1 </th><th>m5t2 </th><th>rm5t2 </th><th>m6t1 </th><th>rm6t1 </th><th>m6t2 </th><th>rm6t2 </th><th>m7t1 </th><th>rm7t1 </th><th>m7t2 </th><th>rm7t2 </th><th>m8t1 </th><th>rm8t1 </th><th>m8t2 </th><th>rm8t2</th></tr>
<tr><td>1 </td><td>IRT </td><td>2 </td><td>MAS </td><td>0 </td><td>KAC </td><td>0 </td><td>DHJ </td><td>0 </td><td>FUS </td><td>2 </td><td>RCA </td><td>0 </td><td>WAC </td><td>4 </td><td>FAR </td><td>2 </td><td>RSB </td><td>0 </td><td>OCK </td><td>0 </td><td>HUSA </td><td>2 </td><td>CRA </td><td>1 </td><td>KACM </td><td>2 </td><td>MCO </td><td>0 </td><td>OCS </td><td>1 </td><td>MAT </td><td>0</td></tr>
<tr><td>2 </td><td>CRA </td><td>1 </td><td>IRT </td><td>0 </td><td>RCA </td><td>1 </td><td>KACM </td><td>1 </td><td>MAS </td><td>1 </td><td>FUS </td><td>1 </td><td>FAR </td><td>1 </td><td>OCS </td><td>1 </td><td>MCO </td><td>1 </td><td>KAC </td><td>0 </td><td>DHJ </td><td>0 </td><td>RSB </td><td>1 </td><td>OCK </td><td>1 </td><td>WAC </td><td>3 </td><td>MAT </td><td>2 </td><td>HUSA </td><td>4</td></tr>
<tr><td>3 </td><td>OCS </td><td>0 </td><td>OCK </td><td>1 </td><td>IRT </td><td>2 </td><td>MAT </td><td>2 </td><td>KACM </td><td>0 </td><td>MAS </td><td>0 </td><td>FUS </td><td>1 </td><td>CRA </td><td>1 </td><td>KAC </td><td>1 </td><td>RSB </td><td>2 </td><td>MCO </td><td>0 </td><td>RCA </td><td>1 </td><td>WAC </td><td>2 </td><td>DHJ </td><td>1 </td><td>HUSA </td><td>1 </td><td>FAR </td><td>0</td></tr>
<tr><td>4 </td><td>MAT </td><td>0 </td><td>FUS </td><td>3 </td><td>RCA </td><td>0 </td><td>KAC </td><td>1 </td><td>CRA </td><td>1 </td><td>KACM </td><td>0 </td><td>MAS </td><td>1 </td><td>MCO </td><td>2 </td><td>FAR </td><td>1 </td><td>IRT </td><td>2 </td><td>DHJ </td><td>0 </td><td>OCS </td><td>0 </td><td>OCK </td><td>2 </td><td>HUSA </td><td>1 </td><td>RSB </td><td>0 </td><td>WAC </td><td>0</td></tr>
<tr><td>5 </td><td>IRT </td><td>2 </td><td>OCK </td><td>1 </td><td>KACM </td><td>2 </td><td>MAT </td><td>1 </td><td>FUS </td><td>2 </td><td>FAR </td><td>3 </td><td>RCA </td><td>3 </td><td>MAS </td><td>0 </td><td>KAC </td><td>0 </td><td>WAC </td><td>1 </td><td>HUSA </td><td>1 </td><td>DHJ </td><td>1 </td><td>MCO </td><td>2 </td><td>CRA </td><td>3 </td><td>OCS </td><td>1 </td><td>RSB </td><td>0</td></tr>
<tr><td>6 </td><td>RSB </td><td>1 </td><td>HUSA </td><td>1 </td><td>FAR </td><td>1 </td><td>KACM </td><td>0 </td><td>DHJ </td><td>1 </td><td>IRT </td><td>1 </td><td>OCK </td><td>1 </td><td>FUS </td><td>2 </td><td>WAC </td><td>2 </td><td>OCS </td><td>0 </td><td>MAS </td><td>0 </td><td>KAC </td><td>0 </td><td>CRA </td><td>0 </td><td>RCA </td><td>2 </td><td>MAT </td><td>1 </td><td>MCO </td><td>1</td></tr>
<tr><td>7 </td><td>IRT </td><td>1 </td><td>RSB </td><td>0 </td><td>KACM </td><td>1 </td><td>OCK </td><td>0 </td><td>FUS </td><td>0 </td><td>DHJ </td><td>0 </td><td>MCO </td><td>0 </td><td>FAR </td><td>0 </td><td>KAC </td><td>2 </td><td>OCS </td><td>1 </td><td>MAS </td><td>1 </td><td>CRA </td><td>0 </td><td>RCA </td><td>2 </td><td>MAT </td><td>3 </td><td>HUSA </td><td>0 </td><td>WAC </td><td>1</td></tr>
<tr><td>8 </td><td>CRA </td><td>1 </td><td>KAC </td><td>2 </td><td>OCS </td><td>2 </td><td>HUSA </td><td>4 </td><td>DHJ </td><td>1 </td><td>KACM </td><td>0 </td><td>WAC </td><td>2 </td><td>IRT </td><td>2 </td><td>FAR </td><td>1 </td><td>RCA </td><td>0 </td><td>MAT </td><td>1 </td><td>MAS </td><td>0 </td><td>OCK </td><td>1 </td><td>MCO </td><td>2 </td><td>RSB </td><td>0 </td><td>FUS </td><td>1</td></tr>
<tr><td>9 </td><td>CRA </td><td>1 </td><td>MAT </td><td>2 </td><td>IRT </td><td>0 </td><td>OCS </td><td>1 </td><td>KACM </td><td>0 </td><td>RSB </td><td>0 </td><td>KAC </td><td>3 </td><td>HUSA </td><td>1 </td><td>FUS </td><td>1 </td><td>WAC </td><td>0 </td><td>RCA </td><td>1 </td><td>OCK </td><td>2 </td><td>MAS </td><td>0 </td><td>FAR </td><td>1 </td><td>MCO </td><td>1 </td><td>DHJ </td><td>0</td></tr>
<tr><td>10 </td><td>HUSA </td><td>1 </td><td>IRT </td><td>3 </td><td>FAR </td><td>2 </td><td>CRA </td><td>2 </td><td>WAC </td><td>2 </td><td>KACM </td><td>0 </td><td>DHJ </td><td>1 </td><td>RCA </td><td>1 </td><td>OCK </td><td>0 </td><td>MAS </td><td>3 </td><td>RSB </td><td>2 </td><td>MCO </td><td>1 </td><td>MAT </td><td>1 </td><td>KAC </td><td>0 </td><td>OCS </td><td>0 </td><td>FUS </td><td>1</td></tr>
<tr><td>11 </td><td>MAS </td><td>0 </td><td>DHJ </td><td>0 </td><td>MCO </td><td>1 </td><td>WAC </td><td>1 </td><td>MAT </td><td>1 </td><td>FAR </td><td>1 </td><td>RCA </td><td>1 </td><td>RSB </td><td>0 </td><td>CRA </td><td>1 </td><td>OCK </td><td>0 </td><td>KAC </td><td>0 </td><td>IRT </td><td>0 </td><td>KACM </td><td>1 </td><td>OCS </td><td>2 </td><td>FUS </td><td>2 </td><td>HUSA </td><td>0</td></tr>
</table>
&#13;
<?php
try{
$host="localhost";
$datab="nmdatab";
$user="user";
$pass="password";
$conect=new PDO("mysql:host=$host;dbname=$datab",$user,$pass);
$conect->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(Exception $e){
die('Erreur : '.$e->getMessage());
}
$matche=$conect->query('SELECT * FROM jawlat ORDER BY jawla_id');
while ($mt=$matche->fetch()){
$jawla_id="".$mt["jawla_id"]."";
$match="".$mt["m1t1"]."_".$mt["m1t2"]."";
$score="".$mt["rm1t1"]."_".$mt["rm1t2"]."";
$nt="INSERT INTO match VALUES ('$jawla_id','$match','$score')";
$conect->exec($nt);
$match="".$mt["m2t1"]."_".$mt["m2t2"]."";
$score="".$mt["rm2t1"]."_".$mt["rm2t2"]."";
$nt="INSERT INTO match VALUES ('$jawla_id','$match','$score')";
$conect->exec($nt);
$match="".$mt["m3t1"]."_".$mt["m3t2"]."";
$score="".$mt["rm3t1"]."_".$mt["rm3t2"]."";
$nt="INSERT INTO match VALUES ('$jawla_id','$match','$score')";
$conect->exec($nt);
$match="".$mt["m4t1"]."_".$mt["m4t2"]."";
$score="".$mt["rm4t1"]."_".$mt["rm4t2"]."";
$nt="INSERT INTO match VALUES ('$jawla_id','$match','$score')";
$conect->exec($nt);
$match="".$mt["m5t1"]."_".$mt["m5t2"]."";
$score="".$mt["rm5t1"]."_".$mt["rm5t2"]."";
$nt="INSERT INTO match VALUES ('$jawla_id','$match','$score')";
$conect->exec($nt);
$match="".$mt["m5t1"]."_".$mt["m5t2"]."";
$score="".$mt["rm5t1"]."_".$mt["rm5t2"]."";
$nt="INSERT INTO match VALUES ('$jawla_id','$match','$score')";
$conect->exec($nt);
$match="".$mt["m5t1"]."_".$mt["m5t2"]."";
$score="".$mt["rm5t1"]."_".$mt["rm5t2"]."";
$nt="INSERT INTO match VALUES ('$jawla_id','$match','$score')";
$conect->exec($nt);
$match="".$mt["m5t1"]."_".$mt["m5t2"]."";
$score="".$mt["rm5t1"]."_".$mt["rm5t2"]."";
$nt="INSERT INTO match VALUES ('$jawla_id','$match','$score')";
$conect->exec($nt);
echo "jawla ".$jawla." done";
}
&GT;
答案 0 :(得分:1)
匹配是reserved关键字,您需要使用back-ticks
INSERT INTO `match`(col1,col2,col3)
VALUES ('$jawla_id','$match','$score')