"The submission of multiple forms does not properly update the MySQL database

I've encountered an issue with my function and first query working correctly but the second involves multiple form inputs like id[], urunad, birim... I'm using $_POST to pass data to the function.

$id2 = $gid;
$sid2 = $sid; 
$urunad2 = $urunad;
$birim2 = $birim;
$adet2 = $adet;
$fiyat2 = $fiyat;
$kdvsiztoplam2 = $kdvsiztoplam; 
I need help identifying what the problem could be.

public function updateData($kasano,$gid,$sturu,$firmaid,$firmaadi,$vergid,$vergin,$adres,$telefon,$email,$sid,$urunad,$birim,$adet,$fiyat,$kdvsiztoplam,$kdv,$aratoplam,$geneltoplam,$kdvtutar,$kdvdahil,$tarih)
{
$query = this->db->prepare("update siparis set kasano = ? ,sturu = ? ,firmaid = ? ,firmaadi = ? ,vergid = ? ,vergin = ? ,adres = ? ,telefon = ? ,email = ? ,kdv = ? ,aratoplam = ? ,geneltoplam = ? ,kdvtutar = ? ,kdvdahil = ? ,tarih = ?");
$update = query->execute(array($kasano,$sturu,$firmaid,$firmaadi,$vergid,$vergin,$adres,$telefon,$email,$kdv,$aratoplam,$geneltoplam,$kdvtutar,$kdvdahil,$tarih));
return $update;

$id2 = $gid;
$sid2 = $sid;   
$urunad2 = $urunad;
$birim2 = $birim;
$adet2 = $adet;
$fiyat2 = $fiyat;
$kdvsiztoplam2 = $kdvsiztoplam; 

for($i=0;$i<count($id2);$i++)
{
$query = this->db->prepare("update surunler set id = ? ,sid = ?,urunad = ? ,birim = ? ,adet = ? ,fiyat = ? ,kdvsiztoplam = ? ");
$update = $query->execute(array($id2[$i],$sid2[$i],$urunad2[$i],$birim2[$i],$adet2[$i],$fiyat2[$i],$kdvsiztoplam2[$i]));
return $update;
}

}

Answer №1

Once "return" is typed in PHP, the function will abruptly end and control will be passed back to the calling function.

As a result, any code written after the initial return statement will not execute.

It's important to note that within a for loop, using return does not solely affect the loop itself as it might in other programming languages; rather, it terminates the entire function and returns control to the caller.

Answer №2

Thank you for your assistance. Below is the working code that may be helpful to someone in need:

