MySql正确的语法在' 19:18附近使用

时间:2016-08-24 12:31:03

标签: php mysql

我使用php运行了一个查询错误

  

您的SQL语法有错误;检查手册   对应于您的MariaDB服务器版本,以获得正确的语法   接近' 20:),('台北',' 12:10'),'东京',' 12:15&# 39;),(' Fra'第2行

我使用php变量值输入数据库。在回声时,像往常一样输出。 Exp:10:20 但是当在查询中使用时,如:' 10:20 我使用这种语法:



<?php
	// database connection
	$koneksi = mysqli_connect("localhost","root","","nilai_valas");

	//delete all data
	$hapus = mysqli_query($koneksi,"TRUNCATE TABLE `jam_dunia`; ");
    //get data
	$Jkt = '<span id=Jkt></span>';
	// Insert data
	$query = mysqli_query($koneksi,"INSERT INTO `jam_dunia`(`nama`,`jam`)
			values ('Jakarta',$Jkt),
			('Taipei','12:10'),
			('Tokyo', '12:15'),
			('Frankfurt', '12:30'),
			('Hongkong', '12:05'),
			('London', '12:10'),
			('Moscow', '12:15'),
			('Mumbai', '12:05'),
			('New York', '12:10'),
			('Auckland', '12:15'),
			('Beijing', '12:05'),
			('Sao Paulo', '12:10'),
			('Sydney', '12:15'),
			('Singapore','12:05')") or die (mysqli_error($koneksi));
 ?>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

将您的查询更改为:

$query = mysqli_query($koneksi,"INSERT INTO `jam_dunia`(`nama`,`jam`)
        values ('Jakarta',"'".$Jkt."'"),
        ('Taipei','12:10'),
        ('Tokyo', '12:15'),
        ('Frankfurt', '12:30'),
        ('Hongkong', '12:05'),
        ('London', '12:10'),
        ('Moscow', '12:15'),
        ('Mumbai', '12:05'),
        ('New York', '12:10'),
        ('Auckland', '12:15'),
        ('Beijing', '12:05'),
        ('Sao Paulo', '12:10'),
        ('Sydney', '12:15'),
        ('Singapore','12:05')") or die (mysqli_error($koneksi));

注意$ Jkt变量。