[kwlug-disc] OT: PHP help

Charles M chaslinux at gmail.com
Mon Jul 9 14:08:39 EDT 2018


Hi all. I'm working on a PHP application to track the following items
(database name is: cr_inc and table name is cr_incoming):

inv_key : Primary key : auto_incremented
date_donated : CURDATE
barcode : varchar(40)
item_type : enum('field1','field2','etc')
donor_name : varchar(60)
donor_location : varchar(40)

I've set up the database and tables in mysql and can successfully see
them in mysql using:

select * from cr_incoming;

I can also see the inserted data from a php script I wrote, but I'm
having problems actually inserting the data from a form (all that
happens is I enter the fields and it just refreshes, I've checked the
database and data isn't getting entered):

<!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
 include('dbConfig.php');

  if(isset($_POST['save']))
{
    $sql = "INSERT INTO cr_incoming (date_donated, barcode, item_type,
donor_name, donor_location)
    VALUES ('$CURDATE()','".$_POST["barcode"]."','".$_POST["item_type"]."','".$_POST["donor_name"]."','".$_POST["donor_location"]."')";

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

?>

<form action="index.php" method="post">
<label id="barcode"> Barcode:</label><br/>
<input type="text" name="barcode"><br/>

<label id="item_type">Item Type:</label><br/>
<input type="text" name="item_type"><br/>

<label id="donor_name">Name: </label><br/>
<input type="text" name="donor_name"><br/>

<label id="donor_location">Location: </label><br/>
<input type="text" name="donor_location"><br/>

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

</form>

</body>
</html>

The file dbConfig.php is in the same folder as the index.php file and
looks like this:

<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "cr_inc";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
?>

I know it isn't the username and password since I have a select script
that shows the test data I've already entered into the database
through the mysql interface. In the script that I looked at they had
the include at the top of the file outside the <?php> tag, but that
shows on the display and didn't look correct. Think I've munged
something at the $curdate area.

I'm not a programmer, just trying to hack together a simple DB for us
to use mostly offline.

Thanks,

Charles




More information about the kwlug-disc mailing list