How to set maximum attachment size in Squirrelmail - javascript

I am using squirrelmail and I have a max size limit 5mb. When User tries to upload file larger than this limit Squirrelmail shows warning message successfully.
The problem is when user tries to upload file larger than "post_max_size"(php.ini) value, my php page just refreshes and Squirrelmail doesn't display any warning message. Is there any way to handle files larger than "post_max_size" value?
<div class="compose">
<table cellspacing="0" class="table1" id="attachment_table">
<tr class="header">
<td class="fieldName" style="width: 1%; white-space: nowrap;">
<?php echo _("New attachment");?>:
</td>
<td class="fieldValue">
<?php
if($max_file_size != -1) {
echo '<input type="hidden" name="MAX_FILE_SIZE" value="' . $max_file_size . '" />';
}
?>
<input type="file" name="attachfile" size="48" <?php if ($accesskey_compose_attach_browse != 'NONE') echo 'accesskey="' . $accesskey_compose_attach_browse . '" '; ?>/>
<input type="submit" name="attach" <?php if ($accesskey_compose_attach != 'NONE') echo 'accesskey="' . $accesskey_compose_attach . '" '; ?>value="<?php echo _("Attach"); ?>" />
<?php
if($max_file_size != -1) {
echo '(' . _("Max.") . ' ' . humanReadableSize($max_file_size) . ')';
}
if (!empty($plugin_output['add_attachment_notes'])) echo $plugin_output['add_attachment_notes'];
?>
</td>
</tr>
<?php
if (!empty($plugin_output['attachment_inputs'])) echo $plugin_output['attachment_inputs'];
$attachment_count = 1;
foreach ($attachments as $attach) {
?>
<tr class="attachment">
<td class="fieldName" style="width: 1%">
<input type="checkbox" name="delete[]" id="delete<?php echo $attachment_count; ?>" accesskey="<?php echo ($attachment_count % 10); ?>" value="<?php echo $attach['Key']; ?>" />
</td>
<td class="fieldValue"><label for="delete<?php echo $attachment_count; ?>">
<?php echo $attach['FileName']; ?> - <?php echo $attach['ContentType']; ?> (<?php echo humanReadableSize($attach['Size']); ?>)
</label></td>
</tr>
<?php
$attachment_count++;
}
if (count($attachments) > 0) {
?>
<tr class="header">
<td colspan="2">
<input type="submit" name="do_delete" <?php if ($accesskey_compose_delete_attach != 'NONE') echo 'accesskey="' . $accesskey_compose_delete_attach . '" '; ?>value="<?php echo _("Delete Selected Attachments"); ?>" />
</td>
</tr>
<?php
}
?>
</table>
</div>

Related

PHP - Cart is not loading on the page

