dsiftnc99059 2014-07-29 02:52
浏览 88
已采纳

来自注册表的信息不会提交到phpmyadmin的表格中

I do not know why it won't connect I have no ideas. When I try to connect it also tells me it's successfully connected to the mysql its weird please help.

It's been annoying the crap out of me and I really need it to work soon because it is driving me nuts.

<?

if(!empty($_POST['username']) && !empty($_POST['password']))
{
    $username = mysql_real_escape_string($_POST['username']);
    $password = md5(mysql_real_escape_string($_POST['password']));
    $email = mysql_real_escape_string($_POST['email']);

    $checkusername = mysql_query("SELECT * FROM users WHERE Username = '".$username."'");

    if(mysql_num_rows($checkusername) == 1)
    {
        echo "<h1>Error</h1>";
        echo "<p>Sorry, that username is taken. Please go back and try again.</p>";
        $checkemail = mysql_query("SELECT * FROM users WHERE email = '".$email."'");

        if(mysql_num_rows($checkemail) == 1)
        {
           echo "<h1>Error</h1>";
           echo "<p>Sorry, that email is taken. Please go back and try again.</p>";
        }
        }
        else
        {
           $registerquery = mysql_query("INSERT INTO users (Username, Password, EmailAddress) VALUES('".$username."', '".$password."', '".$email."')");
           if($registerquery)
           {
               echo "<h1>Success</h1>";
               echo "<p>Your account was successfully created. Please <a href=\"login.php\">click here to login</a>.</p>";
           }
           else
           {
               echo "<h1>Error</h1>";
               echo "<p>Sorry, your registration failed. Please go back and try again.</p>";    
           }       
       }
    }
    else
    {
?>

<h1>Register</h1>

<p>Please enter your details below to register.</p>

    <form method="post" action="register.php" name="registerform" id="registerform">
    <fieldset>
        <label for="username">Username:</label><input type="text" name="username"     id="username" /><br />
        <label for="password">Password:</label><input type="password" name="password"     id="password" /><br />
        <label for="email">Email Address:</label><input type="text" name="email" id="email"    /><br />
        <input type="submit" name="register" id="register" value="Register" />
    </fieldset>
    </form>

    <?php
    }
    ?>

Mysql Connected Successfully

Warning: mysql_real_escape_string(): Access denied for user 'UNKNOWN_USER'@'localhost' (using password: NO) in /home/parap00per/public_html/register.php on line 28
Warning: mysql_real_escape_string(): A link to the server could not be established in /home/parap00per/public_html/register.php on line 28
Warning: mysql_real_escape_string(): Access denied for user 'UNKNOWN_USER'@'localhost' (using password: NO) in /home/parap00per/public_html/register.php on line 29
Warning: mysql_real_escape_string(): A link to the server could not be established in /home/parap00per/public_html/register.php on line 29
Warning: mysql_real_escape_string(): Access denied for user 'UNKNOWN_USER'@'localhost' (using password: NO) in /home/parap00per/public_html/register.php on line 30
Warning: mysql_real_escape_string(): A link to the server could not be established in /home/parap00per/public_html/register.php on line 30
Warning: mysql_query(): Access denied for user 'UNKNOWN_USER'@'localhost' (using password: NO) in /home/parap00per/public_html/register.php on line 32
Warning: mysql_query(): A link to the server could not be established in /home/parap00per/public_html/register.php on line 32
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /home/parap00per/public_html/register.php on line 34
Warning: mysql_query(): Access denied for user 'UNKNOWN_USER'@'localhost' (using password: NO) in /home/parap00per/public_html/register.php on line 48
Warning: mysql_query(): A link to the server could not be established in /home/parap00per/public_html/register.php on line 48
Error

Sorry, your registration failed. Please go back and try again.
  • 写回答

1条回答 默认 最新

  • doy51723 2014-07-29 03:21
    关注

    You're not selecting a database with mysql_select_db().
    (as per your original posted code which was edited).

    Replace the xxx with your own information.

    $host="localhost"; // Host name.
    $db_user="xxx"; // MySQL username.
    $db_password="xxx"; // MySQL password.
    $database="xxx"; // Database name.
    
    $link = mysql_connect($host,$db_user,$db_password);
    if (!$link) {
        die('Not connected : ' . mysql_error());
    }
    
    $db_selected = mysql_select_db($database, $link);
    if (!$db_selected) {
        die ('Can\'t use the DB : ' . mysql_error());
    }
    

    You're also closing your connection prematurely using mysql_close($link); place it after you've finished querying, or don't use it at all. Your connection will close anyway once it's finished executing.

    Edit:

    I noticed you're using EmailAddress and email as column names. One of them or others may not be correct.


    Add error reporting to the top of your file(s) which will help during production testing.

    error_reporting(E_ALL);
    ini_set('display_errors', 1);
    

    Also, use mysqli_* with prepared statements, or PDO with prepared statements.


    Footnotes:

    mysql_* functions deprecation notice:

    http://www.php.net/manual/en/intro.mysql.php

    This extension is deprecated as of PHP 5.5.0, and is not recommended for writing new code as it will be removed in the future. Instead, either the mysqli or PDO_MySQL extension should be used. See also the MySQL API Overview for further help while choosing a MySQL API.

    These functions allow you to access MySQL database servers. More information about MySQL can be found at » http://www.mysql.com/.

    Documentation for MySQL can be found at » http://dev.mysql.com/doc/.

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

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法