Connecting PHP source code and submit form to MySQL Database

后端 未结 4 2038
北海茫月
北海茫月 2021-01-06 04:08

I\'m trying to learn PHP and I\'m trying to connect a MySQL database with my PHP code to make a submit form that lets me input data into the database. My problem is that the

相关标签:
4条回答
  • 2021-01-06 04:18

    Try the following:

    <?php
    
    $user_name = "fees0_14446440";
    $password = "********";
    $database = "fees0_14446440_addressbook";
    $server = "sql107.0fees.net";
    
    mysql_connect("$server","$user_name","$password");
    
    mysql_select_db("$database");
    
    if (isset($_POST['submit'])) {
    $name = $_POST['name'];
    $address = $_POST['address'];
    
    $order = mysql_query("INSERT INTO Trial (name, address) VALUES ('$name', '$address')");
    
    if ($order) {
        echo '<br>Input data is successful';
    } else {
        echo '<br>Input data is not valid';
    }
    }
    ?>
    
    0 讨论(0)
  • 2021-01-06 04:19

    You can find the POST data in PHP's $_POST variable. It should hold all the values that were passed via the POST method.

    $name = $_POST["name"];

    0 讨论(0)
  • 2021-01-06 04:25

    put POST values into variable

    $name=$_POST['name'];
    $address=$_POST['address'];
    

    before sql query and write sql query as

    $order = "INSERT INTO Trial

        (name, address)
    
        VALUES
    
        ('".$name."',
    
        '".$address."')";
    
    0 讨论(0)
  • 2021-01-06 04:37

    Try this

    <html>
    
    <head>
    <title>Form Input Data</title>
    </head>
    
    <body>
    <form action="input.php" method="POST">
    <table border="1">
      <tr>
        <td align="center">Form Input Employees Data</td>
      </tr>
      <tr>
      <td>
      <table>
    
        <tr>
          <td>Name</td>
          <td><input type="text" name="name" size="20">
          </td>
        </tr>
        <tr>
          <td>Address</td>
          <td><input type="text" name="address" size="40">
          </td>
        </tr>
        <tr>
          <td></td>
          <td align="right"><input type="submit" 
          name="submit" value="Sent"></td>
        </tr>
        </table>
      </td>
    </tr>
    </table>
    </form>
    

    In PHP code

    $order = "INSERT INTO Trial
    
            (name, address)
    
            VALUES
    
            ('$_POST["name"]',
    
            '$_POST["address"]')";
    
    0 讨论(0)
提交回复
热议问题