dongliufa6380 2015-06-03 08:02
浏览 35

使用userform输入Database PHP连接[关闭]

I'm trying to enter a username into a text field and click submit then this should connect me to my database. A) What is wrong with the code below:

    .error {color: #FF0000;}


// define variables and set to empty values
$nameErr = $emailErr = "";

    if (empty($_POST["login"]))
        $nameErr = "login is required";
        $login = test_input($_POST["login"]);

        // check if login only contains letters and whitespace
       if (!preg_match("/^[a-zA-Z ]*$/",$login))
           $nameErr = "Only letters and white space allowed"; 

function test_input($data)
   $data = trim($data);
   $data = stripslashes($data);
   $data = htmlspecialchars($data);
   return $data;

<h2>Edge User Login</h2>
<p><span class="error">* required field.</span></p>

<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> 

Login: <input type="text" name="name">
       <span class="error">* <?php echo $nameErr;?></span>
       <input type="submit" name="submit" value="Submit"> 


    $mysqli_connection = new MySQLi('localhost', $login, 'secret', 'edgeserver');

    if ($mysqli_connection->connect_error)
        echo "Not connected, error: " . $mysqli_connection->connect_error;


B) I dont want the user to have to enter a username everytime they run a PHP command. Is there a way of using a master sheet that can be referred back to?

  • 写回答

1条回答 默认 最新

  • duanke1286 2015-06-03 08:17

    A.) You probably don't want your users to connect to MySql through your server

    These should be YOUR login details from MySql, typically you create a user in MySql (maybe phpmyadmin?) and fill the details in here:

    $mysqli_connection = new MySQLi('localhost', $login, 'secret', 'edgeserver');

    Then you would select from a table you create that holds your users.

    B.) You can store user-names in sessions, but that's getting complicated, and I’d recommend you get it working where you just login first.

    Possibly this ( I just googled it ) might help you.

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



    • ¥15 三维直角坐标系下,给定一个平面内四个点坐标,如何将四个点逆时针排序
    • ¥15 UnityWebRequest访问内网地址502
    • ¥20 Python语言来实现牛顿法(Newton's Method)解决非线性(系统)方程的问题。
    • ¥15 matlab控制工业相机采集图像
    • ¥25 R里做折线图和柱状图
    • ¥20 使用kokkos移植项目,遇到问题
    • ¥15 求该问题的Matlab代码
    • ¥15 python下使用pdpbox为何提示has no attribute 'pdp_isolate'?
    • ¥15 求java web病房管理系统项目,用netbeans做的
    • ¥15 python图片画不出来