Saving Dynamically Generated PHP Calculations to A MySQL Database - php

I have a page with with the following php code:
<?php
include ('dbconnect.php');
// get values from the form
function getPosts()
{
$posts = array();
$posts[0] = $_POST['bookingid'];
$posts[1] = $_POST['bookingname'];
$posts[2] = $_POST['cabintype'];
$posts[3] = $_POST['lengthofstay'];
$posts[4] = $_POST['guests_description'];
$posts[5] = $_POST['startdate'];
$posts[6] = $_POST['enddate'];
$posts[7] = $_POST['other_information'];
return $posts;
}
if (isset($_POST['bookingdetails'])) {
$data = getPosts();
$insert_Query = "insert into bookings(Bookingid,Bookingname,Cabin_Type,
lengthofstay,Details_about_guests,Booking_start_date,Booking_end_date,
Other_relavant_information)
values ('$data[0]','$data[1]','$data[2]','$data[3]','$data[4]','$data[5]',
'$data[6]','$data[7]')";
$result = mysqli_query($db, $insert_Query);
if ($result){
echo "<p>Total price is \$$total</p>\n";
Booked</p> </font>";
}else{
echo "<p> Something went Wrong! Contact Your Administrator </p>" .
mysqli_error ($db);
}
}
$Luxury_Cabin= 1200;
$Contemporary_Cabin= 1000;
$Original_Cabin= 800;
$Total= "";
if(isset($_POST['bookingdetails']) && $_POST['luxurycabin']=='1')
{
$num=(int)$_POST['lengthofstay'];
if($num>=0)
{
$Total=($Luxury_Cabin*$num);
}
}
if(isset($_POST['bookingdetails']) && $_POST['contemporarycabin']=='2')
{
$num=(int)$_POST['lengthofstay'];
if($num>=0)
{
$Total=($Contemporary_Cabin*$num);
}
}
if(isset($_POST['bookingdetails']) && $_POST['originalcabin']=='4')
{
$num=(int)$_POST['lengthofstay'];
if($num>=0)
{
$Total=($Original_Cabin*$num);
}
}
echo "<p>Total price is \$$total</p>\n";
?>
And the HTML Code is like the following:
<form method = "post" action = "" >
<tr>
<th>Bookingid </th>
<td><input type = "text" name = "bookingid" /> </td>
</tr>
<tr>
<th>Booking Name </th>
<td><input type = "text" name = "bookingname" /> </td>
</tr>
<tr>
<th>Cabin Type </th>
<td><input type = "text" name = "cabintype" /> </td>
</tr>
<tr>
<th>Luxury Cabin</th>
<td><input type="radio" name="luxurycabin" value="1" />Yes</td>
<td><input type="radio" name="luxurycabin" value="0"
checked="checked"/>No</td>
</tr>
<tr>
<th>Contemporary Cabin</th>
<td><input type="radio" name="contemporarycabin" value="2" />Yes</td>
<td><input type="radio" name="contemporarycabin" value="3"
checked="checked"/>No</td>
</tr>
<tr>
<th>Original Cabin</th>
<td><input type="radio" name="originalcabin" value="4" />Yes</td>
<td><input type="radio" name="originalcabin" value="5"
checked="checked"/>No</td>
</tr>
<tr>
<th>Length of Stay </th>
<td><input type = "text" name = "lengthofstay" id="lengthofstay"/> </td>
</tr>
<tr>
<th>Details About Guests </th>
<td><textarea cols = "30" rows = "5" type = "text" name
="guests_description" /></textarea> </td>
</tr>
<tr>
<th>Booking Start Date </th>
<td><input type = "text" name = "startdate" /> </td>
</tr>
<tr>
<th>Booking End Date </th>
<td><input type = "text" name = "enddate" /> </td>
</tr>
<tr>
<th>Other Relavant Information </th>
<td><textarea cols = "30" rows = "5" type = "text" name
="other_information" /></textarea> </td>
</tr>
<tr>
<th> </th>
<td> <input type = "submit" value = "Create Booking!" name =
"bookingdetails" /> </td>
</tr>
</table>
</form>
What occurs here is that when the "bookingdetails" button is pressed all of the data entered into the form are sent to the database. What is also done is a multiplication calculation which uses the radio buttons and the number entered into the lenghtofstay field. The result is then echoed on the page itself using:
<?php echo "<p>Total price is \£$total</p>\n"; ?>
So what I need your assistance with is how do I get the dynamically generated calculation result into my database table with a column called Booking_Price?

