第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

PHP:將值從窗體插入MySQL

PHP:將值從窗體插入MySQL

GCT1015 2019-09-24 15:29:03
我從終端創(chuàng)建了一個(gè)users表,mysql然后嘗試創(chuàng)建簡(jiǎn)單的任務(wù):從表單中插入值。這是我的dbConfig file<?php$mysqli = new mysqli("localhost", "root", "pass", "testDB");/* check connection */if (mysqli_connect_errno()) {    printf("Connect failed: %s\n", mysqli_connect_error());    exit();}?>這是我的Index.php。<!doctype html><html> <head>    <meta charset="utf-8">    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">    <meta name="description" content="$1">    <meta name="viewport" content="width=device-width, initial-scale=1">    <link rel="stylesheet" type="text/css" href="style.css">    <title>test</title>    <?php    include_once 'dbConfig.php';    ?></head><body>     <?php    if(isset($_POST['save'])){        $sql = "INSERT INTO users (username, password, email)        VALUES ('".$_POST["username"]."','".$_POST["password"]."','".$_POST["email"]."')";    }    ?>    <form method="post">     <label id="first"> First name:</label><br/>    <input type="text" name="username"><br/>    <label id="first">Password</label><br/>    <input type="password" name="password"><br/>    <label id="first">Email</label><br/>    <input type="text" name="email"><br/>    <button type="submit" name="save">save</button>    <button type="submit" name="get">get</button>    </form></body></html>按下我的保存按鈕后,什么也沒(méi)有發(fā)生,數(shù)據(jù)庫(kù)仍然為空。我嘗試echo'ing了INSERT查詢(xún),當(dāng)它被認(rèn)為它從形式的所有值。在嘗試從終端檢查是否可以正常工作后,我登錄到sql嘗試從用戶表返回所有數(shù)據(jù)的操作,但得到了空集。
查看完整描述

3 回答

?
侃侃無(wú)極

TA貢獻(xiàn)2051條經(jīng)驗(yàn) 獲得超10個(gè)贊

您的代碼中有兩個(gè)問(wèn)題。


表單中找不到任何動(dòng)作。

您尚未執(zhí)行查詢(xún)mysqli_query()

dbConfig.php


<?php


$conn=mysqli_connect("localhost","root","password","testDB");


if(!$conn)

{

die("Connection failed: " . mysqli_connect_error());

}


?>

的index.php


 include('dbConfig.php');


<!Doctype html>

<html>

<head>

<meta charset="utf-8">

<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

<meta name="description" content="$1">

<meta name="viewport" content="width=device-width, initial-scale=1">


<link rel="stylesheet" type="text/css" href="style.css">


<title>test</title>



</head>

<body>


 <?php


  if(isset($_POST['save']))

{

    $sql = "INSERT INTO users (username, password, email)

    VALUES ('".$_POST["username"]."','".$_POST["password"]."','".$_POST["email"]."')";


    $result = mysqli_query($conn,$sql);

}


?>


<form action="index.php" method="post"> 

<label id="first"> First name:</label><br/>

<input type="text" name="username"><br/>


<label id="first">Password</label><br/>

<input type="password" name="password"><br/>


<label id="first">Email</label><br/>

<input type="text" name="email"><br/>


<button type="submit" name="save">save</button>


</form>


</body>

</html>


查看完整回答
反對(duì) 回復(fù) 2019-09-24
?
慕尼黑8549860

TA貢獻(xiàn)1818條經(jīng)驗(yàn) 獲得超11個(gè)贊

嘗試這個(gè):


dbConfig.php


<?php

$mysqli = new mysqli('localhost', 'root', 'pwd', 'yr db name');

    if($mysqli->connect_error)

        {

        echo $mysqli->connect_error;

        }

    ?>

的index.php


<html>

<head><title>Inserting data in database table </title>

</head>

<body>

<form action="control_table.php" method="post">

<table border="1" background="red" align="center">

<tr>

<td>Login Name</td>

<td><input type="text" name="txtname" /></td>

</tr>

<br>

<tr>

<td>Password</td>

<td><input type="text" name="txtpwd" /></td>

</tr>

<tr>

<td>&nbsp;</td>

<td><input type="submit" name="txtbutton" value="SUBMIT" /></td>

</tr>

</table>

control_table.php

<?php include 'config.php'; ?>

<?php

$name=$pwd="";

    if(isset($_POST['txtbutton']))

        {

            $name = $_POST['txtname'];

            $pwd = $_POST['txtpwd'];

            $mysqli->query("insert into users(name,pwd) values('$name', '$pwd')");

        if(!$mysqli) 

        { echo mysqli_error(); }

    else

    {

        echo "Successfully Inserted <br />";

        echo "<a href='show.php'>View Result</a>";

    }


         }  


    ?>


查看完整回答
反對(duì) 回復(fù) 2019-09-24
  • 3 回答
  • 0 關(guān)注
  • 612 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)