Display single line data in columns mysql/PHP - php

Currently I have a script that displays the data which is editable and can update the database. I have tried to enter row counts and nothing seem to work. I really like the script to make 3 columns (10 rows per column), please help.
$sql = "SELECT id, pounds FROM price_list ORDER BY id";
$i = 0;
$result = mysql_query($sql);
echo "<form name='prices' method='post' action='updateA.php'>";
while($rows = mysql_fetch_array($result))
{
echo "<body bgColor='#5F5F6B'>";
echo "<table><table border=2 cellspacing=0 cellpadding=1>";
echo "<input type='hidden' name='id[$i]' value='{$rows['id']}' >";
echo "<td><font color='#FFFFFF'><font size='2'>DAYS {$rows['id']}: </font><font size='2'><font color='#000000'>PRICE:<input type='text' size='1' name='pounds[$i]' value='{$rows['pounds']}' ></tr>";
++$i;
}
echo "</table>";
echo "<input type='submit' value='Update Prices Band A' />";
echo "</form>";
?>
The above is the original code.

I don't really know what you're trying to do, but this code will generate a list of all the entries in the database with the ability to change them. Note that you'll have to remake your update_a.php file:
<style>
body {
background:#5F5F6B;
color:#fff;
}
</style>
<?php
$result = mysql_query("SELECT id, pounds FROM price_list ORDER BY id");
if (!$sql || mysql_num_rows($result)==0)
echo "Price list is empty";
else {
echo '<form name="prices" method="GET" action="update_a.php">'; // Change your filename!
$i = 0;
while ($rows = mysql_fetch_array($result)) {
echo 'Day '.$rows['id'].' costs ';
echo '<input type="text" name="'.$rows['id'].'" value="'.$rows['pounds'].'"/> pounds'
echo '<br/>'
$i++;
}
echo '<input type="submit" value="Update Prices Band A"/>';
echo "</form>";
}
?>

First of all many thanks to Leonard Pauli, the code worked perfectly in displaying the data but, it wouldn't update the database using my update.php. Below is the revised code and screenshot of what I was trying to archive.
Screenshot of single lined data displayed in 3 columns
<style>
body {
background:#5F5F6B;
color:#fff;
width:800px;
height:550px;
border:2px solid #bbb;
padding:20px;
float:center;
}
input[type="text"] {
width: 30px;
}
.table {
width:180px;
margin:1px;
border:2px solid #bbb;
padding:10px;
float:left;
}
.header {
width:595px;
margin:1px;
border:2px solid #bbb;
padding:10px;
float:left;
}
</style>
<div class="header"><b>Price List for dates from <font color ="yellow"><?php echo "$SPA"; ?> to <?php echo "$EPA"; ?></font></div>
<?php
$dataprice = $_POST['database'];
$datesrange = $_POST['id'];
$result = mysql_query("SELECT id, pounds FROM $dataprice ORDER BY id");
echo '<form name="prices" method="POST" action="update.php">';
$i = 0;
while ($rows = mysql_fetch_array($result)) {
echo '<div class="table">Day <font color="yellow">'.$rows['id'].' </font> costs ';
echo "<input type='hidden' name='id[$i]' value='{$rows['id']}' >";
echo "<input type='text' name='pounds[$i]' value='{$rows['pounds']}' > Pounds";
echo '<br/></div>';
$i++;
}
echo "<input type='hidden' name='databases' value='$dataprice'>";
echo '<center><input type="submit" value="Update Prices"/>';
echo '<center><font color="yellow"><br><br><br>IF UPDATING PRICE BAND D, ONLY ENTER THE VALUE OF WHICH
PRICES YOU WANT TO INCREASE BY, <br>EXAMPLE: 7 DAYS, IF CURRENT PRICE IS 30, IF YOU WANT TO
CHARGE 34, ONLY ENTER 4 AND LEAVE EVERYTHING ELSE SET TO 0</b></center>';
echo "</form>";
?>
A bit of an idiot really, completely forgot about CSS styling.

Related