Just swap your code around so all the calculation stuff happens before the database insert and then you have your value to insert in $total. Modify your insert query to include it.

Related

Mysqli/PHP/HTML duplicate insert records when using mysqli_insert_id to pull recently autogenerated ID's

I currently Have this code for inserting into my receipt table,
$query = "insert into receipt(petname,receipttype)
values('$petname','$receipttype')";
in which i obtain the autogenerated id
$receiptid=mysqli_insert_id($db);
and send it to the next page. however when the record is inserted, another is also generated (Two of the same content but another auto-generated ID, is entered into the database)
http://prntscr.com/kpjff6 [example of duplicate fields with unique ids]
if (isset($_POST['cmdedit'])){
$petname = mysqli_real_escape_string($db,$_POST['petname']);
$receipttype = mysqli_real_escape_string($db,$_POST['receipttype']);
$query = "insert into receipt(petname,receipttype)
values('$petname','$receipttype')";
$result = mysqli_query($db,$query);
if (mysqli_query($db,$query)){
$receiptid=mysqli_insert_id($db);
if ($result) {
echo "<font color = 'green' > Receipt sucessfully obtained! Page will auto-redirect to order confirmation page in 5 seconds! </font>";
header( "refresh:5; url=addorderhomepage.php?animalid=".$animalid."&receiptid=".$receiptid);
}else{
echo "<p>Something went wrong! </p>" . mysqli_error($db);
}
}
}
?>
<div class = "topbar">
<h2> Order Receipt </h2>
</div>
<?php
$query = "select *
from catalogue
where animalid= " . $animalid;
$result = mysqli_query($db,$query);
if ($result){
while ($rows = mysqli_fetch_array($result))
{
?>
<form method = "post" action = "" >
<table>
<tr>
<th> Animal ID</th>
<td bgcolor="#FFFFFF"> <input type ="text" name = "txtanimalid" value = "<?php echo $rows[0]; ?>" readonly /> </td>
</tr>
<tr>
<th> Animal Name </th>
<td> <input type ="text" name = "petname" value = "<?php echo $rows[1]; ?>" readonly /> </td>
</tr>
<tr>
<th> Animal Type </th>
<td> <input type ="text" name = "petname" value = "<?php echo $rows[3]; ?>" readonly /> </td>
</tr>
<tr>
<th> Animal Species </th>
<td> <input type ="text" name = "petname" value = "<?php echo $rows[2]; ?>" readonly /> </td>
</tr>
<tr>
<th> Animal Description </th>
<td> <input type ="text" name = "petname" value = "<?php echo $rows[4]; ?>" readonly /> </td>
</tr>
<tr>
<th> Receipt type </th>
<td> <input type ="text" name = "receipttype" value = "printable" readonly /> </td>
</tr>
<tr>
<th> Receipt Date </th>
<td> <input type ="date" name = "orderdate" value="<?php echo date('Y-m-j'); ?>" readonly="readonly" </td>
</tr>
<tr>
<th> <br/><br/> </th>
<td> </td>
</tr>
<tr>
<th> </th>
<td> <input type ="submit" value = "Obtain receipt" name = "cmdedit" /> </td>
</tr>
The duplicate row are probably happen because you are calling 2 time the mysqli_query with the same data, the first time when storing the response in the $result var and the second time inside the condition in the if statement.
// ... code
$result = mysqli_query($db,$query);
- if (mysqli_query($db,$query)) {
+ if ($result) {
$receiptid = mysqli_insert_id($db);
if ($result) {
// .. rest of the code

Assigning & Calculating Values Using PHP via an HTML Form

I am new to programming and I am in need of of assistance. I have a HTML form on a page called addbooking.php with the following code:
<form method = "post" action = "" >
<table cellspacing="15">
<tr>
<th>Bookingid </th>
<td><input type = "text" name = "bookingid"/> </td>
</tr>
<tr>
<th>Booking Name </th>
<td><input type = "text" name = "bookingname" /> </td>
</tr>
<tr>
<th> <label for = "Cabin Type">Cabin Type </label> </th>
td><select name = "Cabin Type" id = "Cabin Type">
<option select>Select a Cabin Type</option>
<option value = "Luxury Cabin">Luxury Cabin </option>
<option value = "Contemporary Cabin">Contemporary Cabin </option>
<option value = "Original Cabin">Original Cabin </option>
</select>
</td>
</tr>
<tr>
<th>Length of Stay </th>
<td><input type = "text" name = "lengthofstay" /> </td>
</tr>
<tr>
<th>Details About Guests </th>
<td><textarea cols = "30" rows = "5" type = "text" name="guests_description"
/> </textarea> </td>
</tr>
<tr>
<th>Booking Start Date </th>
<td><input type = "text" name = "startdate" /> </td>
</tr>
<tr>
<th>Booking End Date </th>
<td><input type = "text" name = "enddate" /> </td>
</tr>
<tr>
<th>Other Relavant Information </th>
<td><textarea cols = "30" rows = "5" type = "text" name="other_information"
/> </textarea> </td>
</tr>
<tr>
<th> </th>
<td> <input type = "submit" value = "Create Booking!" name =
"bookingdetails" /> </td>
</tr>
</table>
</form>
I also have php code on the same page which looks like the following:
<?php
include ('dbconnect.php');
// get values from the form
function getPosts(){
$posts = array();
$posts[0] = $_POST['bookingid'];
$posts[1] = $_POST['bookingname'];
$posts[2] = $_POST['lengthofstay'];
$posts[3] = $_POST['guests_description'];
$posts[4] = $_POST['startdate'];
$posts[5] = $_POST['enddate'];
$posts[6] = $_POST['other_information'];
return $posts;
}
if (isset($_POST['bookingdetails'])) {
$data = getPosts();
if (empty($bookingname)){
$errors[] = "Please enter the your booking name.";
}
if(empty($errors)){
foreach($errors as $error){
echo $error . "<br/>";
}
else{
$insert_Query = "insert into bookings
(Bookingid,Bookingname,Lengthofstay,Details_about_guests,
Booking_start_date,Booking_end_date,Other_relavant_information)
values ('$data[0]','$data[1]','$data[2]','$data[3]','$data[4]',
'$data[5]','$data[6]')";
$result = mysqli_query($db, $insert_Query);
if ($result)
{
echo "<font color = 'green' . <p>Successfully Booked</p> </font>";
}
else{
echo "<p> Something went Wrong </p>" . mysqli_error ($db);
}
}
}
?>
I also have a table in my database called cabins which looks like:
Now, what I need some assistance with is how do I assign each of the prices from the Cabin_Price column to each item in the drop down menu on the form and then when the "booking details" button is pressed multiply the chosen value/option for e.g '1200' by what ever value is entered in the 'Length of Stay' field for e.g '4' using php. Below is a picture of what I mean:
Change your menu so that the values of the options are the cabin ID. Then when you're processing the form, you look up the price, and multiply by the length of stay. So the menu should look like:
<select name = "Cabin Type" id = "Cabin Type">
<option select>Select a Cabin Type</option>
<option value = "1">Luxury Cabin </option>
<option value = "2">Contemporary Cabin </option>
<option value = "3">Original Cabin </option>
</select>
And when the form is submitted, you do a query like:
$stmt = $dbh->prepare("SELECT cabin_price FROM cabins WHERE cabin_id = :id");
$stmt->bindParam(":id", $_POST["Cabin Type"]);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$price = $row['cabin_price'];
$total_price = $price * $_POST['lengthofstay'];

How Can I Insert Data Into Database From A Form Properly?

so I've been working on a form using an MVC approach that will insert data into a database using PDO. I have the addWine form, addWine controller, data access model and wine class model. On submission of the form nothing happens and the database isn't populated. Can someone pinpoint what I have done wrong here?
Wine Form
<form action= "" method="POST">
<table>
<b>Fill the form to add new wine</b><p><p>
<tr>
<td> Wine ID: </td>
<td><input type="text" name= "wineID"/></td>
</tr>
<tr>
<td>Wine Country ID: </td>
<td><input type="text" name="wineCountryID"/></td>
</tr>
<tr>
<td>Wine Size ID: </td>
<td><input type="text" name="wineSizeID"/></td>
</tr>
<tr>
<td>Wine Rating ID: </td>
<td><input type="text" name="wineRatingID"/></td>
</tr>
<tr>
<td>Wine Colour ID: </td>
<td><input type="text" name="wineColourID"/></td>
</tr>
<tr>
<td>Wine Package ID: </td>
<td><input type="text" name="winePackageID"/></td>
</tr>
<tr>
<td>Wine Category ID: </td>
<td><input type="text" name="wineCategoryID"/></td>
</tr>
<tr>
<td>Wine Code: </td>
<td><input type="text" name="wineCode"/></td>
</tr>
<tr>
<td>Wine Price: </td>
<td><input type="text" name="wineCountryID"/></td>
</tr>
<tr>
<td>Wine Description: </td>
<td><input type="text" name="wineDescription"/></td>
</tr>
<tr>
<td>Wine Rating: </td>
<td><input type="text" name="wineRating"/></td>
</tr>
<tr>
<td>Wine Image: </td>
<td><input type="text" name="wineImage"/></td>
</tr>
</table><p><br>
<center><input type="submit" name= "addWineButton" value="Add Wine"></center><p><p><p><p>
</form>
Add Wine Controller
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
session_start();
require_once('../Model/dataAccess.php');
require_once('../Model/wine.class.php');
$status = false;
if(isset($_POST["addWineButton"])){
$wineID = $_POST["wineID"];
$wineCountryID = $_POST["wineCountryID"];
$wineSizeID = $_POST["wineSizeID"];
$wineRatingID = $_POST["wineRatingID"];
$wineColourID = $_POST["wineColourID"];
$packageID = $_POST["packageID"];
$wineCategoryID = $_POST["wineCategoryID"];
$wineCode = $_POST["wineCode"];
$price = $_POST["price"];
$description = $_POST["description"];
$wineRating = $_POST["wineRating"];
$wineIMG = $_POST["wineIMG"];
$wineAdd = new Wine();
$wineAdd->wineID = htmlentities($wineID);
$wineAdd->wineCountryID = htmlentities($wineCountryID);
$wineAdd->wineSizeID = htmlentities($wineSizeID);
$wineAdd->wineRatingID = htmlentities($wineRatingID);
$wineAdd->wineColourID = htmlentities($wineColourID);
$wineAdd->packageID = htmlentities($packageID);
$wineAdd->wineCategoryID = htmlentities($wineCategoryID);
$wineAdd->wineCode = htmlentities($wineCode);
$wineAdd->price = htmlentities($price);
$wineAdd->description = htmlentities($description);
$wineAdd->wineRating = htmlentities($wineRating);
$wineAdd->wineIMG = htmlentities($wineIMG);
addWine($wineAdd);
$status = "$description has been updated.";
}
?>
Wine Class Model
<?php
class Wine {
var $wineID;
var $wineSizeID;
var $wineCountryID;
var $wineRatingID;
var $wineColourID;
var $wineCode;
var $price;
var $description;
var $wineRating;
var $wineIMG;
var $packageID;
var $wineCategoryID;
function __get($name){
return $this->$name;
}
function __set($name,$value){
$this->$name=$value;
}
}
?>
Data Access Model
function addWine($wineAdd){
global $pdo;
$statement = $pdo->prepare('INSERT INTO Wine
(wineID, wineCountryID, wineSizeID, wineRatingID, wineColourID, packageID,
wineCategoryID, wineCode, price, description, wineRating, wineIMG) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)');
$statement->execute([$wineAdd->wineID,
$wineAdd->wineCountryID,
$wineAdd->wineSizeID,
$wineAdd->wineRatingID,
$wineAdd->wineColourID,
$wineAdd->packageID,
$wineAdd->wineCategoryID,
$wineAdd->wineCode,
$wineAdd->price,
$wineAdd->description,
$wineAdd->wineRating,
$wineAdd->wineIMG]);
$statement->fetch();
}
The code is working now. I've updated the original post to reflect the changes. Thanks everyone for all the help.

How to have dropdown data WHERE we get from other table for the editing data

I want to have the same drop down Hardware_ID in Adding new record form WHERE I get the data from another table for my Update form.
This is the example for my Update (Edit) form.
Update Form
And this is my Adding new record form.
Adding new record Form
this is my code for Update Form. Im using the same code like my adding new record but I got an error(The error is in the Update Form).
<?php
//get the data
$Asset_ID = $_GET['Asset_ID'];
$Hardware_ID = $_GET['Hardware_ID'];
$Vendor_ID = $_GET['Vendor_ID'];
$PO_ID = $_GET['PO_ID'];
?>
<form action = 'Update_Asset2_Process.php' method = 'POST'>
<table border = '1' align = 'center' cellspacing='0' cellpadding='10'
bgcolor = "White">
<tr>
<th colspan = '2'>ASSET UPDATE FORM</th>
</tr>
<tr>
<td align='center'>Asset ID :</td>
<td><input type = "varchar" name = "Asset_ID" value = "<?php echo
$Asset_ID; ?>" readonly></td>
</tr>
<tr>
<td align='center'> Hardware ID: </td>
<td><input type = "varchar" name = "Hardware_ID" value = "<?php echo
$Hardware_ID?>">
<?php
$query = "SELECT * FROM hardware2 ORDER BY Hardware_ID";
$result = mysql_query($query);
if(mysql_num_rows($result))
{
while ($id = mysql_fetch_row($result))
{
echo "<option value='" . $id[0] . "'>" . $id[0] . " : " .
$id[1] . " </option>";
}
}
?>
</select>
</tr>
<tr>
<td align='center'>Vendor ID :</td>
<td><input type = "varchar" name = "Vendor_ID" value = "<?php echo
$Vendor_ID; ?>"></td>
</tr>
<tr>
<td align='center'>PO ID :</td>
<td><input type = "varchar" name = "PO_ID" value = "<?php echo $PO_ID; ?
>"></td>
</td>
</tr>
<tr>
<td colspan = '2' align = 'right'>
<input type = 'submit' name = 'submit' value = 'UPDATE'>
</td>
</tr>
Back to Asset
</table>
</form>
thanks for your help, Regards
Wrong select box syntax
<?php
//get the data
$Asset_ID = isset($_GET['Asset_ID']) ? $_GET['Asset_ID'] : 0;
$Hardware_ID = isset($_GET['Hardware_ID']) ? $_GET['Hardware_ID'] : 0;
$Vendor_ID = isset($_GET['Vendor_ID']) ? $_GET['Vendor_ID'] : 0;
$PO_ID = isset($_GET['PO_ID']) ? $_GET['PO_ID'] : 0;
?>
<form action = 'Update_Asset2_Process.php' method = 'POST'>
<table border = '1' align = 'center' cellspacing='0' cellpadding='10' bgcolor = "White">
<tr>
<th colspan = '2'>ASSET UPDATE FORM</th>
</tr>
<tr>
<td align='center'>Asset ID :</td>
<td><input type = "varchar" name = "Asset_ID" value = "<?php echo $Asset_ID; ?>" readonly></td>
</tr>
<tr>
<td align='center'> Hardware ID: </td>
<td><input type = "varchar" name = "Hardware_ID" value = "<?php echo $Hardware_ID?>">
<select id="Your_id" name="Your_name">
<?php
$query = "SELECT * FROM hardware2 ORDER BY Hardware_ID";
$result = mysql_query($query);
if(mysql_num_rows($result))
{
while ($id = mysql_fetch_row($result))
{
echo "<option value='".$id[0]."'>".$id[0]." : ".$id[1]."</option>";
}
}
?>
</select>
</tr>
<tr>
<td align='center'>Vendor ID :</td>
<td><input type = "varchar" name = "Vendor_ID" value = "<?php echo $Vendor_ID; ?>" /></td>
</tr>
<tr>
<td align='center'>PO ID :</td>
<td><input type = "varchar" name = "PO_ID" value = "<?php echo $PO_ID; ?>" /></td>
</td>
</tr>
<tr>
<td colspan = '2' align = 'right'>
<input type = 'submit' name = 'submit' value = 'UPDATE'>
</td>
</tr>
Back to Asset
</table>
</form>
Maybe no need the select box in this form
<?php
//get the data
$Asset_ID = isset($_GET['Asset_ID']) ? $_GET['Asset_ID'] : 0;
$Hardware_ID = isset($_GET['Hardware_ID']) ? $_GET['Hardware_ID'] : 0;
$Vendor_ID = isset($_GET['Vendor_ID']) ? $_GET['Vendor_ID'] : 0;
$PO_ID = isset($_GET['PO_ID']) ? $_GET['PO_ID'] : 0;
?>
<form action = 'Update_Asset2_Process.php' method = 'POST'>
<table border = '1' align = 'center' cellspacing='0' cellpadding='10' bgcolor = "White">
<tr>
<th colspan = '2'>ASSET UPDATE FORM</th>
</tr>
<tr>
<td align='center'>Asset ID :</td>
<td><input type = "varchar" name = "Asset_ID" value = "<?php echo $Asset_ID; ?>" readonly></td>
</tr>
<tr>
<td align='center'> Hardware ID: </td>
<td><input type = "varchar" name = "Hardware_ID" value = "<?php echo $Hardware_ID?>">
</tr>
<tr>
<td align='center'>Vendor ID :</td>
<td><input type = "varchar" name = "Vendor_ID" value = "<?php echo $Vendor_ID; ?>" /></td>
</tr>
<tr>
<td align='center'>PO ID :</td>
<td><input type = "varchar" name = "PO_ID" value = "<?php echo $PO_ID; ?>" /></td>
</td>
</tr>
<tr>
<td colspan = '2' align = 'right'>
<input type = 'submit' name = 'submit' value = 'UPDATE'>
</td>
</tr>
Back to Asset
</table>
</form>

PHP Arrays from HTML Forms to UPDATE MySQL

I've got a page showing the contents of my DB in form inputboxes like this:
<?php
while($row = mysql_fetch_array($result))
{
$namn = $row['namn'];
$mandag = $row['mandag'];
$tisdag = $row['tisdag'];
$onsdag = $row['onsdag'];
$torsdag = $row['torsdag'];
$fredag = $row['fredag'];
?>
<td width="100"></td>
<td><?=$namn?><input name="namn[]" type="hidden" value="<?=$namn?>"></td>
</tr>
<tr>
<td width="100">Mandag</td>
<td><input name="mandag[]" type="text" value="<?=$mandag?>"></td>
</tr>
<tr>
<td width="100">Tisdag</td>
<td><input name="tisdag[]" type="text" value="<?=$tisdag?>"></td>
</tr>
<tr>
<td width="100">Onsdag</td>
<td><input name="onsdag[]" type="text" value="<?=$onsdag?>"></td>
</tr>
<tr>
<td width="100">Torsdag</td>
<td><input name="torsdag[]" type="text" value="<?=$torsdag?>"></td>
</tr>
<tr>
<td width="100">Fredag</td>
<td><input name="fredag[]" type="text" value="<?=$fredag?>"></td>
</tr>
<?php } ?>
<tr>
<td width="100"> </td>
<td> </td>
</tr>
<tr>
<td width="100"> </td>
<td>
<input name="update" type="submit" id="update" value="Update">
</td>
</tr>
</table>
</form>
After this I've added code to able to update the different DB entries by changing the content of the inputboxes and pressing the submit button:
<?php
if(isset($_POST['update']))
{
$namnValue = $_POST['namn'];
$mandagValue = $_POST['mandag'];
$tisdagValue = $_POST['tisdag'];
$onsdagValue = $_POST['onsdag'];
$torsdagValue = $_POST['torsdag'];
$fredagValue = $_POST['fredag'];
print_r($mandagValue);
$sql = "UPDATE anstalld SET mandag = '$mandagValue', tisdag = '$tisdagValue', onsdag = '$onsdagValue', torsdag = '$torsdagValue', fredag = '$fredagValue' WHERE namn = '$namnValue'";
echo $sql;
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not update data: ' . mysql_error());
}
echo "Updated data successfully\n";
}
mysql_close($conn);
?>
The DB is being updated, however, the problem is that all my
$namnValue = $_POST['namn'];
$mandagValue = $_POST['mandag'];
$tisdagValue = $_POST['tisdag'];
$onsdagValue = $_POST['onsdag'];
$torsdagValue = $_POST['torsdag'];
$fredagValue = $_POST['fredag'];
are returning the result "Array", an not the actual Values from the inputboxes.
Therefore my SQL UPDATE ends up being
"UPDATE anstalld SET mandag = 'Array', tisdag = 'Array', onsdag =
'Array', torsdag = 'Array', fredag = 'Array' WHERE namn = 'Array'"
I'll appreciate any help I can get on this, thanks.
You need to delete [] on our input names:
<td><input name="onsdag" type="text" value="<?=$onsdag?>"></td>
instead of
<td><input name="onsdag[]" type="text" value="<?=$onsdag?>"></td>
^^
Otherwise they are considered as arrays.
Because of the name of your input fields
<input name="onsdag[]" type="text" value="<?=$onsdag?>">
you are sending arrays and not single values.
Change the names as the previous answer suggests
<input name="onsdag" type="text" value="<?=$onsdag?>">
or access them as arrays
$namnValue = $_POST['namn'][0];
$mandagValue = $_POST['mandag'][0];
...

Categories