-4

我是新来的,这是我在这里的第一个问题!我在 mysql 和 php 中遇到困难

<?php
echo "Hello World";
$con=mysql_connect('localhost:3306','dmail','*****','dhruv');    
if(!$con)
{
echo "Failed to connect"; }

$name2 = 'name2';
$tel_no2 = 'tel_no2';
$email2 = 'email2';
$query2 = 'query2';
$car = 'car';
$city2 = 'city2';
$country2 = 'country2';
$date = 'date';

$query1 ="INSERT INTO 'booking' VALUES (name2, tel_no2, email2, city2, country2, car,         date, query2)";
$query2 ="INSERT INTO 'booking' VALUES ('$name2', '$tel_no2', '$email2', '$city2',     '$country2', '$car', '$date', '$query2')"; 

$update = mysql_query($query1,$con);
if(!$update)
{    echo "Failed to update"; }

>

它总是显示“更新失败”,任何帮助将不胜感激。谢谢。

4

3 回答 3

2
$con=mysql_connect('localhost:3306','dmail','*****','dhruv'); 

应该

$con=mysql_connect('localhost:3306','dmail','*****'); 
$db_selected = mysql_select_db('dhruv', $con);
于 2013-06-14T06:47:32.250 回答
1

删除'table_name 周围并添加'$周围值

$query1 ="INSERT INTO `booking` VALUES ('$name2', '$tel_no2', '$email2', '$city2', '$country2', '$car','$date', '$query2')";
$query2 ="INSERT INTO `booking` VALUES ('$name2', '$tel_no2', '$email2', '$city2',     '$country2', '$car', '$date', '$query2')"; 
于 2013-06-14T06:44:00.453 回答
0

您应该$在 mysql 查询中使用将值实际插入到表中。所以 :

//This query is not valid since you are neither passing a string nor a variable
$query1 ="INSERT INTO 'booking' VALUES (name2, tel_no2, email2, city2, country2, car,         date, query2)";

所以这应该用这样的单引号括起来(从字面上传递name2,tel_no2等):

$query1 ="INSERT INTO 'booking' VALUES ('name2', 'tel_no2', 'email2', 'city2', 'country2', 'car', 'date', 'query2')";

或者您可以像这样传递变量的值:

$query2 ="INSERT INTO 'booking' VALUES ('$name2', '$tel_no2', '$email2', '$city2',     '$country2', '$car', '$date', '$query2')"; 
于 2013-06-14T06:50:07.160 回答