Second submit button not showing [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
I have created a form whose method is "POST" and action is "#", indicating to send the data to the same page.
Now after submitting the form,
A second form appears below which fetches data(according to the selection on first form) from database and gives the user a control to edit the record.
EVERYTHING IS WORKING GOOD AND WELL
The only problem is "*Second form submit button doesn't show up"
My Code of that particular page:(editcategory.php)
<?php
require_once("admin_panel.php");
?>
<!DOCTYPE html>
<head>
<title>Users</title>
<link rel="stylesheet" href="css/footer.css">
<style>
.bodystart{
margin-top:2%;
margin-left:25%;
}
h1{
font-size:xx-large;
}
table {
border-collapse: separate;
border-spacing:5px 5px;
width: auto;
color: #588c7e;
font-family:"Lucida Console", "Courier New", monospace;
font-size: 20px;
text-align: left;
}
th {
background-color: #588c7e;
color: white;
}
option:nth-child(even) {
background-color: #f2f2f2
}
.submitnewcat{
margin-top:3%;
color:#ffffff;
padding:5px;
border-radius:10 px;
background-color:#4CAF50;
cursor:pointer;
}
form{
margin-top:5%;
}
input,select{
border-style:inset;
border-left:6px solid green;
background-color:#ced6e0;
padding: 12px 15px;
border-radius:5px;
}
.catidcont{
background-color:#c7ecee;
cursor:default;
}
label{
padding:12px 15px;
font-size:larger;
background-color:#130f40;
color:#ffffff;
border-radius:5px;
border:2px solid red;
}
</style>
</head>
<body>
<div class="bodystart">
<h1><i>Edit Category</i></h1>
<form method="POST" action="#">
<label>Select Category</label>
<?php
$sql = "SELECT * FROM category";
$result = mysqli_query($db_conn,$sql);
echo "<select name='catset' required>";
echo "<option value=''>Select</option>";
while ($row = $result->fetch_assoc()) {
echo "<option value='" . $row['id'] . "'>" . $row['name'] . "</option>";
}
echo "</select>";
?>
<button class="submitnewcat" name="submit3" type="submit" value="Submit">Fetch Details</button>
</form>
<?php
if(isset($_POST["submit3"])==true){
function validate($data){
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
$x=(int)$_POST['catset'];
$sql = "SELECT * FROM category a WHERE a.id=$x";
$result = $db_conn->query($sql);
if ($result->num_rows > 0) {
$row = $result->fetch_assoc();
echo "<form method='POST' action='updatecategory.php'";
echo "<input type='hidden' readonly>";
echo "<label>Category ID</label>";
echo "<input type='number' name='catid' value=$x readonly style='cursor:no-drop;'><br><br><br>";
echo "<label>New Category Name</label>";
echo "<input type='text' name='newcatname' required placeholder='".$row['name']."'>";
echo "<label>Status</label>";
echo "<select name='newstat' required>";
if($row["status"]==1){
$catstat="Active";
echo "<option value='".$row['status']."' selected>$catstat</option>";
echo "<option value='2'>Disabled</option>";
}
else{
$catstat="Disabled";
echo "<option value='1'>Active</option>";
echo "<option value='".$row['status']."' selected>$catstat</option>";
}
echo "<button class='submigtnewcat' name='submit4' type='submit' value='Submit'>Fetch Details</button>";
echo "</form>";
}
} ?>
</div>
</body>
<?php
require_once("include/footer.php");?>
</html>
Snippet of my page
there is bug you have not close the tag of select so button is not displaying .
i hope you have got your answer .
echo "<select name='newstat' required>";
if($row["status"]==1){
$catstat="Active";
echo "<option value='".$row['status']."' selected>$catstat</option>";
echo "<option value='2'>Disabled</option>";
}
else{
$catstat="Disabled";
echo "<option value='1'>Active</option>";
echo "<option value='".$row['status']."' selected>$catstat</option>";
}
echo "</select>";

Only 1 data submitted into database (food ordering system)

I am new on implementing Ajax on PHP so I need a big help! anyways my problem is I have a 5 column names on my table_menu
table_menu:
menu_id
menu_foodname
menu_price
menu_quantity
menu_image
and inside those column names it has 6 datas.
And I will gonna fetch those datas on my webpage(users.php)
<?php
// users.php
// fetching data
include 'config/initialize.php';
$sql = "SELECT * FROM table_menu";
$res = mysqli_query($con, $sql);
if($res)
{
echo "<table><tr>";
while($row = mysqli_fetch_array($res))
{
echo "<td>";
echo "<div class='horizontalAlign'>";
echo "<form class='form-item' method='post'>";
echo "<img class='img-circle' src='menuImage/".$row['menu_image']."' style='height: 150px; width: 200px;'>";
echo "<input type='hidden' name='menuimage' class='menuimage' value='".$row['menu_image']."'>";
echo "<input type='text' name='menufoodname' class='menufoodname' value='".$row['menu_foodname']."' style='border:none; margin-top: 10px; margin-left: 30px; font-size: 20px;' readonly>";
echo "<div style='font-size: 20px; margin-left: 40px;'>Price:</div> <input type='text' class='menuprice' name='menuprice' value='".$row['menu_price']."' style='border:none; margin-left: 100px; margin-top: -28px; position: absolute; font-size: 20px;' readonly>";
echo "<div style='font-size: 20px;'>Quantity:</div> <input type='number' class='menuquantity' name='menuquantity' style='margin-top: -26px; position: absolute; margin-left: 90px; text-align: center;' value='".$row['menu_quantity']."' min='0' max='100'>";
echo "<br>";
echo "<input type='button' value='Submit order' class='btnaddorder btn btn-lg btn-info' class='btn btn-info'>";
echo "</form>";
echo "</div>";
echo "</td>";
$i++;
if($i == 3)
{
echo "</tr><tr>";
}
} // end of while
echo "</tr></table>";
} // end of variable $i
?> <!-- // end of fetching data -->
and I want the page to be not refresh while the user orders... so I add this ajax script on the bottom of users.php
<script type="text/javascript">
$(document).ready(function() {
$(".btnaddorder").click(function() {
var menuimage = $(".menuimage").val();
var menufoodname = $(".menufoodname").val();
var menuprice = $(".menuprice").val();
var menuquantity = $(".menuquantity").val();
// Returns successful data submission message when the entered information is stored in database.
$.post("addorders.php", {
menuimage1: menuimage,
menufoodname1: menufoodname,
menuprice1: menuprice,
menuquantity1: menuquantity,
}, function(data) {
});
});
});
</script>
Now the problem is when I am clicking the first button on the fetched datas the first one only got inserted and if I am add the second item even the third until fifth item it only display one data on the database which is the first data, why?
heres my addorders.php
<?php
include 'config/initialize.php';
include 'credentials/credentialsForUsers.php';
$menuimage = $_POST['menuimage1'];
$menufoodname = $_POST['menufoodname1'];
$menuprice = $_POST['menuprice1'];
$menuquantity = $_POST['menuquantity1'];
$sql = "INSERT INTO table_orders VALUES('','$username','$email','$menuimage','$menufoodname','$menuprice','$menuquantity')";
$result = mysqli_query($con, $sql);
?>
thank you & sorry for my bad english. hope you understand my problem
To clarify which fields you want to submit you can do the following:
$(".btnaddorder").click(function() {
// here you find closest form tag to the pressed button
var form = $(this).closest('form');
// replace all you values with simple .serialize() function
// this function will use all non-disable fields from the form
$.post("addorders.php", form.serialize(), function(data) { });
});
On the serverside your $_POST will have the same keys as fields on your form.

How to select table rows and display them one after the other at random in php

I am developing an online examination system. Everything works fine but the questions are selected and displayed from question number one to the last question. I wanted to do the following:
Select the questions and display them one after the other at random.
Add a skip button so that students can skip any question they can't answer and it will be rolled back to them later.
Give a time to the answering session so that when the time is up it will stop the student.
This is my code for the question selection.
<!DOCTYPE html">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
body{background-color:#f4fff8;}
#aq{
position:relative;
top:50px;
}
#st{
position:relative;
top:30px;
}
.btn{
background-color:#dedbb8;
color:#016e37;
text-shadow:3px 3px 3px gray;
box-shadow:3px 3px 3px gray;
height:40px;
text-align:center;
font-size:25px;
font-family:'Times New Roman';
font-weight:bold;
font-style:italic;
margin-top:2px;
border-radius: 2px;
}
.style8{
padding-top:5px;
font-size:20px;
}
#pt{
padding-top:20px;
}
h1{
position:relative;
color:green;
top:30px;
}
h2{
position:relative;
color:orange;
top:30px;
}
</style>
</head>
<body>
<?php
require_once("dbconnect.php");
include("header.php");
include("footer.php");
include("stdlogsession.php");
extract($_GET);
extract($_POST);
extract($_SESSION);
$student_id=$_SESSION['login_user'];
$student_id = stripslashes($student_id);
$student_id = mysqli_real_escape_string($db_conn,$student_id);
if(!empty($_GET['examid']))
{
$examid =$_GET['examid'];
}
// Selecting Database
$db = mysqli_select_db($db_conn,$mysql_database);
$rs=mysqli_query($db_conn,"select * from objquestions where exam_id='$examid'") or die('Error: ' .mysql_error($db_conn));
if(!isset($_SESSION['qn']))
{
$_SESSION['qn']=0;
}
if(!empty($_POST['submit'])=='Answer' && isset($ans))
{
mysqli_data_seek($rs,$_SESSION['qn']);
$row= mysqli_fetch_row($rs);
if($ans==$row[8])
{
$remarks= "Correct";
$mark=$row[9];
} else {
$remarks= "Wrong";
$mark=0;
}
mysqli_query($db_conn,"insert into results(exam_id,student_id,quesNum,choice,remarks,mark) values ('$row[1]','$student_id','$row[2]', '$ans','$remarks','$mark')") or die(mysqli_error($db_conn));
$_SESSION['qn']=$_SESSION['qn']+1;
}
if($_SESSION['qn']>mysqli_num_rows($rs)-1)
{
$examN=mysqli_query($db_conn,"select examName from exampaper where exam_id='$examid'") or die('Error: ' .mysqli_error($db_conn));
$row = mysqli_num_rows($examN);
if ($row > 0) {
$rows=mysqli_fetch_assoc($examN);
$Enam=$rows['examName'];
}
echo "<center><h1>congrats! you have successfully finished your " .$Enam."</h1></center>";
echo "<center><h2> Click <a href=instresult.php>here</a> for your results </h2></center>";
unset($_SESSION['qn']);
exit();
}
if(!empty($_POST['submit'])=='Skip' && !isset($ans))
{
mysqli_data_seek($rs,$_SESSION['qn']);
$row= mysqli_fetch_row($rs);
$_SESSION['qn']=$_SESSION['qn']+1;
}
$rs=mysqli_query($db_conn,"select * from exampaper where exam_id='$examid'") or die('Error: ' .mysql_error($db_conn));
$rows = mysqli_num_rows($rs);
while($rows=mysqli_fetch_row($rs))
{
echo "<center>";
echo "<table id=aq >";
echo "<tr><td>
<span class=style8>SUBJECT:</span></td>
<td class=style8>$rows[2]</td>
</tr>";
echo "<tr><td>
<span class=style8>EXAMINATION NAME:</span></td>
<td class=style8>$rows[1]</td>
</tr>";
echo "<tr><td>
<span class=style8>EXAMINATION DATE:</</span></td>
<td class=style8>$rows[3]</td>
</tr>";
echo "<tr><td>
<span class=style8>TOTAL TIME:</span></td>
<td class=style8>$rows[4]</td>
</tr>";
echo "<tr><td>
<span class=style8>INSTRUCTIONS:</span></td>
<td class=style8>$rows[5]</td>
</tr>";
echo "</table>";
echo "</center>";
}
$rs=mysqli_query($db_conn,"select * from objquestions where exam_id='$examid'") or die(mysqli_error($db_conn));
if($_SESSION['qn']>mysqli_num_rows($rs)-1)
{
unset($_SESSION['qn']);}
echo "<center>";
echo "<table id=st>";
mysqli_data_seek($rs,$_SESSION['qn']);
$row= mysqli_fetch_row($rs);
echo "<form name=myfm method=post action=exam.php>";
$n=$_SESSION['qn']+1;
echo "<tR ><td id=pt><span class=style8>Quetion ". $n .": $row[3]</style></td></tr>";
echo "<tr><td class=style8><input type=radio name=ans value=A>$row[4]</td></tr>";
echo "<tr><td class=style8> <input type=radio name=ans value=B>$row[5]</td></tr>";
echo "<tr><td class=style8><input type=radio name=ans value=C>$row[6]</td></tr>";
echo "<tr><td class=style8><input type=radio name=ans value=D>$row[7]</td></tr>";
echo "<tr><td><input class=btn type=submit name=submit value='Answer'> <input align=right class=btn type=submit name=submit value='Skip'></td></tr></form>";
echo "</table>";
echo "</center>";
?>
</body>
</html>

