使用PHP $ variable进行MySQL INSERT INTO [英] MySQL INSERT INTO with PHP $variable

查看:83
本文介绍了使用PHP $ variable进行MySQL INSERT INTO的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在$strSQL = "SELECT * FROM $person";中使用 $ variable 但是我不能在$sql = "INSERT INTO $person . . .

I can use $variable there $strSQL = "SELECT * FROM $person"; But I can't use $variable there $sql = "INSERT INTO $person . . .

`$person` 

也不要工作...

有什么区别?以及如何使用$ variable代替表名(INSERT INTO table_name )

What the difference? And how I can use $variable instead of name of the table (INSERT INTO table_name)

$sql = 'INSERT INTO $person (date, min, sec, count, temp, universal)
    VALUES("'.$date.'", "'.$min.'", "'.$sec.'", "'.$count.'", "'.$temp.'", "'.$universal.'")';
    if(!mysql_query($sql))
    {echo '<center><p><b>ERROR!</b></p></center>';}
    else
    {echo '<center><p><b>Its okay</b></p></center>';}
        }

解决:

mysql_query("INSERT INTO $person (date, min, sec, count, temp, universal) VALUES('$date', '$min', '$sec', '$count', '$temp', '$universal')") or die(mysql_error());

推荐答案

您可以这样使用

mysql_query("INSERT INTO `$person` VALUES(...) ")
or die(mysql_error());

您关闭了if和else错误

You have closed the if and else wrong

请尝试一下

$sql = 'INSERT INTO `name`(date, min, sec, count, temp, universal)
        VALUES("'.$date.'", "'.$min.'", "'.$sec.'", "'.$count.'", "'.$temp.'", "'.$universal.'")';

$sql = 'INSERT INTO $person (date, min, sec, count, temp, universal)
    VALUES("'.$date.'", "'.$min.'", "'.$sec.'", "'.$count.'", "'.$temp.'", "'.$universal.'")';
    if(!mysql_query($sql)) {
    echo '<center><p><b>ERROR!</b></p></center>';
    }else{ 
    echo '<center><p><b>Its okay</b></p></center>';
    }
    }// so where this comes from ?

这篇关于使用PHP $ variable进行MySQL INSERT INTO的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