开发者

insert to database with checkbox

开发者 https://www.devze.com 2023-03-05 17:07 出处:网络
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 ////////////////////////////////////////////////////////////

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 '<a h开发者_如何学Pythonref="#" class="tooltip2">'.$NA.'<span>' .' free '.'</span></a>!';
  } else {
    print '<a href="#" class="tooltip2">'. $NA .'<span>' .' add '.'  '. $PR .' $ '. '</span></a>!';
}
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)

0

精彩评论

暂无评论...
验证码 换一张
取 消