Php 使用面向对象编程将值插入数据库
可能重复:Php 使用面向对象编程将值插入数据库,php,Php,可能重复: 我无法将这些值插入数据库。但是,我也没有收到任何错误消息 <html> <body> <form action="database.php" method="post"> Name : <input type ="text" name = "name"/> Number :<input type ="text" name = "number"/> <input type ="submit" value = "sub
我无法将这些值插入数据库。但是,我也没有收到任何错误消息
<html>
<body>
<form action="database.php" method="post">
Name : <input type ="text" name = "name"/>
Number :<input type ="text" name = "number"/>
<input type ="submit" value = "submit"/>
</form>
</body>
</html>
姓名:
编号:
database.php
<?php
class Database
{
var $host;
var $user;
var $pass;
var $data;
var $con;
var $table;
var $db;
public function controls()
{
$this->host="localhost";
$this->user="cgiadmin";
$this->pass="cgi";
$this->data="j2";
}
public function connection()
{
$this->con="mysql_connect($this->host,$this->user,$this->pass)";
}
public function tablename()
{
$this->table="Insert into employee(name,number) values('$_POST[name]','$_POST[number]')";
}
public function databaseconnection()
{
$this->db="mysql_select_db($this->data,$this->con)";
}
}
$name=new Database;
$name->connection();
if(!($name->con))
{
echo "'Error: ' . mysql_error()";
}
$name->databaseconnection();
$name->tablename();
echo "thanks for taking the survey";
?>
你需要一些魔法:)阅读php
你需要一些魔法:)阅读php
试试这个
Modify tablename()函数
public function tablename($nam,$num)
{
$this->table=mysql_query("INSERT INTO employee(name,number) VALUES ('$nam','$num')");
}
获取值并调用tablename()函数
试试这个
Modify tablename()函数
public function tablename($nam,$num)
{
$this->table=mysql_query("INSERT INTO employee(name,number) VALUES ('$nam','$num')");
}
获取值并调用tablename()函数
为什么要将所有函数调用存储在字符串中?不要通过@k102构建SQL,我应该在代码中的何处插入该查询?请help@Blender我不熟悉这种语言。因此发现很难处理它:(@krish为了使它工作,我应该做什么更改?为什么要将所有函数调用存储在字符串中?不要通过@k102构建SQL我应该在代码中的何处插入该查询?请help@Blender我不熟悉这门语言,所以觉得很难处理它:(@krish我应该做什么更改才能使其正常工作神圣的SQL注入漏洞,蝙蝠侠!@Ruben Nagoga我收到一条错误消息。这是我的数据库有问题吗?错误消息是:警告:mysql_connect()[function.mysql connect]:用户“www data”@“localhost”的访问被拒绝(使用密码:否)第20行的/home/jnagesh/public_html/SampleSurvey/MVC/database.php中出现错误:用户“www data”@“localhost”(使用密码:否)的访问被拒绝警告:mysql_select_db():第28行的/home/jnagesh/public_html/SampleSurvey/MVC/database.php中提供的参数不是有效的mysql链接资源警告:mysql_query()[function.mysql query]:第24行/home/jnagesh/public_html/SampleSurvey/MVC/database.php中用户“www-data”@“localhost”(使用密码:否)的访问被拒绝警告:mysql_query()[function.mysql query]:无法在第24行的/home/jnagesh/public_html/SampleSurvey/MVC/database.php中建立到服务器的链接,感谢您的调查这是程序中的问题还是数据库中的错误?@MichaelBorgwardt您能帮我更正错误Holy SQL注入漏洞吗,蝙蝠侠!@Ruben Nagoga我收到一条错误消息。我的数据库有问题吗?错误消息是:警告:mysql_connect()[function.mysql connect]:在/home/jnagesh/public_html/SampleSurvey/MVC/database.php第20行拒绝用户“www data”@“localhost”(使用密码:否)访问警告:mysql_select_db():第28行的/home/jnagesh/public_html/SampleSurvey/MVC/database.php中提供的参数不是有效的MySQL链接资源警告:MySQL_query()[function.MySQL query]:第24行的/home/jnagesh/public_html/SampleSurvey/MVC/database.php中的用户“www data”@“localhost”(使用密码:NO)的访问被拒绝警告:MySQL_query()[function.mysql query]:无法在第24行的/home/jnagesh/public_html/SampleSurvey/MVC/database.php中建立到服务器的链接。感谢您进行调查。这是程序中的问题还是数据库中的错误?@MichaelBorgwardt您能帮我更正错误吗
$name=new Database;
$name->connection();
if(!($name->con))
{
echo "'Error: ' . mysql_error()";
}
$name->databaseconnection();
$nam=$_POST[name];
$num=$_POST[number];
$name->tablename($nam,$num);
echo "thanks for taking the survey";