I have a website with a cart, the index file is as below:
<?php
session_start();
include_once 'product-action.php';
include_once 'cart.php';
$stmt = $conn->prepare("SELECT * FROM entertainment ORDER BY id ASC");
$stmt->execute();
$entertainment = $stmt->get_result();
echo '<table style="border: 1px solid #ddd;"><tr>';
if (!empty($entertainment)) {
foreach($entertainment as $product){
?>
<td style="border: 1px solid #ddd;">
<form method="post" action=""Location: " . "http://" . $_SERVER['HTTP_HOST'] . $location?action=add&id=<?php echo $product['id']; ?>">
<div class="product-image"><img src="<?php echo $product['image']; ?>" width="200" height="200"></div>
<div><strong><?php echo $product["title"]; ?></strong></div>
<div class="product-price"><?php echo "$".$product["offer_price"]; ?></div>
<div><input type="text" name="quantity" value="1" size="2" /><input type="submit" value="Add to cart" /></div>
</form>
</td>
<?php
}
}
echo '</tr></table>';
?>
The other 2 pages are as follows:
cart.php
<?php
if(!empty($_SESSION["cart_item"])){
$item_total = 0;
?>
<input type="button" value="Empty Cart">
<table cellpadding="10" cellspacing="1">
<tbody>
<tr>
<th><strong>Name</strong></th>
<th><strong>Quantity</strong></th>
<th><strong>Price</strong></th>
<th><strong>Action</strong></th>
</tr>
<?php
foreach ($_SESSION["cart_item"] as $item){
?>
<tr>
<td><strong><?php echo $item["product_title"]; ?></strong></td>
<td><?php echo $item["quantity"]; ?></td>
<td><?php echo "$".$item["price"]; ?></td>
<td>Remove Item</td>
</tr>
<?php
$item_total += ($item["price"]*$item["quantity"]);
}
?>
<tr>
<td colspan="3" align=right><strong>Total:</strong> <?php echo "$".$item_total; ?></td>
</tr>
</tbody>
</table>
<?php
}
?>
<?php
if(!empty($_SESSION["cart_item"])){
$item_total = 0;
?>
<input type="button" value="Empty Cart">
<table cellpadding="10" cellspacing="1">
<tbody>
<tr>
<th><strong>Name</strong></th>
<th><strong>Quantity</strong></th>
<th><strong>Price</strong></th>
<th><strong>Action</strong></th>
</tr>
<?php
foreach ($_SESSION["cart_item"] as $item){
?>
<tr>
<td><strong><?php echo $item["title"]; ?></strong></td>
<td><?php echo $item["quantity"]; ?></td>
<td><?php echo "$".$item["offer_price"]; ?></td>
<td>Remove Item</td>
</tr>
<?php
$item_total += ($item["offer_price"]*$item["quantity"]);
}
?>
<tr>
<td colspan="3" align=right><strong>Total:</strong> <?php echo "$".$item_total; ?></td>
</tr>
</tbody>
</table>
<?php
}
The product_action.php
<?php
if(!empty($_GET["action"])) {
$productId = isset($_GET['id']) ? htmlspecialchars($_GET['id']) : '';
$quantity = isset($_POST['quantity']) ? htmlspecialchars($_POST['quantity']) : '';
switch($_GET["action"]) {
case "add":
if(!empty($quantity)) {
$stmt = $conn->prepare("SELECT * FROM entertainment where id= ?");
$stmt->bind_param('i',$productId);
$stmt->execute();
$productDetails = $stmt->get_result()->fetch_object();
$itemArray = array($productDetails->id=>array('product_title'=>$productDetails->title, 'id'=>$productDetails->id, 'quantity'=>$quantity, 'price'=>$productDetails->offer_price));
if(!empty($_SESSION["cart_item"])) {
if(in_array($productDetails->id,array_keys($_SESSION["cart_item"]))) {
foreach($_SESSION["cart_item"] as $k => $v) {
if($productDetails->id == $k) {
if(empty($_SESSION["cart_item"][$k]["quantity"])) {
$_SESSION["cart_item"][$k]["quantity"] = 0;
}
$_SESSION["cart_item"][$k]["quantity"] += $quantity;
}
}
} else {
$_SESSION["cart_item"] = $_SESSION["cart_item"] + $itemArray;
}
} else {
$_SESSION["cart_item"] = $itemArray;
}
}
break;
case "remove":
if(!empty($_SESSION["cart_item"])) {
foreach($_SESSION["cart_item"] as $k => $v) {
if($productId == $v['id'])
unset($_SESSION["cart_item"][$k]);
}
}
break;
case "empty":
unset($_SESSION["cart_item"]);
break;
}
}
I am completely new to PHP. I tried searching alot but didn't find what I wanted. now the problem is while loading the page, the page is not displaying, its still loading. can anyone tell me how to fix it. any help would be great.

Sec0nd Data Accessing error in my view page

