Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 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 'keys) VALUES ('1','159')' at line 1' in C:\xampp\htdocs\***\index12.php:93 Stack trace: #0 C:\xampp\htdocs\***\index12.php(93): PDOStatement->execute(Array) #1 {main} thrown in C:\xampp\htdocs\***\index12.php on line 93
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
for($i = 1; $i < sizeof($counts_index);$i++){
//echo $i.": ".$counts_index[$i]."<br/>";
$index = $counts_index[$i];
$sql1 = "INSERT INTO asce (idn,keys) VALUES (:idn,:keys)";
$q1 = $dbh->prepare($sql1);
$params1 = array(
':idn'=>$i,
':keys'=> $index
);
$q1->execute($params1);
}
答案 0 :(得分:3)
private void tbNbCat_KeyDown(object sender, KeyEventArgs e)
{
int id=0;
if (e.KeyCode == Keys.Return){
id = int.Parse(tbNbCat.Text);
MessageBox.Show(id.ToString());
createTxtTeamNames(id);
}
}
public void createTxtTeamNames(int id)
{
TextBox[] txtTeamNames = new TextBox[id];
for (int u = 0; u < id; u++)
{
txtTeamNames[u] = new TextBox();
}
int i = 0;
foreach (TextBox txt in txtTeamNames)
{
string name = "TeamNumber" + i.ToString();
txt.Name = name;
txt.Text = name;
txt.Location = new Point(0, 32 + (i * 28));
txt.Visible = true;
this.Controls.Add(txt);
i++;
}
}
是MySQL中的保留字。您可以更改列名称(更好的解决方案),也可以在反引号中更新查询包装Keys
。
keys