0

I'm new to PHP and mySQL, and I'm trying to make a simple form that posts into my DB. The connection (via connect.php) works and I can add data manually via PHP.

Here's the code I've written so far (without the basic html, body, etc. tags):


enterinfo.php

<?php
    include "..\htdocs\connect.php";
?>

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

<table border="0">


<tr>
    <td>ID</td>
    <td align="center"><input type="integer" name="ID" size="30" /></td>
</tr>

<tr>
    <td>Firstname</td>
    <td align="center"><input type="text" name="Firstname" size="30" /></td>
</tr>

<tr>
    <td>Lastname</td>
    <td align="center"><input type="text" name="Lastname" size="30" /></td>
</tr>

<tr>
    <td>ZIPCODE</td>
    <td align="center"><input type="text" name="ZIPCODE" size="30" /></td>
</tr>

<tr>
    <td colspan="2" align="center"><input type="submit" value="Submit" /></td>
</tr>

</table>

datarecorded.php

<?php
    include "..\htdocs\connect.php";

    $id = $_POST['ID'];
    $firstname = $_POST['Firstname'];
    $lastname = $_POST['Lastname'];
    $zip = $_POST['ZIPCODE'];


    $query = "INSERT INTO employees (ID, Firstname, Lastname, ZIPCODE)
                VALUES ($id, $firstname, $lastname, $zip)";

    $result = mysqli_query($myConnection, $query);

    echo $query;
 ?>

I also don't know if I have to include connect.php in both files. The echo in datarecord.php correctly displays what I entered in enterinfo.php - but the data doesn't go into the actual Database.

Any help would be greatly appreciated!

cholz
  • 83
  • 2
  • 12

0 Answers0