I get an error like this;
Notice: Undefined offset: 0 on line 93
My php code is look like this below code..
$i=0;
while ($ww=mysqli_fetch_array($query))
{
if ($i%2==0)
$class="evenRow";
else
$class="oddRow";
$id=$ww[0];
$studentid=$ww[1];
$name=$ww[2];
$kelompok=$ww[8];
$block=$ww[9];
$level=$ww[10];
$house=$ww[11];
$status=$ww[14];
echo "<tr>
<input type=hidden name=applyid[] value=".$id."/>
<td>$studentid</td>
<td>$name</td>
<td>$kelompok</td>
<td>$block</a></td>
<td>$level</td>
<td>$house</td>
<td>
<input type=checkbox name=status approved checked> APPROVED <br>
</td>
</tr>";
}
$i++;
echo "</table>";
This is the error on line 93: $checkbox[] .= $_POST['applyid'][$i];}
And the SQL Query to update the status is look like this...
<?php
include("connection.php");
$checkbox = array();
if(isset($_POST['applyid']))
{
$check = count($_POST['applyid']);
for($i=0;$i<$check;$i++){
$checkbox[] .= $_POST['applyid'][$i];}
$check = "('" . implode( "','", $checkbox ) . "');" ;
$sql="UPDATE application SET apply_status = 'APPROVED' WHERE apply_id IN $check" ;
$result = mysqli_query($con, $sql) or die(mysqli_error($con));
}
?>
I want to update multiple row selected by checkbox. This is the table output
Click Here
..............................................................................
VIEW THE PENDING STATUS:
This is my code if only the apply_status = 'PENDING' will only view.
I add the if else statement... but is not working. if there is several apply_status = approved. It will not showed the pending one. But if there is no apply_status = aprroved. It will view all the application.
<?php
include("connection.php");
$sql="SELECT * FROM application";
$record = mysqli_query($con, $sql) or die ("error".mysqli_error($con));
$apply = mysqli_fetch_assoc($record);
$status1 = $apply["apply_status"];
if ($status1 == "APPROVED") {
echo "<br>";
echo "No application from student yet.<br>";
echo "<br>";
} else {
echo "<table border='1'><tr>
<td><strong>Student ID</strong></td>
<td><strong>Student Name</strong></td>
<td><strong>Kelompok</strong></td>
<td><strong>Block</strong></td>
<td><strong>Level</strong></td>
<td><strong>House</strong></td>
<td><strong>Status</strong></td>
</tr>";
$i=0;
while ($ww=mysqli_fetch_array($query))
{
if ($i%2==0)
$class="evenRow";
else
$class="oddRow";
$id=$ww[0];
$studentid=$ww[1];
$name=$ww[2];
$kelompok=$ww[8];
$block=$ww[9];
$level=$ww[10];
$house=$ww[11];
$status=$ww[14];
echo '<tr>
<input type="hidden" name="applyid['.$i.']" value="'.$id.'"/>
<td>'.$studentid.'</td>
<td>'.$name.'</td>
<td>'.$kelompok.'</td>
<td>'.$block.'</a></td>
<td>'.$level.'</td>
<td>'.$house.'</td>
<td>
<input type="checkbox" name="status['.$i.']" value="approved" checked> APPROVED <br>
</td>
</tr>';
$i++;
}
echo '</table>';
}
?>
Try changing :
$check = count($_POST['applyid']);
for($i=0;$i<$check;$i++){
$checkbox[] .= $_POST['applyid'][$i];
}
TO
foreach($_POST['applyid'] as $index=>$idValue){
$checkbox[] .= $idValue;
}
EDIT :
use the index of the loop to index the input's so that you can associate them with each other in the receiving page :
$i = 0; // $i used to determain if it is odd or even, also used as the index in the html inputs
// comments are your friend
while ($ww=mysqli_fetch_array($query))
{
if ($i%2==0){ // best practice for readable code is to use the braces
$class="evenRow";
}
else{
$class="oddRow";
}
// easier to read when spaced equally
$id = $ww[0];
$studentid = $ww[1];
$name = $ww[2];
$kelompok = $ww[8];
$block = $ww[9];
$level = $ww[10];
$house = $ww[11];
$status = $ww[14];
// single quotes are faster to proccess in PHP
// use $i to force the array index
// place quotation marks arrount html attribute values
echo '<tr>
<input type="hidden" name="applyid['.$i.']" value="'.$id.'"/>
<td>'.$studentid.'</td>
<td>'.$name.'</td>
<td>'.$kelompok.'</td>
<td>'.$block.'</td> <!-- removed a closing "a" tag, as it wasn\'t closeing anything -->
<td>'.$level.'</td>
<td>'.$house.'</td>
<td>
<input type="checkbox" name="status['.$i.']" value="approved" checked> APPROVED <br>
</td>
</tr>';
$i++; // increment $i inside the loop, else it will never change until the loop is completed
}
// single quotes are faster to proccess in PHP
echo '</table>';
On the recieving page, use this,
include("connection.php");
if(isset($_POST['applyid']))
{
$allIDs = ''; // using this in the single SQL query, remove it if you not going to use it
$approvedIds = ''; // we will add all the approved Ids here for using in the SQL query
$unapprovedIds = ''; // we will add all the un-approved Ids here for using in the SQL query
// if the single SQL query works, remove the $unapprovedIds
foreach($_POST['applyid'] as $index=>$idValue){
if(isset($_POST['status'][$index])){ // if the status for this ID was posted, it was selected ( ony selected checkboxes get posted )
$approvedIds .= ($approvedIds === '' ? '' : ', ').$idValue; // we add it to the string that will be used in the "IN"
// if $approvedIds is not blank, add a comma to format corrctly for SQL
}else{ // if the single SQL query works, remove this entire else
$unapprovedIds .= ($unapprovedIds === '' ? '' : ', ').$idValue; // we add it to the string that will be used in the "IN"
// if $unapprovedIds is not blank, add a comma to format corrctly for SQL
}
$allIDs .= ($allIDs === '' ? '' : ', ').$idValue; // using this in the single SQL query, remove it if you not going to use it
}
// update all the approved ones
// single quotes
// format you SQL in a easy to read way
$sql = 'UPDATE application
SET apply_status = \'APPROVED\'
WHERE apply_id IN ('.$approvedIds.')' ;
$result = mysqli_query($con, $sql) or die(mysqli_error($con));
// update all the unaproved ones
// format you SQL in a easy to read way
$sql = 'UPDATE application
SET apply_status = \'UNAPROVED\'
WHERE apply_id IN ('.$unapprovedIds.')' ;
$result = mysqli_query($con, $sql) or die(mysqli_error($con));
/////////////////
//
// worth a try as a single query UNTESTED :
//
//////////////////////////////////////////////
$sql='UPDATE application
SET apply_status =
CASE WHEN apply_id IN ('.$approvedIds.') THEN \'APPROVED\'
ELSE \'UNAPPROVED\'
END
WHERE apply_id IN ('.$allIDs.')';
}
I have added some basic guidelines for you so that you can apply them going forward
Related
I have two tables named bookings and packages. Checked checkboxes are retrieved from bookings table and are working perfectly. But I also need unchecked check boxes from packages table. The problem is checked checkbox values display again.
<?php
$get_pro = "select * from booking";
$result = mysqli_query($con, $get_pro);
$book_packages = $row_pro['Book_Packages'];
$book_packages = substr(trim($book_packages) , 0, -1);
$split_pkg = (explode(",", $book_packages));
if (!empty($split_pkg)) {
foreach ($split_pkg as $book_pkg) {
$checked = (in_array($book_pkg, $split_pkg)) ? 'checked="checked"' : '';
?>
<input type="checkbox" name="pkg_list_name[]" value="<?php echo $book_pkg; ?>" size="17" <?php echo $checked; ?>> <?php echo $book_pkg; ?> <br>
<?php
}
}
$get_pros = "select * from package";
$results = mysqli_query($con, $get_pros);
while ($row_pros = mysqli_fetch_array($results)) {
$package_name = $row_pros['Pkg_Name'];
if ($package_name != $split_pkg) {
echo "<input type='checkbox' data-parsley-required='true' value='$package_name' data-parsley-trigger='click' id='checkbox1' name='pkg_list_name[]'>
<label>$package_name</label><br> ";
} else {
}
}
?>
You shouldn't have two loops. You should only create the checkboxes from the package table. When you're creating those checkboxes, add checked="checked" if the package name is in $split_pkg.
$book_packages = trim($row_pro['Book_Packages']);
$split_pkg = array_map('trim', explode(',', $book_packages));
$get_pros = "select * from package";
$results = mysqli_query($con, $get_pros);
while ($row_pros = mysqli_fetch_array($results)) {
$package_name = $row_pros['Pkg_Name'];
$checked = (in_array($package_name, $split_pkg)) ? 'checked="checked"' : '';
echo "<label><input type='checkbox' data-parsley-required='true' value='$package_name' data-parsley-trigger='click' name='pkg_list_name[]' $checked>
$package_name</label><br> ";
}
BTW, it's not a good idea to to put comma-separated values in database columns. You should have a separate row for each booking. Then you would be able to join the two tables easily.
so i'm making a php file that updates multiple rows to mysql but I'm having a problem whenever i submit,and I have no idea if I'm using foreach well. here is my code:
$query = "SELECT id, departments, deptName, headOfOffice FROM aip";
$result = mysqli_query($db,$query);
$count = mysqli_num_rows($result);
while ($row = mysqli_fetch_assoc($result)) {
echo '<tr>';
echo '<td><input type="text" name="id[]" value="'.$row['id'].'" readonly></td>';
echo '<td><input type="text" id ="department_code" name="department_code[]" value="'.$row['departments'].'"></td>';
echo '<td><input type="text" id="department_name" name="department_name[]" value="'.$row['deptName'].'"></td>';
echo '<td><input type="text" id="department_head" name="department_head[]" value="'.$row['headOfOffice'].'"></td>';
echo '</tr>';
}
echo '<tr>';
echo '<td></td>';
echo '<td></td>';
echo '<td><input type="submit" name="update" value="Update">';
echo '</tr>';
if($_SERVER["REQUEST_METHOD"] == "POST"){
$deptid = $_POST['id'];
$code = $_POST['department_code'];
$dname = $_POST['department_name'];
$dhead =$_POST['department_head'];
foreach($_POST['id'] as $count){ \\ i don't know if this is right.
$query2 = "UPDATE aip SET deparments = '".$code[$count].'" WHERE id = "'.$deptid[$count]."'";
$result2 = mysqli_query($db,$query2);
}
}
the error says "Undefined offset: 2"
I'm a newbie here, and this is my first time using arrays. hope someone could help. please!
foreach($_POST['id'] as $count => $id){
$query2 = "UPDATE aip SET deparments = '".$code[$count]."' WHERE id = '".$deptid[$count]."'";
$result2 = mysqli_query($db,$query2);
}
P.S. your code is vulnerable to SQL injection
There are two ways of using foreach:
foreach($array as $key => $value){
...
}
or
foreach($array as $value){
...
}
The foreach loop will then iterate through all elements in array, executing the code in brackets for each element once, holding the key name and the value of the element in $key and $value respectively (you can use other than $value and $key as well).
I don't fully understand what exactly you are doing in your code, so if you add an explanation, I will be able to solve your particular case;
i have changed in your script..pls used my script. you do not need to changes any thing just copy and paste my script.
if($_SERVER["REQUEST_METHOD"] == "POST"){
$data = $_POST;
if(count($data['id'])>0){
foreach($data as $key=>$item){
$query2 = "UPDATE aip SET deparments = '".$item['department_code'][$key]."', deptName = '".$item['department_name'][$key]."',headOfOffice = '".$item['department_head'][$key]."' WHERE id = '".$item['id'][$key]."'";
$result2 = mysqli_query($db,$query2);
}
}
}
I'm using a rather long HTML form to update lots of details relating to a product - for brevity I won't share the form in its entirety. However, for illustrative purposes here's a snippet :
HTML FORM
<form name="form1" method="post" action="update_ac.php">
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td>
<input name="season" type="text" class="button_select" id="season" value="<?=$rows['season']; ?>" size="10" />
<input name="restock" type="checkbox" id="restock" value="on" <?php if($rows['restock']=='on') { echo 'checked="checked"'; } ?>/>
// other fields
</td>
</tr>
</table>
</form>
My question is when posting the form to update_ac.php - how can I dynamically generate a MYSQL update statement based on the fields that are completed?
Here's an example of my form action page:
PHP FORM Action
<?php
foreach ($_POST as $key => $value) {
$$key = $value;
}
$sql= mysql_query ("
UPDATE product SET
title='".$title."',
rating='".$rating."',
season='".$season."',
brand_id='".$brand_id."',
category='".$category."',
... etc ");
?>
I don't want to have to declare every single field that could possibly need updating in the UPDATE statement. I would like the UPDATE statement to only address the fields concerned given the presence of defined PHP variables posted from the form.
At the moment, I'm getting lots of NOTICE: Undefined variable x where there have been empty fields when posting the form.
I hope this makes sense - little long winded.
Any advice? Thanks
UPDATE
Following on from #Styphon's answer - I amended it slightly to include the WHERE condition at the end of the query.
$query = "UPDATE product SET";
$comma = " ";
foreach($_POST as $key => $val) {
if( ! empty($val)) {
$query .= $comma . $key . " = '" . mysql_real_escape_string(trim($val)) . "'";
$comma = ", ";
}
}
$product_id = $_POST['product_id'];
$query = $query . "WHERE product_id = '".$product_id."' ";
Assuming that all the field names in the table are the same as the names of your form inputs this is straight forward. You can use this:
$query = "UPDATE product SET";
$comma = " ";
foreach($_POST as $key => $val) {
if( ! empty($val)) {
$query .= $comma . $key . " = '" . mysql_real_escape_string(trim($val)) . "'";
$comma = ", ";
}
}
$sql = mysql_query($query);
To be more secure you should create a whitelist of accepted parameters, i.e. the columns in your table like this:
$query = "UPDATE product SET";
$comma = " ";
$whitelist = array(
'title',
'rating',
'season',
'brand_id',
'cateogry',
// ...etc
);
foreach($_POST as $key => $val) {
if( ! empty($val) && in_array($key, $whitelist)) {
$query .= $comma . $key . " = '" . mysql_real_escape_string(trim($val)) . "'";
$comma = ", ";
}
}
$sql = mysql_query($query);
That way your query can only contain parameters you set, and if anyone manages to inject extras (by changing the names of your form inputs for example) it wont be passed to your database.
I'd also recommend you stop using Mysql_*, it's deprecated. You should look at MySQLi or PDO as alternatives.
I am dynamically generating a set of radio buttons from MySQL. The buttons are creating and the variables assigned to them are populating as I did an echo print_r and it shows the array for the variable. I now want to compare the values generated from this and if the vale is "0" I want to insert a score and present a green check graphic and the word correct. If the value is "1" I want it to input different values for the score and present Incorrect and a red X graphic. Here is what I have so far (Everything populates dynamically both the question and the answers as radio buttons):
<?php
echo '<form id="frmQuestion" name="frmQuestion" method="post" action="QuizQuestion1.php">';
// Connect to the Database
require_once('mysqli_connect.php');
//create the query for the question
$q = "SELECT `Question` FROM tbl_Question WHERE QuestionID = 1";
//Create the query for the Answers
$q2 = "SELECT `Answer`,`AnswerStatusID`,`AnswerResponse` FROM tbl_Answer WHERE QuestionID = 1";
//Run the query
$r = mysqli_query($conn,$q);
//run the answer query
$r2 = mysqli_query($conn,$q2);
while($row = mysqli_fetch_array($r,MYSQLI_ASSOC)){
echo '<div id="Question1"><p> ' . $row['Question'] . '</div></p>';
}
//Declare the variables as a array
$AnswerResponse = array();
$AnswerStatusID = array();
while($row2 = mysqli_fetch_array($r2,MYSQLI_ASSOC)){
echo '<div id="Question1"><input name="q1" type="radio" value="'.$AnswerStatusID.'"/>' . $row2['Answer'] . '</div><br/>';
//Assign the AnswerStatusID to a var
$AnswerStatusID[] = $row2['AnswerStatusID'];
//Assign the AnswerResponse to a var
$AnswerResponse[] = $row2['AnswerResponse'];
}
//Create the submit button
echo '<input type="submit" value="Submit Answer" name="submit"/>';
echo '</form>';
//Logic for correct or incorrect answers
if (isset($_POST['q1']) && ($_POST['q1'] == '0'))
{
//create the query for the score
$q3 = "INSERT INTO tbl_Score (`Score`,`QuestionID`) VALUES ('100%','1')";
//Run the query
$r = #mysqli_query ($conn,$q3);
if($r){
//Confirm message data was entered with a correct response and a graphic
echo '<h1>Correct!!</h1><img src="/images/green_Check_Low.jpg" alt="Green Check"/>';
echo 'Click here for the next question';
}
else
{
//there was an error
echo'<h1>System error</h1>';
//Debugging message
echo'<p>' . mysqli_error($conn) . '<br/><br/>Query:' . $q3 . '</p>';
}//End of nested IF
}
else{
//create the query for the score
$q4 = "INSERT INTO tbl_Score (`Score`,`QuestionID`) VALUES ('0%','1')";
//Run the query
$r2 = #mysqli_query ($conn,$q3);
if($r2){
//Confirm message data was entered with a correct response and a graphic
echo '<h1>Incorrect!!</h1><img src="/images/red_X_Low.jpg" alt="Red X"/>';
echo 'Click here for the next question';
}
else
{
//there was an error
echo'<h1>System error</h1>';
//Debugging message
echo'<p>' . mysqli_error($conn) . '<br/><br/>Query:' . $q3 . '</p>';
}//End of nested IF
}
//Free up the results for the Question query
mysqli_free_result($r);
//Free up the results from the Answer query
mysqli_free_result($r2);
//close the DB connection
mysqli_close($conn);
?>
This is the answer and work as intended. Thanks for everyones input.
//Declare the variables as a array
$AnswerResponse = array();
$AnswerStatusID = array();
while($row2 = mysqli_fetch_array($r2,MYSQLI_ASSOC)){
echo '<div id="Question1"><input name="q1" type="radio" value="'.$row2['AnswerStatusID'].'"/>' . $row2['Answer'] . '</div><br/>';
//Assign the AnswerStatusID to a var
$AnswerStatusID[] = $row2['AnswerStatusID'];
//Assign the AnswerResponse to a var
$AnswerResponse[] = $row2['AnswerResponse'];
}
//Create the submit button
echo '<input type="submit" value="Submit Answer" name="submit"/>';
echo '<input type="hidden"name="submitted"value="TRUE"/>';
echo '</form>';
if($_POST['submitted']) {
//Logic for correct or incorrect answers
if (isset($_POST['q1']) && ($_POST['q1'] == '0'))
{
//create the query for the score
$q3 = "INSERT INTO tbl_Score (`Score`,`QuestionID`) VALUES ('100%','1')";
//Run the query
$r3 = #mysqli_query ($conn,$q3);
//Confirm message data was entered with a correct response and a graphic
echo '<h1>Correct!!</h1><img src="/images/green_Check_Low.jpg" alt="Green Check"/>';
echo 'Click here for the next question';
}
else{
//create the query for the score
$q4 = "INSERT INTO tbl_Score (`Score`,`QuestionID`) VALUES ('0%','1')";
//Run the query
$r4 = #mysqli_query ($conn,$q4);
//Confirm message data was entered with a correct response and a graphic
echo '<h1>Incorrect!!</h1><img src="/images/red_X_Low.jpg" alt="Red X"/><br/>';
echo 'Click here to try again';
}
}
I am having a big issue.
This is the first time I sue a foreach and I do not even know if it's the right thing to use.
I have a textarea where my members can add some text.
They also have all the accounts where to send the posted text.
Accounts are of two types F and T.
They are shown as checkboxes.
So when a member types "submit" the text should be INSERTED in a specific table for EACH of the selected accounts. I thought php foreach was the right thing. But I am not sure anymore.
Please take in mind I do not know anything about foreach and arrays. So please when helping me, consider to provide the modded code =D . Thank you so much!
<?php
require_once('dbconnection.php');
$MembID = (int)$_COOKIE['Loggedin'];
?>
<form action="" method="post">
<p align="center"><textarea id="countable1" name="addit" cols="48" rows="10" style="border-color: #ccc; border-style: solid;"></textarea>
<br>
<?
$DB = new DBConfig();
$DB -> config();
$DB -> conn();
$on="on";
$queryF ="SELECT * FROM `TableF` WHERE `Active`='$on' AND `memberID`='$MembID' ORDER BY ID ASC";
$result=mysql_query($queryF) or die("Errore select from TableF: ".mysql_error());
$count = mysql_num_rows($result);
if ($count > 0)
{
while($row = mysql_fetch_array($result)) {
?><div style="width:400px; height:100px;margin-bottom:50px;"><?
$rowid = $row['ID'];
echo $row['Name'] . '</br>';
$checkit = "checked";
if ($row['Main'] == "")
$checkit = "";
if ($row['Locale'] =="")
$row['Locale'] ="None" . '</br>';
echo $row['Locale'] . '</br>';
if ($row['Link'] =="")
$row['Link'] ="javaScript:void(0);";
?>
<!-- HERE WE HAVE THE "F" CHECKBOXES. $rowid SHOULD BE TAKEN AND INSERTED IN THE FOREACH BELOW FOR ANY SELECTED CHECKBOX IN THE FIELD "Type".SEE BELOW -->
<input type="checkbox" name="f[<?php echo $rowid?>]" <?php echo $checkit;?>>
</div>
<?
}//END WHILE MYSQL
}else{
echo "you do not have any Active account";
}
$DB = new DBConfig();
$DB -> config();
$DB -> conn();
$queryTW ="SELECT * FROM `TableT` WHERE `Active`='$on' AND `memberID`='$MembID' ORDER BY ID ASC";
$result=mysql_query($queryTW) or die("Errore select TableT: ".mysql_error());
$count = mysql_num_rows($result);
if ($count > 0)
{
while($row = mysql_fetch_array($result)) {
?><div style="width:400px; height:100px;margin-bottom:50px;"><?
$rowid = $row['ID'];
echo $row['Name'] . '</br>';
$checkit = "checked";
if ($row['Main'] == "")
$checkit = "";
if ($row['Locale'] =="")
$row['Locale'] ="None" . '</br>';
echo $row['Locale'] . '</br>';
if ($row['Link'] =="")
$row['Link'] ="javaScript:void(0);";
?>
<!-- HERE WE HAVE THE "T" CHECKBOXES. $rowid SHOULD BE TAKEN AND INSERTED IN THE FOREACH BELOW FOR ANY SELECTED CHECKBOX IN THE FIELD "Type".SEE BELOW -->
<input type="checkbox" name="t[<?php echo $rowid?>]" <?php echo $checkit;?> >
</div>
<?
}//END 2° WHILE MYSQL
}else{
echo "you do not have any Active account";
}
?>
<input type="submit" value="submit">
</form>
<?
//WHEN CHECKBOXES "F" ARE FOUND, FOR EACH CHECKBOX IT SHOULD INSERT INTO TableG THE VALUES BELOW, FOR EACH SELECTED "F" CHECKBOX
if(!empty($_POST['addit']) && !empty($_POST['f'])){
$thispostF = $_POST['f'];
$f="F";
foreach ($thispostF as $valF)
//THE MOST IMPORTANT FIELD HERE IS "Type". THE ARRAY INSERT "on", I NEED INSTEAD THE VALUE $rowid AS ABOVE
$queryaddF="INSERT INTO TableG (ID,memberID,Type,IDAccount,Tuitting) VALUES (NULL,".$MembID.",'".$f."','".$valF."', '".$_POST['addit']."')";
$resultaddF=mysql_query($queryaddF) or die("Errore insert G: ".mysql_error());
}
//WHEN CHECKBOXES "T" ARE FOUND, FOR EACH CHECKBOX IT SHOULD INSERT INTO TableG THE VALUES BELOW, FOR EACH SELECTED "T" CHECKBOX
if(!empty($_POST['addit']) && !empty($_POST['t'])){
$thispostT = $_POST['t'];
$t="T";
foreach ($thispostT as $valF)
//THE MOST IMPORTANT VALUE HERE IS "Type". THE ARRAY GIVES "on", I NEED INSTEAD THE VALUE $rowid AS ABOVE
$queryaddT="INSERT INTO TableG (ID,memberID,Type,IDAccount,Tuitting) VALUES (NULL,".$MembID.",'".$t."','".$valF."', '".$_POST['addit']."')";
$resultaddF=mysql_query($queryaddF) or die("Errore insert G: ".mysql_error());
}
?>
foreach ($thispostT as $valF)
{
$queryaddT="INSERT INTO TableG (ID,memberID,Type,IDAccount,Tuitting) VALUES (NULL,".$MembID.",'".$t."','".$valF."', '".$_POST['addit']."')";
$resultaddF=mysql_query($queryaddF) or die("Errore insert G: ".mysql_error());
}
please put start and ending bracket to your foreach loop and try i have not read the whole code but just found you missing the brackets. hope that helps you.
I think I know what you're doing...
You're going to need to do:
foreach($_POST as $key => $value) {
$type = substr($key,0,1);
$id = substr($key,1);
if($type == 't') {
// do insert for t table here
} else if($type == 'f') {
// do insert for f table here
}
}
I didn't test it but it should be something like this.
My suggestion is
create field name as t[] (array)
onchecked value will be passed on the next page
the form checkbox field should be like that
<input type="checkbox" name="t[]" value="< ?php echo $rowid?>" <?php echo $checkit;? > >
and when you Submit the form
GET THE VALUE and insert in to database;
< ?
if($_POST['t'])
{
foreach($_POST['t'] as $v)
{
queryaddT="INSERT INTO TableG (ID,memberID,Type,IDAccount,Tuitting) VALUES (NULL,".$MembID.",'".$t."','".$valF."', '".$_POST['addit']."')";
$resultaddF=mysql_query($queryaddF) or die("Errore insert G: ".mysql_error());
}
}
? >