I'm trying to get class id for a dynamic table rows, the first row is working perfectly when it's selected, but the other rows are being fetched from java-scripts and are not working.
i.e. I can't get the class ids from the rows that is fetching from the java-script table row.
//this is jquery function am using....
$('#course_code').click(function(){
var course_id = $('#course_code').val();
if(course_id != '')
{
$.ajax({
url:"<?php echo base_url('Undergraduate_pg/fetch_course_code'); ?>",
method:"POST",
data:{course_id:course_id},
success:function(data){
$('#course_cod').val(data);
}
})
}
})
//this is the javascript table rows that is loading dynamically using click button..
function addrows(){
var row = ($('.detail tr').length-0)+1;
var tr = '<tr>' +
'<th>'+row+'</th>' +
'<td><select class="form-control course_code" id="course_code" name="course_code[]" required><option value="" selected="selected">Select Course Code</option><?php if (isset($pos)) { ?><?php foreach ($pos as $row) { ?>
echo "<option> <?php echo $row->course_code; ?></option>";<?php } } ?></select></td>' +
'<td><select class="form-control course_title" id="Title" name="course_title[]" required><option value="" selected="selected">Select Course Title</option><?php if (isset($pos)) { ?><?php foreach ($pos as $row) { ?>
echo "<option> <?php echo $row->course_title; ?></option>";<?php } } ?></select></td>' +
'<td><input type="number" class="form-control unit_elect" id="course_units" name="course_unit[]" value="" required></td>' +
'<td><select class="form-control course_status" id="course_status" name="course_status[]" required><option value="" selected="selected">Select Course Status</option><?php if (isset($pos)) { ?><?php foreach ($pos as $row) { ?>
echo "<option> <?php echo $row->course_status; ?></option>";<?php } } ?></select></td>' +
'<td colspan="3"><a class="btn btn-danger remove" >X</a></td>'+
'</tr>';
$('.detail').append(tr);
}
</script>
//i expect both static row and the dynamic row should be working once selected..
<!--this is the html code.. note, only this is working....-->
<tbody class="detail">
<td>1</td>
<td><select class="form-control course_code" id="course_code" name="course_code" required>
<option value="">--Select Course Code--</option>
<?php if (isset($pos)) { ?>
<?php foreach ($pos as $row) { ?>
echo "<option value="<?php echo $row->course_id; ?>"> <?php echo $row->course_code; ?></option>";
<?php } } ?>
</select>
<input type="text" class="form-control course_cod" id="course_cod" name="course_code[]" required>
</td>
I expect both static row and the dynamic row should be working once selected.
Related
I am just new in this using javascript and I am having a hard time in appending a value from a checkbox to a table cell with a inputbox inside. When I check one of the checkbox(fee_type) the table is populated by all the fee types from the data base and plus the the amount table must be populated in the amount and penalty table(please see attached image of the actual view form)... please help me with this problem.
Thank you very much in advance.
The Actual View Form
--Form View--
<div class="form-group">
<label>Grade Level</label>
<select id="class_id" name="class_id" class="form-control" >
<option value=""><?php echo $this->lang->line('select'); ?></option>
<?php foreach ($classlist as $class) { ?>
<option value="<?php echo $class['id'] ?>"
<?php if (set_value('class_id') == $class['id']) {
echo "selected =selected";
}
?>><?php echo $class['class'] ?></option>
<?php
$count++;
}
?>
</select>
<span class="text-danger"><?php echo form_error('class_id'); ?></span>
</div>
<div class="form-group">
<label for="exampleInputEmail1">Fee Group Name</label>
<select autofocus="" id="fee_groups_id" name="fee_groups_id" class="form-control" >
<option value=""><?php echo $this->lang->line('select'); ?></option>
</select><span class="text-danger"><?php echo form_error('fee_groups_id'); ?></span>
</div>
<div class="form-group">
<label>amount</label>
<input id="amount" name="amount" placeholder="" type="text" class="form-control" value="<?php echo set_value('amount'); ?>" />
<span class="text-danger"><?php echo form_error('amount'); ?></span>
</div>
<div class="form-group">
<label>Penalty</label>
<input id="penalty" name="penalty" placeholder="" type="text" class="form-control"/>
<span class="text-danger"><?php echo form_error('penalty'); ?></span>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="exampleInputEmail1">Fee type</label>
<?php foreach ($feetypeList as $feetype) { ?>
<div class="checkbox" >
<label style="display: inline-block; max-height: 25px; list-style: none; float: left; padding-top: 5px; width: 130px; margin-right: 40px;">
<input id="chkAdd" type="checkbox" name="feetype_id" value="<?php echo $feetype['id'] ?>" <?php echo set_checkbox('feetype', $feetype['id']); ?> ><?php echo $feetype['type'] ?>
</label>
</div>
<?php } ?>
<span class="text-danger"><?php echo form_error('feetype_id'); ?></span>
</div>
--Javascript--
<script type="text/javascript">
$(function () {
$(document).on("click", "#chkAdd", function () {
var lenght_div = $('#TextBoxContainer .app').length;
var div = GetDynamicTextBox(lenght_div);
$("#TextBoxContainer").append(div);
});
$(document).on("click", "#btnGet", function () {
var values = "";
$("input[name=DynamicTextBox]").each(function () {
values += $(this).val() + "\n";
});
});
});
function GetDynamicTextBox(value) {
var row = "";
$('#chkAdd:checked').each(function(){
row += '<tr class="tableGroup">';
<?php foreach ($feetypeList as $feetype) { ?>
row += '<td class="mailbox-name"><input class="form-control" name="feetype_id" value="<?php echo set_value('feetype_id', $feetype['type']); ?>"/></td>';
row += '<td class="mailbox-name"><input class="form-control" name="startDate" value="<?php echo set_value('startDate', $feetype['start_date']); ?>"/></td>';
row += '<td class="mailbox-name"><input class="form-control" name="endDate" value="<?php echo set_value('startDate', $feetype['end_date']); ?>"/></td>';
row += '<td class="mailbox-name"><input id="amountCell" name="amountCell" placeholder="" type="text" class="form-control"/></td>';
row += '<td class="mailbox-name"><input id="penaltyCell" name="penaltyCell" placeholder="" type="text" class="form-control"/></td>';
row += '</tr>';
<?php
$count++;
}
?>
});
row = row.substring();
$(".tableGroup").val(row);
return row;
}
</script>
<script type="text/javascript">
$(document).ready(function () {
$(".feemaster_form").submit(function (e)
{
$("#TextBoxContainer").html("");
$.ajax(
{
url: formURL,
type: "POST",
data: postData,
dataType: 'json',
success: function (data, textStatus, jqXHR)
{
if (data.st === 1) {
$.each(data.msg, function (key, value) {
$('.' + key + "_error").html(value);
});
} else {
var response = data.msg;
if (response && response.length > 0) {
for (i = 0; i < response.length; ++i) {
var feetype_id = response[i].feetype_id;
var row_id = response[i].id;
appendRow(feetype_id, row_id);
}
} else {
appendRow(0, 0, 0);
}
$('#chkAdd');
}
},
error: function (jqXHR, textStatus, errorThrown)
{
}
});
e.preventDefault();
});
});
function appendRow() {
var value = $('#TextBoxContainer .app').length;
var row = "";
row += '<td class="mailbox-name"><input class="form-control" name="feetype_id" value="<?php echo set_value('feetype_id', $feetype['type']); ?>"/></td>';
row += '<td class="mailbox-name"><input class="form-control" name="startDate" value="<?php echo set_value('startDate', $feetype['start_date']); ?>"/></td>';
row += '<td class="mailbox-name"><input class="form-control" name="endDate" value="<?php echo set_value('startDate', $feetype['end_date']); ?>"/></td>';
row += '<td class="mailbox-name"><input id="amountCell" name="amountCell" placeholder="" type="text" class="form-control"/></td>';
row += '<td class="mailbox-name"><input id="penaltyCell" name="penaltyCell" placeholder="" type="text" class="form-control"/></td>';
$count++;
row += '</tr>';
$("#TextBoxContainer").append(row);
}
</script>
Hi guys I'm having a hard time with this one please help me.
So I have an add row function where I can add dynamic rows to the form. My plan is to get the value of the Particulars with onchange event. So when you change the particular if will get the current value of the selected Particulars specifically on the selected row only.
The form looks like this:
So to test this out I'm trying to put the value in alert messages.
So this is the one I've done so far, I don't know if I'm making this correctly.
This is my html code.
<table class="table table-bordered" id="addSubPaymentTable">
<thead>
<tr>
<th >Particulars</th>
<th style="width:10%;"><button type="button" class="btn btn-success btn-sm" onclick="addPaymentRow()">Add Row</button></th>
</tr>
</thead>
<tbody>
<?php $arrayNumber = 0; for($x = 1; $x < 2; $x++) { ?>
<tr id="row<?php echo $x; ?>" class="<?php echo $arrayNumber; ?>">
<td class="form-group">
<select class="form-control particulars" name="subparticulars[<?php echo $x; ?>]" id="subparticulars<?php echo $x; ?>"
onchange="specificBalance('<?php echo $x; ?>')" /> //AS YOU CAN SEE I HAVE AN ONCHANGE EVENT HERE
<option value="">Select Particulars</option>
<?php foreach ($particularsData as $particulars)
{
?>
<option value="<?php echo $particulars['feetype_id']; ?>"> <?php echo $particulars['feetype_name']; ?> </option>
<?php
}
?>
</select>
<?php $arrayNumber++; } // /.foreach?>
</tbody>
So this is the function for the onchange event of Specific Balance
Javascript
// Get Specific Balance
function specificBalance(row = null)
{
var particular = $(this).val();
alert('Testing value is' +particular );
}
Please help me to get the value of the Particular, that is different in every row.
replace this line
<select class="form-control particulars" name="subparticulars[<?php echo $x; ?>]" id="subparticulars<?php echo $x; ?>"
onchange="specificBalance('')" />
with
<select class="form-control particulars" name="subparticulars[<?php echo $x; ?>]" id="subparticulars<?php echo $x; ?>"
onchange="specificBalance(this)" />
and in the jquery function use this
function specificBalance(row = null)
{
var particular = $(row).val();
alert('Testing value is' +particular );
}
Use this.value in onchange() function for select tag in HTML
<select class="form-control particulars" name="subparticulars[<?php echo $x; ?>]" id="subparticulars<?php echo $x; ?>"
onchange="specificBalance(this.value)" /> //AS YOU CAN SEE I HAVE AN ONCHANGE EVENT HERE
<option value="">Select Particulars</option>
<?php foreach ($particularsData as $particulars)
{
?>
<option value="<?php echo $particulars['feetype_id']; ?>"> <?php echo $particulars['feetype_name']; ?> </option>
<?php
}
?>
</select>
I'm developing an app that have a form that contains two selects populated dynamically with arrays.
The second select is disabled if there isn't a choice in the first of them and i need to filter the options of the second select respect the choice of the first.
Whereas I must to pass these values to another PHP page I mustn't do the filter using the value attribute.
I've tried to use a custom attribute but without results.
This is my code,
<tr>
<td style="color: white;">Seleziona data: </td>
<td>
<select class="form-control" name="data" id="select1">
<option value="prova" disabled selected> Scegli</option>
<?php for ($y=0; $y<count($giorni); $y++){ $giorno=$ giorni[$y];?>
<option value="<?php echo $giorno; ?>" id="<?php echo $y; ?>">
<?php echo $giorno; ?> </option>
<?php } ?>
</select>
</td>
</tr>
<tr>
<td style="color: white;">Seleziona ora: </td>
<td>
<select class="form-control" name="ora" id="select2" disabled>
<?php $count=1 ; while ($count <=3 ){ if ($count==1 ){ for ($g=0; $g<count($ora1); $g++){ ?>
<option id="<?php echo $count-1; ?>" value="<?php echo $ora1[$g]; ?>">
<?php echo $ora1[$g]; ?>
</option>
<?php } $count ++; } ?>
<?php if ($count==2 ){ for ($g=0; $g<count($ora2); $g++){ ?>
<option id="<?php echo $count-1; ?>" value="<?php echo $ora2[$g]; ?>">
<?php echo $ora2[$g]; ?>
</option>
<?php } $count ++; } ?>
<?php if ($count==3 ){ for ($g=0; $g<count($ora2); $g++){ ?>
<option id="<?php echo $count-1; ?>" value="<?php echo $ora3[$g]; ?>">
<?php echo $ora3[$g]; ?>
</option>
<?php } $count ++; } } ?>
</select>
</td>
</tr>
JAVASCRIPT:
<script>
document.getElementById('select1').onchange = function() {
document.getElementById('select2').disabled = false;
};
</script>
<script>
$("#select1").change(function() {
if ($(this).data('options') == undefined) {
/*Taking an array of all options-2 and kind of embedding it on the select1*/
$(this).data('options', $('#select2 option').clone());
}
var id = $(this).id();
var options = $(this).data('options').filter('[id=' + id + ']');
$('#select2').html(options);
});
</script>
How can I solve it?
Thanks
There is an issue with your html. There is more than one option with an identical id. On a html document, ids must be unique.
For the same reason, you cannot filter your options on the id value.
What you should do is to use a data- attribute instead the id attribute. This will allow you to filter on it.
You could use the json_encode function to generate JSON objects in your PHP code and create the select2 options dynamically on the client side.
<tr>
<td style="color: white;">Seleziona data: </td>
<td>
<select class="form-control" name="data" id="select1">
<option value="prova" disabled selected> Scegli</option>
<?php
foreach ($giorni as $key => $value) {
?>
<option value="<?php echo $value; ?>" id="<?php echo $key; ?>" ><?php echo $value; ?></option>
<?php
}
?>
</select>
</td>
</tr>
<tr>
<td style="color: white;">Seleziona ora: </td>
<td>
<select class="form-control" name="ora" id="select2" disabled></select>
</td>
</tr>
<script>
// the options object contains the possible option values for select2
// it can be accessed as an associative array using the selected value from select1
var options = {
"0" : <php echo json_encode($ora1, JSON_FORCE_OBJECT) ?>,
"1" : <php echo json_encode($ora2, JSON_FORCE_OBJECT) ?>,
"2" : <php echo json_encode($ora3, JSON_FORCE_OBJECT) ?>
};
// a helper variable to prevent unnecessary work
var prevSelectedValue = null;
// onChange handler for select1
document.getElementById('select1').onchange = function () {
var selectedValue = document.getElementById('select1').value;
if (selectedValue && (prevSelectedValue != selectedValue)) {
// select1 has changed so there is work to do
// 1 - get a handle on select2 to make code more legible
var select2 = document.getElementById('select2');
// 2 - remove all existing options
select2.options.length = 0;
// 3 - add new options
var obj = options[selectedValue];
// iterate through the object to get the keys and values
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
var newOption = document.createElement('option');
newOption.text = obj[key];
newOption.value = key;
select2.options.add(newOption);
}
}
// 4 - enable select2
select2.disabled = false;
// 5 - record select1 change in prevSelectedValue
prevSelectedValue = selectedValue;
}
};
</script>
My php code is as follows
<?php
if (isset($_POST["pitcode"]))
{
echo $_POST['pitcode'];
$pnetamt=0;
foreach ($_POST['txtwono1'] as $k => $v)
{
$pitcode=$_POST['pitcode'][$k];
$m_no=0;
$sql = mysql_query("select itrate from ITMAST where itcode='$pitcode'") or die(mysql_error());
$row = mysql_fetch_array($sql) or die(mysql_error());
$m_no = mysql_num_rows($sql);
if ($m_no!=0)
{
$sql = mysql_query("select itrate from ITMAST where itcode='$pitcode'") or die(mysql_error());
$row = mysql_fetch_row($sql);
$prate=$row[0];
}
}
}
?>
Javascript code is
<script type='text/javascript'>
function getitemcode()
{
var model=$('#itname').val();
document.frmwo.getElementById("txtitcode").value = model;
}
</script>
and HTML is
<html>
<td><input type="text" maxlength="3" size="2" name="txtwono1[]" class="rightJustified" value="<?php echo $pwono1; ?>"/></td>
<td><input type="text" maxlength="2" size="2" name="txtsno[]" class="rightJustified" value="<?php echo $psno; ?>"/></td>
<td>
<?php
$sql = "SELECT itcode,itname FROM ITMAST ";
$result = mysql_query($sql) or die(mysql_error());
echo "<select name='itname[]' id='itname' onchange='getitemcode()'>";
while ($row = mysql_fetch_array($result))
{
echo "<option value = '{$row['itcode']}'";
if ($pitcode == $row['itcode'])
echo "selected = 'selected'";
echo ">{$row['itname']}</option>";
}
echo "</select>";
?>
</td>
<td><input type="text" maxlength="8" size="8" name="txtitcode" id='txtitcode' class="rightJustified" value="<?php echo $pitcode; ?>"/></td>
<td><input type="text" maxlength="8" size="8" name="txtqty[]" class="rightJustified" onchange="calcitemamt()" value="<?php echo $pqty; ?>"/></td>
<td><input type="text" maxlength="6" size="6" name="txtrate[]" class="rightJustified" disabled="disabled" value="<?php echo $prate; ?>"/></td>
<td><input type="text" maxlength="7" size="7" name="txtamt[]" disabled="disabled" class="rightJustified" value="<?php echo $pamt; ?>"/></td>
</html>
My Problem is when I selects the Item from Combo, its value is not passed to php code from where I am getting price of that item and that price should come to in rate column. This should work for all rows of html table - How
Change html code
echo "<select name='itname[]' id='itname' onchange='getitemcode()'>";
with
echo "<select name='itname[]' id='itname' onchange='getitemcode(this.value)'>";
also change javascript code
<script type='text/javascript'>
function getitemcode()
{
var model=$('#itname').val();
document.frmwo.getElementById("txtitcode").value = model;
}
</script>
with
<script type='text/javascript'>
function getitemcode(model)
{
document.frmwo.getElementById("txtitcode").value = model;
}
</script>
I don't think that I have to use javascript here. But if this is the solution, I will take it.
I am able to echo the SESSION of Username in my pages. But when I try to call it again in order to get the detail of the user information, it doesn't work.
Here is the scenario when it doesn't work:
I echo the session of username in the clause of sql select with the code bellow:
$member_email = $_SESSION['member_email'];
$member_name = $_SESSION['member_name'];
$results = $mysqli->query("SELECT * FROM member_registry WHERE member_name='$member_name' And member_email='$member_email'");
$obj = $results->fetch_object();
echo '<tr><td colspan="6"><input type="text" readonly name="member_address" value="'.$obj->member_address_satu.'"/></td><tr>';
It works when I input the value of username directly in the clause of where of sql select
$results = $mysqli->query("SELECT * FROM member_registry WHERE member_name='Someone Name'");
I am very sure that the Session of username is fine. Becuase when I echo it, it shows the username:
<li>You Login as <?php echo $member_name;?></li>
If I can't use clause of WHERE member_name='$member_name' then I think I can use javascript to send the text from You login as <?php echo $member_name;? as the string to the clause.
How to do this, and how to solve this problem cleanly. Please help, I am just learning and learning and learning.
I hope anyone understand what I am asking here. Many thanks for all of that.
[UPDATED]
<?php
include_once("config.php");
$member_name = $_SESSION['member_name'];
$results = $mysqli->prepare("SELECT * FROM member_registry WHERE member_name=?");
$bind=$mysqli->bind_param('s',$member_name);
$mysqli->execute();
$obj = $results->fetch_object();
if(isset($_SESSION["products"])) {
$total = 0;
echo '<form action="cart-post-config.php" enctype="multipart/form-data" method="POST">';
foreach ($_SESSION["products"] as $cart_itm) {
echo '<tr>';
echo '<td></td>';
echo '<input type="hidden" name="member_name" value="'.$member_name.'"/>';
echo '<td><input type="text" readonly name="product_name[]" value="'.$cart_itm["name"].'"/></td>';
echo '<td><input type="text" readonly name="product_price[]" value="'.$cart_itm["price"].'"/></td>';
echo '<td><input type="text" readonly name="product_quantity[]" value="'.$cart_itm["qty"].'"/></td>';
$totalPerEach = ($cart_itm["price"]*$cart_itm["qty"]);
echo '<td><input type="text" readonly name="product_eachTotal[]" value="'.$totalPerEach.'"/></td>';
echo '<td>View Save Delete</td>';
echo '</tr>';
}
echo '<tr><td colspan="6"><input type="text" readonly name="member_address" value="'.$obj->member_address_satu.'"/></td><tr>';
echo '<tr><td colspan="6" style="text-align: right; background: yellowgreen;"><input type="submit" name="submit" /></td><tr>';
echo '</form>';//close the form
}
else {
echo 'Your Cart is empty'; }
?>
This is at the header of the page.
<?php
include("config.php");
$member_name = $_SESSION['member_name'];
$member_email = $_SESSION['member_email'];
?>
<ul id="list-logo-menu">
<li>Live Chat</li>
<li>Contact</li>
<li>You Login as <?php echo $member_name;?></li>
<li>Logout</li>
</ul>
[UPDATE 2]
<tr class="boder-table">
<td width="32"><u>No</u></td>
<td width="174"><u>Product Name</u></td>
<td width="103"><u>Price</u></td>
<td width="103"><u>Quantity</u></td>
<td width="103"><u>Total Price</u></td>
<td width="142"><u>Mark</u></td>
</tr>
$member_name = $_SESSION['member_name'];
$results = $mysqli->prepare("SELECT * FROM member_registry WHERE member_name=? ");
$bind=$mysqli->bind_param('s',$member_name);//bind them here
$result= $mysqli->execute();//execute your query
print_r($result).'<br/>';
if($result->num_rows<0)
{
$mysqli->error;
} else echo '<br/>'.$mysqli->num_rows;
if(isset($_SESSION["products"])) {
include_once("config.php");
$total = 0;
echo '<form action="cart-post-config.php" enctype="multipart/form-data" method="POST">';
foreach ($_SESSION["products"] as $cart_itm) {
echo '<tr>';
echo '<td></td>';
echo '<input type="hidden" name="member_name" value="'.$member_name.'"/>';
echo '<td><input type="text" readonly name="product_name[]" value="'.$cart_itm["name"].'"/></td>';
echo '<td><input type="text" readonly name="product_price[]" value="'.$cart_itm["price"].'"/></td>';
echo '<td><input type="text" readonly name="product_quantity[]" value="'.$cart_itm["qty"].'"/></td>';
$totalPerEach = ($cart_itm["price"]*$cart_itm["qty"]);
echo '<td><input type="text" readonly name="product_eachTotal[]" value="'.$totalPerEach.'"/></td>';
echo '<td>View Save Delete</td>';
echo '</tr>';
}
echo '<tr><td colspan="6"><input type="text" readonly name="member_address" value="'.$obj->member_address_satu.'"/></td><tr>';
echo '<tr><td colspan="6" style="text-align: right; background: yellowgreen;"><input type="submit" name="submit" /></td><tr>';
echo '</form>';//close the form
}
else {
echo 'Your Cart is empty'; }
?>
</table>
I just move the location where I should write the new sql statements.
<?php
if(isset($_SESSION["products"])) {
include_once("config.php");
$total = 0;
echo '<form action="cart-post-config.php" enctype="multipart/form-data" method="POST">';
foreach ($_SESSION["products"] as $cart_itm) {
echo '<tr>';
echo '<td></td>';
echo '<input type="hidden" name="member_name" value="'.$member_name.'"/>';
echo '<td><input type="text" readonly name="product_name[]" value="'.$cart_itm["name"].'"/></td>';
echo '<td><input type="text" readonly name="product_price[]" value="'.$cart_itm["price"].'"/></td>';
echo '<td><input type="text" readonly name="product_quantity[]" value="'.$cart_itm["qty"].'"/></td>';
$totalPerEach = ($cart_itm["price"]*$cart_itm["qty"]);
echo '<td><input type="text" readonly name="product_eachTotal[]" value="'.$totalPerEach.'"/></td>';
echo '<td>View Save Delete</td>';
echo '</tr>';
}
$member_name = $_SESSION['member_name'];
$results = $mysqli->query("SELECT * FROM member_registry WHERE member_name='$member_name'");
$obj = $results->fetch_object();
echo '<span class="product-name">'.$obj->member_address_satu.'</span></br>';
echo '<tr><td colspan="6"><input type="text" readonly name="member_address" value="'.$obj->member_address_satu.'"/></td><tr>';
echo '<tr><td colspan="6" style="text-align: right; background: yellowgreen;"><input type="submit" name="submit" /></td><tr>';
echo '</form>';//close the form
}
else {
echo 'Your Cart is empty'; }
?>
You need to use the bind_param
$member_name = $_SESSION['member_name'];
$results = $mysqli->prepare("SELECT * FROM member_registry WHERE member_name=?");
$bind=$mysqli->bind_param('s',$member_name);//bind them here
$result= $mysqli->execute();//execute your query
$row = $result->fetch_array(MYSQLI_ASSOC);
print_r($row).'<br/>'; // to see the result.
if($result->num_rows<0)
{
$mysqli->error;//to check the error
} else echo '<br/>'.$mysqli->num_rows;//to print the row.
if(isset($_SESSION["products"])) {
include_once("config.php");
$total = 0;
echo '<form action="cart-post-config.php" enctype="multipart/form-data" method="POST">';
foreach ($_SESSION["products"] as $cart_itm) {
echo '<tr>';
echo '<td></td>';
echo '<input type="hidden" name="member_name" value="'.$member_name.'"/>';
echo '<td><input type="text" readonly name="product_name[]" value="'.$cart_itm["name"].'"/></td>';
echo '<td><input type="text" readonly name="product_price[]" value="'.$cart_itm["price"].'"/></td>';
echo '<td><input type="text" readonly name="product_quantity[]" value="'.$cart_itm["qty"].'"/></td>';
$totalPerEach = ($cart_itm["price"]*$cart_itm["qty"]);
echo '<td><input type="text" readonly name="product_eachTotal[]" value="'.$totalPerEach.'"/></td>';
echo '<td>View Save Delete</td>';
echo '</tr>';
}
echo '<tr><td colspan="6"><input type="text" readonly name="member_address" value="'.$obj->member_address_satu.'"/></td><tr>';
echo '<tr><td colspan="6" style="text-align: right; background: yellowgreen;"><input type="submit" name="submit" /></td><tr>';
echo '</form>';//close the form
}
else {
echo 'Your Cart is empty'; }
?>
</table>
#klaudia,First check your mysqli connection to database is proper or not. The sample connection for mysqli as below.
$mysqli = mysqli_connect("localhost","mysql_user","mysql_password","database");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
Then Check your session details proper or not via print session.
echo $_SESSION['member_email'];
echo $_SESSION['member_name'];
Then you need to fire below query as per your requirement.
//Below is sample membername & email,you can put your session data in below two line.
$member_email = 'user#user.com';
$member_name = 'test';
//For Your scenario it would be like below. (Rememeber you need to put session_start() in top of the page)
$member_email = $_SESSION['member_email'];
$member_name = $_SESSION['member_name'];
$results = $mysqli->query("SELECT * FROM member_registry WHERE member_name='$member_name' And member_email='$member_email'");
$obj = $results->fetch_object();
echo "<pre>";print_r($obj);
Please try above & let me know if still any issues.