Keep values in input fields - php array

I have a php array that includes inputs for posting. It uses a counter for each array record, and this counter is applied to the name of the input to be used in performing some actions with the post - this is working great.
The issue is that I would like to keep the users' existing inputs and re-populate the input fields in the array if their post doesn't pass validation.
I have done this before with static fields, simply storing the post variable and echoing it in the "value" --- but I can't figure out how to do this when working with an array. Anyone have any ideas?
$counter = 0;
echo "<form method='post'>";
echo "<table class='mainlist' width='680'>";
while ($row = mysqli_fetch_array($result)) {
echo "<tr height='60'>";
echo "<td class='mainlist'><input type=text name=options[$counter] autocomplete=off onclick='this.select()' class='txt'></td>";
echo "</tr>";
$counter = $counter + 1;
}
echo "</table>";
Full code per request:
<?php
if($_SERVER["REQUEST_METHOD"] == "POST")
{
$userid = $_SESSION['login_user'];
$companyid = $_POST['companyid'];
$options = $_POST['options'];
$counter = $_POST['hiddencounter'];
$runningtotal=0;
$totaloptions = array_sum($options);
$result = mysqli_query($connection, "SELECT options_balance FROM user_options_balance WHERE user_id = '".$userid."'");
for ($i=0; $i<$counter; $i++)
{
if(empty($options[$i]))
{ /* IF NO INPUT ON OPTIONS */
/* DO NOTHING */
}
else
{
$checknewcompanies = mysqli_query($connection, "SELECT company_id FROM user_company_total_invested WHERE user_id = '".$userid."' and company_id = '" .$companyid[$i]."'");
if($checknewcompanies->num_rows == 1)
{ // do nothing
}
else
{
$runningtotal = $runningtotal + 1;
}
} /* END OF ELSE IF NOT EMPTY OPTIONS */
} /* END OF FOR LOOP */
$checkcurrentcompanies = mysqli_query($connection, "SELECT company_id FROM user_company_total_invested WHERE user_id = '".$userid."'");
$countcompanies = $checkcurrentcompanies->num_rows;
$countcheck = $runningtotal + $countcompanies;
if($countcheck <= 4)
{
while($row = mysqli_fetch_array($result))
{
$balance = $row['options_balance'];
}
if ($totaloptions>$balance)
{
$notenoughoptions= "<div style='background-color:#FF0000; border-radius: 15px; padding: 10px; color: #FFFFFF; font-size: 12px;'>Oops! You don't have enough options! Try investing less!</div>";
}
else
{
// loop through array
for ($i=0; $i<$counter; $i++)
{
if(empty($options[$i])){ /* IF NO INPUT ON OPTIONS */
/* DO NOTHING */
}
else {
if(!ctype_digit($options[$i]) or !is_numeric($options[$i])){
$charactercheck= "<div style='background-color:#FF0000; border-radius: 15px; padding: 10px; color: #FFFFFF; font-size: 12px;'>Oops! Please enter only positive numbers to invest!</div>";
}
else {
$checkcompanies = mysqli_query($connection, "SELECT company_id FROM company_main WHERE company_id = '".$companyid[$i]."'");
if($checkcompanies->num_rows != 1)
{
$companynotexist= "<div style='background-color:#FF0000; border-radius: 15px; padding: 10px; color: #FFFFFF; font-size: 12px;'>Oops! That company doesn't exist!</div>";
}
else
{
// loop through array
for ($i=0; $i<$counter; $i++)
{
if(empty($options[$i]))
{ /* IF NO INPUT ON OPTIONS */
/* DO NOTHING */
}
else
{
$query = "INSERT INTO user_company_invested(user_id, company_id, user_company_options_invested)
VALUES($userid,$companyid[$i],$options[$i])";
mysqli_query($connection, $query);
} /* END OF ELSE IF NOT EMPTY OPTIONS */
} /* END OF FOR LOOP */
$balancecheck = mysqli_query($connection, "SELECT options_balance FROM user_options_balance WHERE user_id = '".$userid."'");
while($row = mysqli_fetch_array($balancecheck))
{
$balance2 = $row['options_balance'];
}
if($balance2 > 0)
{
header('Location: user_invest.php');
}
else
{
header('Location: user_market.php');
}
} // end company check
} //end character check
} //end empty option check
} //end loop
} /* END OF NOT ENOUGH OPTIONS CHECK */
}
else
{
$toomanycompanies = "<div style='background-color:#FF0000; border-radius: 15px; padding: 10px; color: #FFFFFF; font-size: 12px;'>Oops! You can invest in a maximum of 4 companies per week. Please choose fewer companies, or invest more in some of your existing companies!</div>";
/* echo "Maximum number of companies you can invest in is 4";
echo "<br />";
echo "Companies you already are invested in: ".$countcompanies;
echo "<br />";
echo "New companies you are trying to invest in: ".$runningtotal;
echo "<br />";
echo "Total: ".$countcheck;*/
}
} /* END OF ISSET CHECK */
else
{
}
?>
<?php
$result = mysqli_query($connection,"SELECT * from company_main");
$counter=0;
echo "<form method='post'>";
echo "<table class='mainlist' width='680'>";
while($row = mysqli_fetch_array($result))
{
echo "<tr height='60'>";
echo "<td class='mainlist' width=140 align='center'>" . "<img src='".$row['company_logo']."' width='40'/>" . "</td>";
echo "<td class='mainlist' align='left' width=390 style='font-size: 15px;'>" . $row['company_name'] . "</td>";
echo "<input type=hidden name=companyid[$counter] value=" . $row['company_id'] . " />";
echo "<td class='mainlist'><input value='{$_POST['options[$counter]']}' type=text name=options[$counter] autocomplete=off onclick='this.select()' class='txt' style=' background-color: #FCFCFC;
border: solid 1px #CCCCCC;
font-size: 12px;
padding: 5px;
height: 20px;
text-align: right;'></td>";
echo "</tr>";
$counter=$counter+1;
}
echo "</table>";
echo "<input type='hidden' name='hiddencounter' value='$counter'>";
echo "
<table>
<tr>
<td width='630' height='50'></td>
<td align='right' width='60' style='color: #848580; font-size: 20px;'>Total: </td>
<td align='right' width='40' style='color: #94D90B; font-size: 20px; font-weight: bold; padding-right:20px;'><span id='sum'>0</span></td><td width='10'></td>
</tr><tr height='20px'></tr><tr>
<td width='570' align='center' style='color: #94D90B; font-size: 12px;'>";?>
<?php echo $notenoughoptions; ?>
<?php echo $charactercheck; ?>
<?php echo $toomanycompanies; ?>
<?php echo "
</td>
<td colspan='2' width='100' align='right'><input name='userinvestoptionsdynamic' type='submit' value='Invest!'></td><td width='10'></td>
</tr>
<tr height='20px'></tr>
</table>";
echo "</form>";
?>
The correct syntax is:
echo "{$arrayname($keyname)}";
So for example echo('value=' . $_POST['options'][$counter]); becomes:
echo "value={$_POST['options'][$counter]}";