I have fetched some 10 records from database and accessed in view page using foreach.But i can only give approve to first record not other records.Why it is not happening.
this is my view page
<tr><tbody>
<?php`enter code here`
if(isset($result))
{
foreach($result as $value){?>
<td><?php echo $name;?> </td>
<td><?php echo $value->date1;?> </td>
<td><?php echo $value->purpose;?> </td>
<td><?php echo $value->amount;?> </td>
<td><?php echo $value->rep_date;?> </td>
<?php if($value->temp==1){?>
<td> Approved </td>
<td><?php echo $value->id;?> </td>
<?php } else {?>
<td>
<form method="POST" action="<?php echo base_url().'Admin/updatestatus';?>">
<input type="hidden" name ="hid" id="hid" value="<?php echo $value->id;?>">
<input type="submit" name="sub" id="sub" class="btn green" value="Approve" >
</td>
<?php }?>
<td> chat </td>
</tr>
<?php } }?>
</tbody>
This is my controller
function updatestatus()
{
$this->load->database();
$this->load->library('session');
$this->load->model('lpmodel');
$frmdate=$this->session->userdata('from');
$todate=$this->session->userdata('to');
$status=$this->session->userdata('stat');
$emp_id=$this->session->userdata('id');
$hidid=$this->input->post('hid');
echo $hidid;
$data=array(
'temp'=>'1');
$query=$this->lpmodel->ad_aprove_data($emp_id,$data,$hidid);
if($query==true)
{ //echo "hi";
?> <script>
alert('Approved');
</script><?php
//$value['result']=$this->lpmodel->selectapproverow($id);
$name=$this->session->userdata('name');
$value['name']=$name;
//$status=$this->session->set_userdata('stat');
$value['result']=$this->lpmodel->ad_selectreimb($emp_id,$status,$frmdate,$todate);
$this->load->view('ad_reimbursement',$value);
}
else
{// echo "error";
?> <script>
alert('Try Again');
</script><?php
$value['new']=$this->lpmodel->fetchname();
$this->load->view('ad_reimbursement',$value);
}
}

Datepicker for date of birth input field

