dongli4711 2013-12-11 18:14
浏览 50
已采纳

PHP - 为什么我不能在表格中插入信息?

I'm trying to insert information into my table using classes and functions.

I don't know why, but my function doesn't work. Although it recognizes my database, it's giving an error message when I submit the form.

What do I need to change?

Here's my form page code:

<?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">
                &copy; Copyright &copy; 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() . "
";
                            }
                        $Cliente->endCliente();


}
?>


            </ul>
        </div> 
    </div> 
</body>
</html>

My function code:

function introduzirCliente($Nome, $Pass) {


            $sql = "INSERT INTO clientes VALUES ('$Nome' , '$Pass')";
            if($this->bd->executarSQL($sql)) return true;
            else return false;
        }
  • 写回答

1条回答 默认 最新

  • dongxiao9583 2013-12-11 18:29
    关注

    I'm going to assume that you have more than just two fields in the clientes database table. As such, you need to change the sql line from:

    $sql = "INSERT INTO clientes VALUES ('$Nome' , '$Pass')";
    

    to something like:

    $sql = "INSERT INTO clientes (username, password) VALUES ('$Nome','$Pass')";
    

    where you substitute in the correct field name for username and password.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP