Jump to content

Connection between HTML table and MySql database


Recommended Posts

I always get the following warnings and i have no idea why.

    Warning: Undefined array key "username" in C:\xampp\htdocs\Kulinarik\save_order.php on line 2

    Warning: Undefined array key "item" in C:\xampp\htdocs\Kulinarik\save_order.php on line 3

    Warning: Undefined array key "quantity" in C:\xampp\htdocs\Kulinarik\save_order.php on line 4

    Fatal error: Uncaught Error: Call to a member function bind_param() on bool in C:\xampp\htdocs\Kulinarik\save_order.php:13 Stack trace: #0 {main} thrown in C:\xampp\htdocs\Kulinarik\save_order.php on line 13

Here comes the code that belongs to the errors


                  <table class="u-table-entity" src="jquery.js" action="save_order.php" method="POST">

                    <script scr="calculation.js"></script>
                      <col width="20%">
                      <col width="2.1%">
                      <col width="22%">
                      <col width="21.7%">
                      <col width="34.2%">
                    <tbody class="u-table-alt-grey-5 u-table-body">
                      <tr style="height: 55px;">
                        <th class="u-table-cell u-table-cell-1"><b>Produkt</b><span style="font-weight: 700;"></span>
                        <th class="u-table-cell"></th>
                        <th class="u-table-cell u-table-cell-3"><b>Einzelpreis</b></th>
                        <th class="u-table-cell u-table-cell-4"><b>Menge</b></th>
                        <th class="u-table-cell u-table-cell-5"><b>Gesamtpreis</b></th>

                      <tr style="height: 55px;">
                        <td class="u-table-cell">
                          <input name="item" value="Kornspitz"></input>
                        <td class="u-table-cell"></td>
                        <td class="u-table-cell">
                          <input type="text" class="price" value="11.39" readonly/>
                        <td class="u-table-cell">
                          <input type="text" class="quantity"/> 
                        <td class="u-table-cell">
                          <input type="text" class="total" readonly/>

        <a href="save_order.php" class="u-border-none u-btn u-button-style u-custom-color-1 u-btn-2" type="submit">Bestellen<br>


	$username = $_POST['username'];
	$item = $_POST['item'];
	$quantity = $_POST['quantity'];

	// Database connection
	$conn = new mysqli('localhost','root','123456','orders');
		echo "$conn->connect_error";
		die("Connection Failed : ". $conn->connect_error);
	} else {
		$stmt = $conn->prepare("insert into orders(username, item, quantity) values(?, ?, ?)");
		$stmt->bind_param("sssssi", $username, $item, $quantity);
		$execval = $stmt->execute();
		echo $execval;
		echo "Bestellung Erfolgreich";


Edited by Setzi138
Link to comment
Share on other sites

Quite.  Perhaps you need to go back to reading up on how to write html?

For the heck of it here's a sample of what a form could look like.  Note the things that are different from what you produced.

//  producing an html form from php
//  this form will produce 3 POST entries: fld1, fld2 and btn
	<form method='POST' action='(this script's name)' autocomplete=off>
	<label>Enter this data item:
	<input type='text' name='fld1' class='sz_10' value='$fld1'>
	<label>Enter this data also:
	<input type='text' name='fld2' class='sz_6' value='$fld2'>
	<input type='submit' name='btn' value='Submit'>
	echo $code;

This utilizes PHP's heredocs verb to produce easy-to-write and easy-to-read html while in php mode.  It also references a couple of css classes to help set the size of the input fields.  Read up on css and avoid the antiquated use of styles on your input tags.  Note the use of label tags.  And note the use of var names in the value clauses of the inputs.  These can be used to send back the user's input when your script needs to report an error and you don't want the user to have to re-type their inputs when you send the form back to them.

A lot to learn which will benefit you immensely if you simply try and follow it.  Along with a reference manual.

Edited by ginerjm
Link to comment
Share on other sites

Join the conversation

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

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.