I have a registration portal in which I change its view according to my template and now I want to add an input field to add date of birth with date picker how to use script in this registration page to add date picker.
<html>
<head>
<title></title>
<link href="catalog/view/theme/default/stylesheet/stylesheet1.css" rel=stylesheet type="text/css" />
<link href="catalog/view/theme/default/stylesheet/register.css" rel="stylesheet" type="text/css" />
<link href="catalog/view/theme/default/stylesheet/Menu.css" rel="stylesheet" type="text/css" />
<script>
$(function() {
$( "#datepicker" ).datepicker();
});
</script>
</head>
<body>
<div id="Holder">
<div id="Navbar">
<nav>
<ul>
<li>Login</li>
<li>Register</li>
<li>Forgot Password</li>
</ul>
</nav>
</div>
<?php if ($error_warning) { ?>
<div class="warning"><?php echo $error_warning; ?></div>
<?php } ?>
<?php echo $column_left; ?>
<div id="content"><?php echo $content_top; ?>
<h1><?php echo $heading_title; ?></h1>
<p><?php echo $text_account_already; ?></p>
<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data">
<div id="Details">
<div id="YourPersonalDetails">
<h2><?php echo $text_your_details; ?></h2>
<div class="content">
<table class="form">
<tr>
<td><span class="required">*</span> <?php echo $entry_emp_name; ?></td>
<td><input type="text" name="emp_name" value="<?php echo $emp_name; ?>" />
<?php if ($error_emp_name) { ?>
<span class="error"><?php echo $error_emp_name; ?></span>
<?php } ?></td>
</tr>
<tr>
<td><span class="required">*</span> <?php echo $entry_emp_ID; ?></td>
<td><input type="text" name="emp_ID" value="<?php echo $emp_ID; ?>" />
<?php if ($error_emp_ID) { ?>
<span class="error"><?php echo $error_emp_ID; ?></span>
<?php } ?></td>
</tr>
<tr>
<td><span class="required">*</span> Date Of Birth</td>
<td><input type="text" id="datepicker" name="dob" value="<?php echo $dob; ?>" size="12" id="dob" />
<?php if ($error_dob) { ?>
<span class="error">We require your date of birth!</span>
<?php } ?></td>
</tr>
<tr>
<td><span class="required">*</span> <?php echo $entry_email; ?></td>
<td><input type="text" name="email" value="<?php echo $email; ?>" />
<?php if ($error_email) { ?>
<span class="error"><?php echo $error_email; ?></span>
<?php } ?></td>
</tr>
<tr>
<td><span class="required">*</span> <?php echo $entry_mobile_no; ?></td>
<td><input type="text" name="mobile_no" value="<?php echo $mobile_no; ?>" />
<?php if ($error_mobile_no) { ?>
<span class="error"><?php echo $error_mobile_no; ?></span>
<?php } ?></td>
</tr>
</table>
</div>
</div>
<div id="YourAddress" >
<h2><?php echo $text_your_address; ?></h2>
<div class="content">
<table class="form">
<tr>
<td><?php echo $entry_company; ?></td>
<td><input type="text" name="company" value="<?php echo $company; ?>" /></td>
</tr>
<tr style="display: <?php echo (count($customer_groups) > 1 ? 'table-row' : 'none'); ?>;">
<td><?php echo $entry_customer_group; ?></td>
<td><?php foreach ($customer_groups as $customer_group) { ?>
<?php if ($customer_group['customer_group_id'] == $customer_group_id) { ?>
<input type="radio" name="customer_group_id" value="<?php echo $customer_group['customer_group_id']; ?>" id="customer_group_id<?php echo $customer_group['customer_group_id']; ?>" checked="checked" />
<label for="customer_group_id<?php echo $customer_group['customer_group_id']; ?>"><?php echo $customer_group['name']; ?></label>
<br />
<?php } else { ?>
<input type="radio" name="customer_group_id" value="<?php echo $customer_group['customer_group_id']; ?>" id="customer_group_id<?php echo $customer_group['customer_group_id']; ?>" />
<label for="customer_group_id<?php echo $customer_group['customer_group_id']; ?>"><?php echo $customer_group['name']; ?></label>
<br />
<?php } ?>
<?php } ?></td>
</tr>
<tr id="company-id-display">
<td><span id="company-id-required" class="required">*</span> <?php echo $entry_company_id; ?></td>
<td><input type="text" name="company_id" value="<?php echo $company_id; ?>" />
<?php if ($error_company_id) { ?>
<span class="error"><?php echo $error_company_id; ?></span>
<?php } ?></td>
</tr>
<tr>
<td><span class="required">*</span> <?php echo $entry_office_location; ?></td>
<td><input type="text" name="office_location" value="<?php echo $office_location; ?>" />
<?php if ($error_office_location) { ?>
<span class="error"><?php echo $error_office_location; ?></span>
<?php } ?></td>
</tr>
<tr>
<td><?php echo $entry_address_2; ?></td>
<td><input type="text" name="address_2" value="<?php echo $address_2; ?>" /></td>
</tr>
<tr>
<td><span class="required">*</span> <?php echo $entry_city; ?></td>
<td><input type="text" name="city" value="<?php echo $city; ?>" />
<?php if ($error_city) { ?>
<span class="error"><?php echo $error_city; ?></span>
<?php } ?></td>
</tr>
<tr>
<td><span id="postcode-required" class="required">*</span> <?php echo $entry_postcode; ?></td>
<td><input type="text" name="postcode" value="<?php echo $postcode; ?>" />
<?php if ($error_postcode) { ?>
<span class="error"><?php echo $error_postcode; ?></span>
<?php } ?></td>
</tr>
<tr>
<td><span class="required">*</span> <?php echo $entry_country; ?></td>
<td><select name="country_id">
<option value=""><?php echo $text_select; ?></option>
<?php foreach ($countries as $country) { ?>
<?php if ($country['country_id'] == $country_id) { ?>
<option value="<?php echo $country['country_id']; ?>" selected="selected"><?php echo $country['name']; ?></option>
<?php } else { ?>
<option value="<?php echo $country['country_id']; ?>"><?php echo $country['name']; ?></option>
<?php } ?>
<?php } ?>
</select>
<?php if ($error_country) { ?>
<span class="error"><?php echo $error_country; ?></span>
<?php } ?></td>
</tr>
<tr>
<td><span class="required">*</span> <?php echo $entry_zone; ?></td>
<td><select name="zone_id">
<option value=""><?php echo $text_select; ?></option>
<option value="1483">Delhi</option>
<option value="1505">UP</option>
</select>
<?php if ($error_zone) { ?>
<span class="error"><?php echo $error_zone; ?></span>
<?php } ?></td>
</tr>
</table>
</div>
</div>
</div>
<div id="YourPassword">
<h2><?php echo $text_your_password; ?></h2>
<div class="content">
<table class="form">
<tr>
<td><span class="required">*</span> <?php echo $entry_password; ?></td>
<td><input type="password" name="password" value="<?php echo $password; ?>" />
<?php if ($error_password) { ?>
<span class="error"><?php echo $error_password; ?></span>
<?php } ?></td>
</tr>
<tr>
<td><span class="required">*</span> <?php echo $entry_confirm; ?></td>
<td><input type="password" name="confirm" value="<?php echo $confirm; ?>" />
<?php if ($error_confirm) { ?>
<span class="error"><?php echo $error_confirm; ?></span>
<?php } ?></td>
</tr>
</table>
</div>
</div>
<div id="NewsLetter">
<h2><?php echo $text_newsletter; ?></h2>
<div class="content">
<table class="form">
<tr>
<td><?php echo $entry_newsletter; ?></td>
<td><?php if ($newsletter) { ?>
<input type="radio" name="newsletter" value="1" checked="checked" />
<?php echo $text_yes; ?>
<input type="radio" name="newsletter" value="0" />
<?php echo $text_no; ?>
<?php } else { ?>
<input type="radio" name="newsletter" value="1" />
<?php echo $text_yes; ?>
<input type="radio" name="newsletter" value="0" checked="checked" />
<?php echo $text_no; ?>
<?php } ?></td>
</tr>
</table>
</div>
</div>
<?php if ($text_agree) { ?>
<div class="buttons">
<div class="right"><?php echo $text_agree; ?>
<?php if ($agree) { ?>
<input type="checkbox" name="agree" value="1" checked="checked" />
<?php } else { ?>
<input type="checkbox" name="agree" value="1" />
<?php } ?>
<input type="submit" value="<?php echo $button_continue; ?>" class="button" />
</div>
</div>
<?php } else { ?>
<div class="buttons">
<div class="right">
<input type="submit" value="<?php echo $button_continue; ?>" class="button" />
</div>
</div>
<?php } ?>
</form>
<?php echo $content_bottom; ?></div>
<script type="text/javascript"><!--
$('input[name=\'customer_group_id\']:checked').live('change', function() {
var customer_group = [];
<?php foreach ($customer_groups as $customer_group) { ?>
customer_group[<?php echo $customer_group['customer_group_id']; ?>] = [];
customer_group[<?php echo $customer_group['customer_group_id']; ?>]['company_id_display'] = '<?php echo $customer_group['company_id_display']; ?>';
customer_group[<?php echo $customer_group['customer_group_id']; ?>]['company_id_required'] = '<?php echo $customer_group['company_id_required']; ?>';
customer_group[<?php echo $customer_group['customer_group_id']; ?>]['tax_id_display'] = '<?php echo $customer_group['tax_id_display']; ?>';
customer_group[<?php echo $customer_group['customer_group_id']; ?>]['tax_id_required'] = '<?php echo $customer_group['tax_id_required']; ?>';
<?php } ?>
if (customer_group[this.value]) {
if (customer_group[this.value]['company_id_display'] == '1') {
$('#company-id-display').show();
} else {
$('#company-id-display').hide();
}
if (customer_group[this.value]['company_id_required'] == '1') {
$('#company-id-required').show();
} else {
$('#company-id-required').hide();
}
if (customer_group[this.value]['tax_id_display'] == '1') {
$('#tax-id-display').show();
} else {
$('#tax-id-display').hide();
}
if (customer_group[this.value]['tax_id_required'] == '1') {
$('#tax-id-required').show();
} else {
$('#tax-id-required').hide();
}
}
});
$('input[name=\'customer_group_id\']:checked').trigger('change');
//--></script>
<script type="text/javascript"><!--
$('select[name=\'country_id\']').bind('change', function() {
$.ajax({
url: 'index.php?route=account/register/country&country_id=' + this.value,
dataType: 'json',
beforeSend: function() {
$('select[name=\'country_id\']').after('<span class="wait"> <img src="catalog/view/theme/default/image/loading.gif" alt="" /></span>');
},
complete: function() {
$('.wait').remove();
},
success: function(json) {
if (json['postcode_required'] == '1') {
$('#postcode-required').show();
} else {
$('#postcode-required').hide();
}
html = '<option value=""><?php echo $text_select; ?></option>';
if (json['zone'] != '') {
for (i = 0; i < json['zone'].length; i++) {
html += '<option value="' + json['zone'][i]['zone_id'] + '"';
if (json['zone'][i]['zone_id'] == '<?php echo $zone_id; ?>') {
html += ' selected="selected"';
}
html += '>' + json['zone'][i]['name'] + '</option>';
}
} else {
html += '<option value="0" selected="selected"><?php echo $text_none; ?></option>';
}
$('select[name=\'zone_id\']').html(html);
},
error: function(xhr, ajaxOptions, thrownError) {
alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
}
});
});
$('select[name=\'country_id\']').trigger('change');
//--></script>
<script type="text/javascript"><!--
$(document).ready(function() {
$('.colorbox').colorbox({
width: 640,
height: 480
});
});
//--></script>
</div>
</body>
</html>
You can use Jquery date picker. Look at this https://jqueryui.com/datepicker/
You just need to use
("#inputField").Datepicker()
Place your html anywhere in the form.
The line above should go inside script> tag
Update You need to include jquery files like this in your page's header section
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">