public function updateData($kasano,$gid,$sturu,$firmaid,$firmaadi,$vergid,$vergin,$adres,$telefon,$email,$sid,$urunad,$birim,$adet,$fiyat,$kdvsiztoplam,$kdv,$aratoplam,$geneltoplam,$kdvtutar,$kdvdahil,$tarih)
{
        $query = $this->db->prepare("update siparis set kasano = ? ,sturu = ? ,firmaid = ? ,firmaadi = ? ,vergid = ? ,vergin = ? ,adres = ? ,telefon = ? ,email = ? ,kdv = ? ,aratoplam = ? ,geneltoplam = ? ,kdvtutar = ? ,kdvdahil = ? ,tarih = ?");
        $update = $query->execute(array($kasano,$sturu,$firmaid,$firmaadi,$vergid,$vergin,$adres,$telefon,$email,$kdv,$aratoplam,$geneltoplam,$kdvtutar,$kdvdahil,$tarih));

        $id2 = $gid;
        $sid2 = $sid;   
        $urunad2 = $urunad;
        $birim2 = $birim;
        $adet2 = $adet;
        $fiyat2 = $fiyat;
        $kdvsiztoplam2 = $kdvsiztoplam; 

    for($i=0;$i<count($id2);$i++)
    {
        $query = $this->db->prepare("update surunler set sid = ?,urunad = ? ,birim = ? ,adet = ? ,fiyat = ? ,kdvsiztoplam = ? where id = ?");
        $update = $query->execute(array($sid2[$i],$urunad2[$i],$birim2[$i],$adet2[$i],$fiyat2[$i],$kdvsiztoplam2[$i],$id2[$i]));
    }
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Accessing form data from Ajax/Jquery in php using $_POST variables

Thank you in advance for any assistance on this matter. I'm currently attempting to utilize Ajax to call a script and simultaneously post form data. While everything seems to be working correctly, the $POST data appears to come back blank when trying ...

Searching in sequelize for a specific date using a clause

Operating System: Linux (Lubuntu) Programming Language: Javascript (Node js) Framework: express js Database: mysql "data" represents a Date field from the "activitat" table Upon running this query using Sequelize.js models.TblActivitat.findAll( ...

Accessing PHP output within Jquery

Even though I know PHP is a server-side script and JavaScript is client-side, I encountered an issue. I struggled to bypass browser security when making an AJAX request to another domain. Feeling lost, I decided to turn to PHP for help. The challenge I f ...

What is the process for sharing your website content on Google Blogger?

I am currently developing a dashboard for a small business website and I would like to implement a feature that allows users to post directly to their Blogger blog from the dashboard of their own website. This eliminates the hassle of having to switch betw ...

Adding parameters to a URL is a common practice

"Adding additional information to a URL that was previously included?" I apologize for the confusing title, but I can't find a better way to phrase it. Perhaps an example will make things clearer. Let's say I have URL 1: http://example.com/?v ...

utilize jQuery to load webpage with an HTML dropdown element

Querying the Campaigns: // Getting the campaigns $campaigns = $wpdb->get_results( "SELECT * FROM tbl_campaigns ORDER BY campaignID DESC", OBJECT_K ); // Displaying the Cam ...

Deleting an element from HTML using jQuery

In the midst of creating a system that allows users to construct their own navigation structure, I have encountered a stumbling block. The idea is that when a user lands on the site, they are presented with a list of available topics from which they can ch ...

Using jQuery to dynamically insert a table row with JSON data into dropdown menus

I'm working on a web form that includes a table where users can add rows. The first row of the table has dependent dropdowns populated with JSON data from an external file. Check out the code snippet below: // Function to add a new row $(function(){ ...

Exploring SQL Components with JavaScript

Here is the code I am currently using: //This function handles all games and their attributes function handleGames(){ sql.query('SELECT id FROM games', function (err, rows){ if(err){ console.log(String(err).error.bgWhite) ...

Please include the document with a name that contains spaces

I am facing an issue where I cannot attach files with spaces in the name. However, when a file with no space in the name is successfully attached. I am using CodeIgniter for this purpose, uploading the file to the server before attaching it. I use the help ...

Failing to send contact information using JSON in PHP

I attempted to transmit JSON data to PHP for email processing, but encountered an issue where the process veered into the 'else' condition during debugging. Here is the code snippet: HTML <form id="cbp-mc-form" class="cbp-mc-form" method="po ...

Mastering Yii2: Implementing Javascript Functions such as onchange() in a View

One of the elements in my project is a checkbox: <div class="checkbox"> <label> <?= Html::checkbox('chocolate', false) ?> Chocolate </label> </div> In addition to that, I also have a span ta ...

Retrieving Information from Ajax Response Following a Successful Insert Query in Codeigniter

I am trying to use ajax method to insert form data into a database and then redirect it to the next page. I have successfully passed the data in ajax and inserted it into the database table. However, I am facing an issue with getting the generated referenc ...

Melodic Streaming Platform

I currently have a client-side application built using React. I have a collection of music stored on my Google Drive that I would like to stream online continuously. I lack experience in server-side programming. Can you suggest any resources or steps I s ...

Utilizing JSON for Google Charts

Although I have no prior experience with Google Charts, I am currently attempting to graph temperature data collected from sensors placed around my house. Unfortunately, I keep encountering an Exception error. I suspect the issue lies in the JSON format no ...

Is there a way I can obtain the code for a message box?

When I refer to a message box, I am talking about a container that gives users the ability to input their text and access different features like BOLD, ITALIC, color, justify, etc., in order to customize their message's appearance! (Think of it as the ...

Guide on automatically attaching a file to an input file type field from a database

Currently, I am implementing a PHP file attachment feature to upload files. Upon successful upload, the system stores the filename with its respective extension in the database. The issue arises when trying to retrieve and display all entries from the ...

Sophisticated web applications with Ajax functionalities and intricate layouts powered by MVC frameworks

I am looking to integrate an ajax-driven RIA frontend, utilizing JQuery layout plugin (http://layout.jquery-dev.net/demos/complex.html) or ExtJs (http://www.extjs.com/deploy/dev/examples/layout/complex.html), with... a PHP MVC backend, potentially using ...

Since switching to PHP 5.5 from version 3.x, I have noticed that it is attempting to interpret my JavaScript comment within a script tag in a PHP include file

After a long break from working with PHP, I recently encountered an issue with an older website I built using PHP and the include function. The site was functioning perfectly until the web host updated PHP to version 5.5, causing a strange bug where it see ...

Convert text into a clickable link

Creating a form with numerous text fields, some of which require numerical input. The main goal is to have users enter a tracking number, order number, or any other type of number that, when submitted, will open a new URL in a separate window with the spec ...