dongtuota3633 2015-06-23 09:00
浏览 74
已采纳

使用php将数据输入mysql数据库

Customer will complete a form and enter a pathway where they will want the CSV to be exported to. The pathway is entered using the top section of the php (below):

    <form action="register.php" method="post">
        Enter file pathway where CSV will be saved: <input type="text" name="username" required="required"/> <br/>
        <input type="submit" value="Enter"/>
    </form>
</body>

I want to create a variable called pathway. At the moment I can get text entered into the correct row in the mysql database (I can get John printed in the database), but not the correct text that was entered into the form (i.e. $pathway). I want to create a variable because after saving the pathway in the database i also want to use it in an export.php.

I am assuming i also need something like this:

if($_SERVER["REQUEST_METHOD"] == "POST"){
    $pathway = mysql_real_escape_string($_POST['pathway']); 
// but i can't seem to piece it altogether.


    <?php
    $servername = "localhost";
    $username = "";
    $password = "";
    $dbname = "first_db";
    $table_users = $row['pathway'];
    $pathway = "pathway";                                             

    // Create connection
    $conn = mysqli_connect($servername, $username, $password, $dbname);
    // Check connection
    if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
    }

    $sql = "INSERT INTO users (pathway)
    VALUES ('John')";

    if (mysqli_query($conn, $sql)) {
    echo "New record created successfully";
    } else {
    echo "Error: " . $sql . "<br>" . mysqli_error($conn);
    }

    mysqli_close($conn);
    ?>
  • 写回答

4条回答 默认 最新

  • dpn4073 2015-06-23 09:15
    关注

    This shoud work, if not then check your usename and password...

    <?php
    $servername = "localhost";
    $username = "";
    $password = "";
    $dbname = "first_db";
    $pathway = $_POST['username'];  username - is the name of your input.                                             
    
    // Create connection
    $conn = mysqli_connect($servername, $username, $password, $dbname);
    // Check connection
    if (!$conn)
    {
        die("Connection failed: " . mysqli_connect_error());
    }
    
    $sql = "INSERT INTO users (pathway)
        VALUES ('$pathway')";
    
    if (mysqli_query($conn, $sql)) {
        echo "New record created successfully";
    }
    else
    {
    echo "Error: " . $sql . "<br>" . mysqli_error($conn);
    }
    
    mysqli_close($conn);
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退
  • ¥20 win系统的PYQT程序生成的数据如何放入云服务器阿里云window版?