Cannot get radio button value on while loop

I am doing a simple quiz program using PHP and JavaScript(for its timer)
Here is my code
<!DOCTYPE html>
<html>
<head>
</head>
<body bgcolor="#CCFFCC">
<?php
session_start ();
$_SESSION['username'];
?>
<div id="wrap">
<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="table"; // Database name
$tbl_name="q_quiz"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// get value of id that sent from address bar
$id=$_GET['q_id'];
$sql="SELECT * FROM $tbl_name WHERE q_id='$id'";
$result=mysql_query($sql);
$rows=mysql_fetch_array($result);
?>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td><table width="100%" frame="box" cellpadding="3" cellspacing="1" bgcolor="#CCFFCC">
<tr>
<td bgcolor="#CCFFCC"><h3>Quiz Info : </h3></td>
</tr>
<tr>
<td bgcolor="#CCFFCC"><strong>Quiz Name : </strong><?php echo $rows['q_name']; ?></td>
</tr>
</table>
</td>
</tr>
</table>
<div style="font-weight: bold" id="quiz-time-left"></div>
<script type="text/javascript">
var max_time = <?php echo $rows['q_time'] ?>;
var c_seconds = 0;
var total_seconds =60*max_time;
max_time = parseInt(total_seconds/60);
c_seconds = parseInt(total_seconds%60);
document.getElementById("quiz-time-left").innerHTML='Time Left: ' + max_time + ' minutes ' + c_seconds + ' seconds';
function init(){
document.getElementById("quiz-time-left").innerHTML='Time Left: ' + max_time + ' minutes ' + c_seconds + ' seconds';
setTimeout("CheckTime()",999);
}
function CheckTime(){
document.getElementById("quiz-time-left").innerHTML='Time Left: ' + max_time + ' minutes ' + c_seconds + ' seconds' ;
if(total_seconds <=0){
setTimeout('document.quiz.submit()',1);
} else
{
total_seconds = total_seconds -1;
max_time = parseInt(total_seconds/60);
c_seconds = parseInt(total_seconds%60);
setTimeout("CheckTime()",999);
}
}
init();
</script>
</font>
Problem starts here
<br>
<?php
//so i will set a default score of 0.
$score = 0;
$tbl_name2="a_quiz";
$sql2="SELECT * FROM $tbl_name2 WHERE q_id='$id'";
$result2=mysql_query($sql2);
while($rows=mysql_fetch_array($result2)){
?>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td><table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr style='overflow:hidden; word-wrap:break-word;'>
<td bgcolor="lightgreen"><strong>Question:</strong></td>
<td bgcolor="lightgreen">:</td>
<td bgcolor="lightgreen" style="max-width: 1000px;"><?php echo $rows['q_question'] ?></td>
</tr>
<tr>
<td bgcolor="lightgreen"><strong>A</strong></td>
<td bgcolor="lightgreen">:</td>
<td bgcolor="lightgreen"><input type="radio" name="<?php echo $rows['q_question'] ?>" value="a"><?php echo $rows['a'] ?></td>
</tr>
<tr>
<td width="18%" bgcolor="lightgreen"><strong>B</strong></td>
<td width="5%" bgcolor="lightgreen">:</td>
<td width="77%" bgcolor="lightgreen"><input type="radio" name="<?php echo $rows['q_question'] ?>" value="b"><?php echo $rows['b'] ?></td>
</tr>
<tr>
<td width="18%" bgcolor="lightgreen"><strong>C</strong></td>
<td width="5%" bgcolor="lightgreen">:</td>
<td width="77%" bgcolor="lightgreen"><input type="radio" name="<?php echo $rows['q_question'] ?>" value="c"><?php echo $rows['c'] ?></td>
</tr>
<tr>
<td bgcolor="lightgreen"><strong>D</strong></td>
<td bgcolor="lightgreen">:</td>
<td bgcolor="lightgreen"><input type="radio" name="<?php echo $rows['q_question'] ?>" value="d"><?php echo $rows['d'] ?></td>
</tr>
<?php
In this part im getting the correct answer in the database (the answer is a)
$correct_answer == $rows['answer'];
This score = score + 1; is not working
if ($correct_answer==$_POST[$rows['q_question']]){
$score = $score + 1;
}
?>
<?php
$connection=mysql_connect('localhost', 'root','');
mysql_select_db('thesis');
$username= $_SESSION['username'];
$query6 = mysql_query("SELECT * FROM student WHERE username='$username'");
$row6 = mysql_fetch_assoc($query6);
$s_id = $row6['id'];
$name = $row6['name'];
$email = $row6['email'];
$position = $row6['position'];
?>
This is where I get all the data needed in the results
<p hidden>
<input type="text" name="s_id" value="<?php echo $s_id ?>">
<input type="text" name="q_id" value="<?php echo $rows['q_id'];?>">
<input type="text" name="score" value="<?php echo $score; ?>">
</p>
</table></td>
</tr>
<hr>
</table><br>
<?php
}
?>
<input type="submit" name="submit" value="Submit Answer" class="btn">
</form>
After hitting the submit button, im only getting s_id, q_id , but the score is still 0 even if I selected the correct answer
My problem here is getting the selected radio button and then comparing it to the answer(where is in the database)
I just did a quick mock up and this worked for me.
$answer = $_POST["'" . $rows['q_question'] . "'"];
if ($correct_answer == $answer)
{
$score++;
}

