我正在尝试使用类和函数将信息插入到我的表中。
我不知道为什么,但我的功能不起作用。虽然它识别我的数据库,但是当我提交表单时它会给出错误消息。
我需要改变什么?
这是我的表单页面代码:
<?php
include("BDMySQL.class.php");
?>
<html>
<head>
<title>Registo</title>
<link rel="stylesheet" href="css/style.css" type="text/css"/>
</head>
<body>
<span id="background"></span>
<div id="page">
<div id="sidebar">
<div id="logo">
<a href="index.html">Apenas as melhores da <em>BlastingBeats Rec.</em></a>
</div>
<ul id="navigation">
<li><a href="Index.html">Home</a></li>
<li class="selected"><a href="login.html">Login</a></li>
<li><a href="registo.html">Registar</a></li>
</ul>
<ul id="connect">
<li><a href="http://facebook.com/freewebsitetemplates" target="_blank" class="facebook"></a></li>
<li><a href="http://twitter.com/fwtemplates" target="_blank" class="twitter"></a></li>
<li><a href="" class="link-us"></a></li>
</ul>
<div class="footer">
© Copyright © 2011.<br/>
<a href="index.html">Company name</a> all rights reserved.
</div>
</div>
<div id="contents">
<ul class="images">
<?php
if($_POST['Nome']=="") {
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"><p>
Nome de Utilizador:<p>
<input type="text" name="Nome"></input><p>
Palavra-Passe:<p>
<input type="text" name="Pass"></input><p>
<input type="submit" class="button"><p>
</form>
<?php
}
else {
?>
<?php
include("Cliente.class.php");
$Cliente = new Cliente();
if($Cliente->introduzirCliente($_REQUEST['Nome'], $_REQUEST['Pass'])) {
echo "Registo efectuado com sucesso !!!<br>";
} else {
echo "Problema encontado no Registo !!!<br>";
echo mysql_errno() . "\n";
}
$Cliente->endCliente();
}
?>
</ul>
</div>
</div>
</body>
</html>
我的功能代码:
function introduzirCliente($Nome, $Pass) {
$sql = "INSERT INTO clientes VALUES ('$Nome' , '$Pass')";
if($this->bd->executarSQL($sql)) return true;
else return false;
}
答案 0 :(得分:1)
我将假设您在clientes数据库表中只有两个字段。因此,您需要更改sql行:
$sql = "INSERT INTO clientes VALUES ('$Nome' , '$Pass')";
类似于:
$sql = "INSERT INTO clientes (username, password) VALUES ('$Nome','$Pass')";
您可以在正确的字段名称中替换用户名和密码。