Jump to content

Insert into row with a form


omardavinci

Recommended Posts

Hi sorry but i tried to use of many ways and i use prepare etc, But i cant create one without vars. But when i use one form and check the post method to save this new row. It is empty. Code:

<?php
 
require_once 'database.php';
$database_connection = database_connect();
 
$users = $database_connection->query('SELECT * FROM coffee')->fetchAll();
$title = 'Home';
$content = '
<h4>Title 1</h4>
<form method="POST">
<table>
<tr>
    <td><input type="number" name="fname" required placeholder="First Name"></td>
 
</tr>
<tr>
    <td><input type="text" name="lname" required placeholder="Last Name"></td>
 
</tr>
<tr>
     <td><input type="text" name="age" required placeholder="Age" min="10" > </td>
 
</tr>
<tr>
    <td><input type="submit" name="insert"></input></td>
</br>
</tr>
</form></table>
<br>
';
$content .=  '<br><table>';
if(isset($_POST['submit']) == "insert")
{
 
 
// get values form input text and number
    $fname = $_POST['fname'];
    $lname = $_POST['lname'];
    $age = $_POST['age'];
 
$uso = $database_connection->query('INSERT INTO coffee (id) VALUES (:fname)');
 
 
}else{
    echo "nothing";
}
 
 
foreach($users as $user) {
 
    $content .= '<tr>';
    $content .= '<td>' . $user["id"] . '</td>';
    $content .= '<td>' . $user["type"] . '</td>';
    $content .= '<td>' . $user["price"] . '</td>';
    $content .= '<td><a href="index.php">' . $user["price"] . '<a/></td>';
    $content .= '<td><a href="index.php">' . $user["price"] . '<a/></td>';
    $content .= '</tr>';
}
 
 
$content .=  '</table>';
 
include 'Template.php';
?>

 

I am trying to do easy things. Like insert,update,delete,search but with a form.

 

Link to comment
Share on other sites

In an earlier post on this forum (http://forums.phpfreaks.com/topic/302132-page-php-how-include-input-and-type-to-search-in-my-table/?do=findComment&comment=15372780) you had

 

INSERT INTO `coffee` (`id`, `name`, `type`, `price`, `roast`, `country`, `image`, `review`) VALUES
(1, 'Cafe au Lait', 'Classic', 2.25, 'Medium', 'France', 'Images/Coffee/Cafe-Au-Lait.jpg', 'A coffee beverage consisting strong or bold coffee (sometimes espresso) mixed with scalded milk in approximately a 1:1 ratio.'')')

 

So why are you using the `coffee` table with a form for entering firstname, lastname and age? Or are all your tables named `coffee`?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.