php shopping cart not displaying items in cart?

I'm trying to implement a php shopping cart on my site. I currently have the products page correctly reading from my database. When the cart is empty, the "There are no items in your cart," text displays, however when the cart has something in it, it displays the headers to this table, but no product information.
<form name="cartform" method="post" action="">
<input type="hidden" name="productid" />
<input type="hidden" name="command" />
<span id="cont_shop">
<input type="button" value="Continue Shopping" onclick="window.location.href='../Project/products.php'" />
</span>
<div id="formerror"><?php echo $message ?></div>
<table id="cart_table">
<?php
if(count($_SESSION['cart']))
{
echo '<tr>
<th>Name</th>
<th>Price</th>
<th>Quantity</th>
<th>Amount</th>
<th>Options</th>
</tr>';
$max = count($_SESSION['cart']);
for($i = 0; $i < $max; $i++)
{
$product_id = $_SESSION['cart'][$i]['productid'];
$quantity = $_SESSION['cart'][$i]['quantity'];
$product_name = get_product_name($dbc,$product_id);
$product_price = get_price($dbc,$product_id);
if($quantity == 0)
{
continue;
}
echo '<tr>
<td>' . $product_name . '</td>
<td>$ ' . $product_price . '</td>
<td><input type="text" name="product' . $product_id . '" value="' . $quantity . '" maxlength="4" size="2" /></td>
<td>$ ' . $product_price*$quantity . '</td>
<td>Remove Item</td>
</tr>';
}
echo '<tr>
<td colspan="2"><strong>Order Total: $' . get_order_total($dbc) . '</strong></td>
<td></td>
<td colspan="3" id="cart_buttons">
<input type="submit" value="Clear Cart" onclick="clear_cart()">
<input type="submit" value="Update Cart" onclick="update_cart()">
<input type="submit" value="Complete Order" onclick="complete_order()">
</td>
</tr>';
}
else
{
echo '<tr><td>There are no items in your shopping cart.</td></tr>';
}
?>
</table>
</form>
When I view the page source, all I see is the HTML render to here:
<table id="cart_table">
<tr>
<th>Name</th>
<th>Price</th>
<th>Quantity</th>
<th>Amount</th>
<th>Options</th>
</tr>
<?php
if(count($_SESSION['cart']))
{
?>
<form name="cartform" method="post" action="">
<input type="hidden" name="productid" />
<input type="hidden" name="command" />
<span id="cont_shop">
<input type="button" value="Continue Shopping" onclick="window.location.href='../Project/products.php'" />
</span>
<div id="formerror"><?php echo $message ?></div>
<table id="cart_table">
<?php
echo '<tr>
<th>Name</th>
<th>Price</th>
<th>Quantity</th>
<th>Amount</th>
<th>Options</th>
</tr>';
$max = count($_SESSION['cart']);
for($i = 0; $i < $max; $i++)
{
$product_id = $_SESSION['cart'][$i]['productid'];
$quantity = $_SESSION['cart'][$i]['quantity'];
$product_name = get_product_name($dbc,$product_id);
$product_price = get_price($dbc,$product_id);
if($quantity == 0)
{
continue;
}
echo '<tr>
<td>' . $product_name . '</td>
<td>$ ' . $product_price . '</td>
<td><input type="text" name="product' . $product_id . '" value="' . $quantity . '" maxlength="4" size="2" /></td>
<td>$ ' . $product_price*$quantity . '</td>
<td>Remove Item</td>
</tr>';
}
echo '<tr>
<td colspan="2"><strong>Order Total: $' . get_order_total($dbc) . '</strong></td>
<td></td>
<td colspan="3" id="cart_buttons">
<input type="submit" value="Clear Cart" onclick="clear_cart()">
<input type="submit" value="Update Cart" onclick="update_cart()">
<input type="submit" value="Complete Order" onclick="complete_order()">
</td>
</tr>';
?>
</table>
</form>
<?php
}
else
{
echo '<tr><td>There are no items in your shopping cart.</td></tr>';
}
?>

Categories

Resources