insert to database with checkbox

I'm trying to find a way to upload a value to SQL using a checkbox but no luck
this is my code:
/////////////////////////// FOR RXTRA ////////////////////////////////////////////////////////////
$sql = "SELECT ext_id,ext_price,ext_name,ext_description FROM tbl_extra ORDER by ext_id ASC";
$result = mysql_query($sql) or trigger_error(mysql_error(),E_USER_ERROR);
$number = mysql_num_rows($result);
$i = 0;
while ($number > $i) {
$ID = mysql_result($result,$i,"ext_id");
$NA= mysql_result($result,$i,"ext_name");
$PR= mysql_result($result,$i,"ext_price");
$DES= mysql_result($result,$i,"ext_description");
//this part chack if the value is "0" and show with "tooltip" the value\/
if ( $PR == 0 ) {
print ''.$NA.'<span>' .' free '.'</span>!';
} else {
print ''. $NA .'<span>' .' add '.' '. $PR .' $ '. '</span>!';
}
print "<input style='width: 30px; height: 15px;' type='checkbox' name='extra[]' value='$NA'></td>\n";
//this java calculate the value add to extra ant outpot the total extra that pass to sql table
print "<input type='hidden' name='item_name'/>";
print "<input type='hidden' name='amount'/>";
print "<input style='width: 30px; height: 15px;' type='checkbox' onClick='ReadForm (this.form, false);' value='+$PR'></td>\n";
$i++;
}
?>
</div></div>
<?
} else {
}
?>
<!----->
<div class="item_add_cart">
<span class="title">total extra $</span>
<div class="content">
<?
print "<input style='color:#000;font-size:13px;' size='7' name='tot' type='text'/>";
?>
</div></div>
<!----->
my problem is that I have two table's one is the total price and one is the names I try to insert all value with one checkbox and it's not working
If I create 2 checkboxes and click on them then the value uploads ok
but I need only one checkbox that sends value from $NA to Table ext_name and total price from name='tot' to ext_price table
Please note that the above code doesn't work, #Majid Fouladpour suggests the following code instead.
/////////////////////////// FOR RXTRA ////////////////////////////////////////////////////////////
$sql = "SELECT ext_id,ext_price,ext_name,ext_description FROM tbl_extra ORDER by ext_id ASC";
$result = mysql_query($sql) or trigger_error(mysql_error(),E_USER_ERROR);
$number = mysql_num_rows($result);
$i = 0;
while ($number > > $i) {
$ID = mysql_result($result,$i,"ext_id");
$NA= mysql_result($result,$i,"ext_name");
$PR= mysql_result($result,$i,"ext_price");
$DES= mysql_result($result,$i,"ext_description");
//this part chack if the value is "0" and show with "tooltip" the value\/
if ( $PR == 0 ) {
print ''.$NA.'' <a href="#" class="tooltip2">'.$NA.'<span>' .' free '.'!';
.'</span></a>!';
} else {
print ''. <a href="#" class="tooltip2">'. $NA .'' '<span>' .' add '.' '. $PR .' $ '. '!';
</span></a>!';
}
print "\n";<input style='width: 30px; height: 15px;' type='checkbox' name='extra[]' value='$NA'></td>\n";
//this java calculate the value add to extra ant outpot the total extra that pass to sql table
print "";
<input type='hidden' name='item_name'/>";
print "";<input type='hidden' name='amount'/>";
print "\n";
<input style='width: 30px; height: 15px;' type='checkbox' onClick='ReadForm (this.form, false);' value='+$PR'></td>\n";
$i++;
}
?>
total >
</div></div>
<?
} else {
}
?>
<!----->
<div class="item_add_cart">
<span class="title">total extra $</span>
<div class="content";
>
<?
print "<input style='color:#000;font-size:13px;' size='7' name='tot' type='text'/>";
?>
>
</div></div>
<!----->
(I've made this answer community wiki so the rep doesn't go to me)

Categories