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>
Related
I'm a beginner seeking to solve this problem!
how to calculate the total of each item in the cart and how to calculate grand total?
this is my code
<td class="p-price first-row"><?php echo 'LBP '.number_format($r['product_price'],0)?>/KG</td>
<input type="hidden" class="unitprice" id="unitprice" value="<?php echo $r['product_price']?>">
<input type="text" id="quantity" class="quantity" value="<?php echo $weight ?>" readonly>
<td class="total-price first-row"><input class="total" id="total" readonly></td>
<input type="int" value="" id="grandtotal" class="grandtotal" readonly>
The variables you want arent quite clear. That said, it seems you're looking for something like:
$grandTotal = 0;
foreach ($_SESSION as $key => $values) {
if (strpos($key, "pid") !== false) {
$sql = "select * from products LEFT JOIN category on products.category_id = category.category_id where product_id = $_SESSION[$key]";
$result = $connect->query($sql);
$r = mysqli_fetch_assoc($result);
$w = "weight";
$w .= (string)$r['product_id'];
$weight = $_SESSION[$w];
$total = $r['product_price'] * $weight;
$grandTotal += $total;
}
}
I want to use onkeyup function inside for loop of a php script.
The value in the second box in each row should be 5, 10, 15, 20, 25 respectively irrespective of the entry in the first box. But I am not getting the desired result. The final result (ie 25) is showing for each box.
<?php
for ($i=1;$i<=5;++$i)
{
${"k3".$i}=5*$i;
?>
<html>
<script>
function gftt2(xx1){
var drr2=<?php echo ${"k3".$i}?>;
document.getElementById(xx1).value=drr2;
}
</script>
<input type="text" size="1" maxlength="" id="<?php echo "dd1{$i}"?>" name="dd1[$i]" onkeyup="gftt2('<?php echo "dd4{$i}"?>')"/>
<input type="text" size="1" maxlength="" id="<?php echo "dd4{$i}"?>" name="dd4[$i]" /><br/>
</html>
<?php } ?>
Please help.
<html>
<head>
<script>
function gftt2(id, value)
{
document.getElementById(id).value = value;
}
</script>
</head>
<body>
<?php
for ($i=1;$i<=5;++$i) {
$value = 5*$i;
?>
<input type="text" size="1" maxlength="" id="dd1<?php echo $i ?>" name="dd1[<?php echo $i ?>]" onkeyup="gftt2('dd4<?php echo $i ?>', '<?php echo $value?>')"/>
<input type="text" size="1" maxlength="" id="dd4<?php echo $i ?>" name="dd4[<?php echo $i ?>]" /><br/>
<?php
}
?>
</body>
</html>
It's untested. :o
I have one payment page where payment values will fill automatically . so i don't want allow that page to user to submit . how can i do auto submit of my page ?
my code is
include "configaration/config.php";
// Merchant key here as provided by Payu
$MERCHANT_KEY = "4LbrUG";
// Merchant Salt as provided by Payu
$SALT = "EhDp06FA";
// End point - change to https://secure.payu.in for LIVE mode
$PAYU_BASE_URL = "https://test.payu.in";
$sucess_url = 'http://localhost/georamble/success.php';
$failur_url = 'http://localhost/georamble/failure.php';
$action = '';
$posted = array();
if(!empty($_POST)) {
foreach($_POST as $key => $value) {
$posted[$key] = $value;
}
}
$formError = 0;
if(empty($posted['txnid'])) {
// Generate random transaction id
$txnid = substr(hash('sha256', mt_rand() . microtime()), 0, 20);
} else {
$txnid = $posted['txnid'];
}
$hash = '';
// Hash Sequence
$hashSequence = "key|txnid|amount|productinfo|firstname|email|udf1|udf2|udf3|udf4|udf5|udf6|udf7|udf8|udf9|udf10";
if(empty($posted['hash']) && sizeof($posted) > 0) {
if(
empty($posted['key'])
|| empty($posted['txnid'])
|| empty($posted['amount'])
|| empty($posted['firstname'])
|| empty($posted['email'])
|| empty($posted['phone'])
|| empty($posted['productinfo'])
|| empty($posted['surl'])
|| empty($posted['furl'])
|| empty($posted['service_provider'])
) {
$formError = 1;
} else {
//$posted['productinfo'] = json_encode(json_decode('[{"name":"tutionfee","description":"","value":"500","isRequired":"false"},{"name":"developmentfee","description":"monthly tution fee","value":"1500","isRequired":"false"}]'));
$hashVarsSeq = explode('|', $hashSequence);
$hash_string = '';
foreach($hashVarsSeq as $hash_var) {
$hash_string .= isset($posted[$hash_var]) ? $posted[$hash_var] : '';
$hash_string .= '|';
}
$hash_string .= $SALT;
$hash = strtolower(hash('sha512', $hash_string));
$action = $PAYU_BASE_URL . '/_payment';
}
} elseif(!empty($posted['hash'])) {
$hash = $posted['hash'];
$action = $PAYU_BASE_URL . '/_payment';
}
//data from previous page
if(isset($_POST['submit1']))
{
$packname = $_POST['pname'];
$package_price = $_POST['advn_pay'];
$person = $_POST['person'];
$date = $_POST['date'];
$date = date('Y-m-d', strtotime($date));
$package_id = $_POST['pkid'];
$wallet_amount = $_POST['wallet_amount'];
$wallet_amount_use = 0;
if(isset($_POST['wuamount']))
{
$wallet_amount_use = $_POST['wuamount'];
}
$ref_no =rand(20,10000000);
$pay_status = "unpaid";
$req_status = "requested";
$wallet_update_money= $wallet_amount - $wallet_amount_use;
$update= mysql_query("UPDATE wallet SET amount='$wallet_update_money' WHERE user_id='$login_session'");
//fetch a user name
$query = mysql_query("select * from user where user_id= '$login_session'");
if(!$query)
{
echo "error";
}
while($row=mysql_fetch_array($query))
{
$name = $row['first_name'];
$email = $row['email'];
$contact_number = $row['contact_number'];
}
$p_name=$_POST['name'];
$age=$_POST['age'];
for($i=0;$i<count($p_name);$i++)
{
$qry_add="INSERT INTO trvel_person_details (ref_user_id,ref_cus_name,cus_name,cus_age,travel_date)
VALUES ('$login_session', '$name','$p_name[$i] ','$age[$i]','$date')";
if(!mysql_query($qry_add))
{
die('Error: ' . mysql_error());
}
}
$total_amount= $package_price - $wallet_amount_use ; //total amount
$qry="INSERT INTO pack_req (user_id,user_name,package_id,pacakage_name,amount,date_jrny,no_person,refrence_number,payment_status,req_status)
VALUES ('$login_session', '$name','$package_id ','$packname','$total_amount','$date ','$person','$ref_no','$pay_status ','$req_status')";
if(!mysql_query($qry))
{
die('Error: ' . mysql_error());
}
}
?>
<html>
<head>
<script>
var hash = '<?php echo $hash ?>';
function submitPayuForm() {
if(hash == '') {
return;
}
var payuForm = document.forms.payuForm;
payuForm.submit();
}
</script>
</head>
<body onload="submitPayuForm()">
<h2>PayU Form</h2>
<br/>
<?php if($formError) { ?>
<span style="color:red">Please fill all mandatory fields.</span>
<br/>
<br/>
<?php } ?>
<form action="<?php echo $action; ?>" method="post" id="payuForm" name="payuForm">
<input type="hidden" name="key" value="<?php echo $MERCHANT_KEY ?>" />
<input type="hidden" name="hash" value="<?php echo $hash ?>"/>
<input type="hidden" name="txnid" value="<?php echo $txnid ?>" />
<table>
<tr>
<td><b>Mandatory Parameters</b></td>
</tr>
<tr>
<td>Amount: </td>
<td><input name="amount" id="amount" value="<?php echo (empty($posted['amount'])) ? $total_amount : $posted['amount']; ?>" /></td>
<td>First Name: </td>
<td><input name="firstname" id="firstname" value="<?php echo (empty($posted['firstname'])) ? $name : $posted['firstname']; ?>" /></td>
</tr>
<tr>
<td>Email: </td>
<td><input name="email" id="email" value="<?php echo (empty($posted['email'])) ? $email : $posted['email']; ?>" /></td>
<td>Phone: </td>
<td><input name="phone" value="<?php echo (empty($posted['phone'])) ? $contact_number : $posted['phone']; ?>" /></td>
<td>transation Id: </td>
<td><input name="txnid" value="<?php echo (empty($posted['txnid'])) ? $ref_no : $posted['txnid']; ?>" /></td>
</tr>
<tr>
<td>Product Info: </td>
<td colspan="3"><textarea name="productinfo"><?php echo (empty($posted['productinfo'])) ? $packname : $posted['productinfo'] ?></textarea></td>
</tr>
<tr>
<td>Success URI: </td>
<td colspan="3"><input name="surl" value="<?php echo (empty($posted['surl'])) ? $sucess_url : $posted['surl'] ?>" size="64" /></td>
</tr>
<tr>
<td>Failure URI: </td>
<td colspan="3"><input name="furl" value="<?php echo (empty($posted['furl'])) ? $failur_url : $posted['furl'] ?>" size="64" /></td>
</tr>
<tr>
<td colspan="3"><input type="hidden" name="service_provider" value="payu_paisa" size="64" /></td>
</tr>
<?php if(!$hash) { ?>
<td colspan="4"><input type="submit" value="Submit" /></td>
<?php } ?>
</tr>
</table>
</form>
even i have tried with one javascript to auto submit the form
<script type="text/javascript">
$(document).ready(function(){
$("#payuForm").submit();
});
</script>
but still its not redirecting . how can do this . any hint or help . sorry for my bad english
Create a hidden submit type button(i.e. display:none;), after page load through jquery click on it automatically(i.e. $('#submit').click() ), Create a function for clicking on submit button, call it after page loads...
EDIT:
HTML:
<form ...>
...
<input type="submit" id="submit" style="display:none;" />
</form>
Javascript:
function submit_click(){
$("#submit").click();
}
Now, when your auto form populating data's function called, call this function in last line submit_click();
try this
<script>
$(document).ready(function(){
$('#payuForm').trigger('submit');
})
</script>
Remember that some browser do not let you trigger the "submit" event if you have not an ENABLED submit button (be it an input or button, with type="submit")
Thus, you need to a button in the form, and if you don't want it to be shown, you can add
#button {
display: none;
visibility: hidden;
}
I'm trying to create a form for my system, user could add the numbers of input fields, the input fields are mostly drop down box with the options coming from tables in the database. The forms would insert the data into two different database. But it shows error of "Array to string conversion" Right now the data only inserted into the first table. Here's what I'd done so far
My form's code:
<form method="post" name="maklumat_akaun" action="proses_daftar_akaun.php">
<label for="NoAkaun">No. Akaun</label>
<input type="text" id="NoAkaun" name="NoAkaun" class="required input_field" required/>
<div class="cleaner_h10"></div>
<label for="KodDaerah">Daerah</label>
<?php
include('dbase.php');$sql = "SELECT KodDaerah, NamaDaerah FROM koddaerah";
$result = mysql_query($sql);
echo "<select name='KodDaerah' id='KodDaerah' class='input_field' required /><option></option>";
while($kod = mysql_fetch_array($result)){
echo "<option value=".$kod['KodDaerah'].">" .$kod['NamaDaerah']."</OPTION>";
}
echo "</select>";
?>
<div class="cleaner_h10"></div>
<label for="KodBahagian">Bahagian</label>
<?php
$sql = "SELECT KodBahagian, NamaBahagian FROM kodbahagian";
$result = mysql_query($sql);
echo "<select name='KodBahagian' id='KodBahagian' class='input_field' required /><option></option>";
while($kod = mysql_fetch_array($result)){
echo "<option value=".$kod['KodBahagian'].">" .$kod['NamaBahagian']."</OPTION>";
}
echo "</select>";
?>
<div class="cleaner_h10"></div>
<label for="KodKategori">Kategori Akaun</label>
<?php
$sql = "SELECT KodKategori, NamaKategori , SubKategori FROM kodkategori";
$result = mysql_query($sql);
echo "<select name='KodKategori' id='KodKategori' class='input_field' required /><option></option>";
while($kod = mysql_fetch_array($result)){
echo "<option value=".$kod['KodKategori'].">" .$kod['NamaKategori']." (".$kod['SubKategori'].")</OPTION>";
}
echo "</select>";
?>
<div class="cleaner_h10"></div>
<label for="Tarif">Tarif</label>
<input type="text" maxlength="4" size="4" id="Tarif" name="Tarif" class="required year_field" onkeyup="this.value=this.value.replace(/[^0-9.]/g,'')">
<div class="cleaner_h10"></div>
<!-----------------------------------------------------------//-->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
var max_fields = 25; //maximum input boxes allowed
var wrapper = $(".input_fields_wrap"); //Fields wrapper
var add_button = $(".add_field_button"); //Add button ID
var x = 1; //initial text box count
$(add_button).click(function(e){ //on add input button click
e.preventDefault();
if(x < max_fields){ //max input box allowed
x++; //text box increment
$(wrapper).append('<div>'+
'<td> <?php
$sql = "SELECT KodLokasi, NamaLokasi FROM kodlokasi";
$result = mysql_query($sql);
echo "<select name=\'KodLokasi[]\' id=\'KodLokasi[]\' class=\'input_field\' required ><option></option>";
while($kod = mysql_fetch_array($result)){
echo "<option value=".$kod['KodLokasi'].">" .$kod['NamaLokasi']. "</OPTION>";
}
echo "</select>";
?> </td> </tr>'+
'<tr> <td> <?php
$sql = "SELECT KodJenisAkaun, NamaJenisAkaun FROM kodjenisakaun";
$result = mysql_query($sql);
echo "<select name=\'KodJenisAkaun[]\' id=\'KodJenisAkaun[]\' class=\'input_field\' required ><option></option>";
while($kod = mysql_fetch_array($result)){
echo "<option value=".$kod['KodJenisAkaun'].">" .$kod['NamaJenisAkaun']. "</OPTION>";
}
echo "</select>";
?> </td>'+
'<td> <input type="text" name="NoTelefon[]" id="NoTelefon[]" value="0" class="required input_field"> </td>' +
'Batal</tr></div>'); //add input box
}
});
$(wrapper).on("click",".remove_field", function(e){ //user click on remove text
e.preventDefault(); $(this).parent('div').remove(); x--;
});
});
</script>
<fieldset>
<div class="input_fields_wrap">
<h3 class="add_field_button">Add More Fields</h3>
<table>
<tr>
<td> <label for="KodLokasi">Lokasi</label> </td> <td> <label for="KodJenisAkaun">Jenis Akaun</label> </td> <td> <label>No.Telefon:</label> </td>
</tr>
<tr>
<td> <?php
$sql = "SELECT KodLokasi, NamaLokasi FROM kodlokasi";
$result = mysql_query($sql);
echo "<select name='KodLokasi[]' id='KodLokasi' class='input_field' required /><option></option>";
while($kod = mysql_fetch_array($result)){
echo "<option value=".$kod['KodLokasi'].">" .$kod['NamaLokasi']."</OPTION>";
}
echo "</select>";
?>
</td>
<td> <?php
$sql = "SELECT KodJenisAkaun, NamaJenisAkaun FROM kodjenisakaun";
$result = mysql_query($sql);
echo "<select name='KodJenisAkaun[]' id='KodJenisAkaun' class='input_field' required /><option></option>";
while($kod = mysql_fetch_array($result)){
echo "<option value=".$kod['KodJenisAkaun'].">" .$kod['NamaJenisAkaun']."</OPTION>";
}
echo "</select>";
?>
</td>
<td> <input type="text" name="no_telefon[]" value="0" class="required input_field" onkeyup="this.value=this.value.replace(/[^0-9.]/g,'')"> </td>
</tr>
</table>
</div>
</fieldset>
<!-----------------------------------------------------------//-->
<div class="cleaner_h10"></div>
<div class="cleaner_h10"></div>
<input type="submit" value="Daftar" id="submit" name="register-submit" class="submit_btn" />
<input type="reset" value="Batal" id="reset" name="reset" class="submit_btn" />
</table>
</form>
While this is my code for the inserting process.
<?php
require("dbase.php");
if ($_POST) {
$NoAkaun = isset($_POST['NoAkaun']) ? $_POST['NoAkaun'] : '';
$KodBahagian = isset($_POST['KodBahagian']) ? $_POST['KodBahagian'] : '';
$Tarif = ISSET($_POST['Tarif']) ? $_POST['Tarif'] : '';
$KodDaerah = isset($_POST['KodDaerah']) ? $_POST['KodDaerah'] : '';
$KodKategori = isset($_POST['KodKategori']) ? $_POST['KodKategori'] : '';
$NoTelefon = isset($_POST['NoTelefon']) ? $_POST['NoTelefon'] : '';
$KodLokasi = isset($_POST['KodLokasi']) ? $_POST['KodLokasi'] : '';
$KodJenisAkaun = isset($_POST['KodJenisAkaun']) ? $_POST['KodJenisAkaun'] : '';
$akaun_idAkaun = isset($_POST['akaun_idAkaun']) ? $_POST['akaun_idAkaun'] : '';
$sql = mysql_query("INSERT INTO maklumatakaun VALUES ('', '$NoAkaun' , '$KodBahagian' , '$KodDaerah' , '$KodKategori' , '$Tarif' )");
$akaun_idAkaun = mysql_insert_id();
foreach ($NoTelefon AS $i => $telefon) {
$sql = mysql_query("INSERT INTO detailakaun VALUES ('', '$KodLokasi[$i]', '$KodJenisAkaun' , '$telefon' , '$akaun_idAkaun' )");
}
echo "<script type='text/javascript'> alert('AKAUN BERJAYA DIDAFTARKAN')</script> ";
echo "<script type='text/javascript'>window.location='pilih_kategori_daftar.php'</script>";
}
?>
Can anyone help me figure this out?
The error "Array to string conversion" means you are using an array as a string somewhere in your code. That error message is usually followed by a filename and line number which should help you narrow down your search. One helpful way to see what is contained within a variable is to use the following:
echo '<pre>'; print_r($stuff); die();
If the error is happening on a line inside of a while loop you should put the echo '' before the while and the die(); after so that you can see all instances of the problem within the loop.
I found your problem on this statement
$sql = mysql_query("INSERT INTO detailakaun VALUES ('', '$KodLokasi[$i]', '$KodJenisAkaun' , '$telefon' , '$akaun_idAkaun' )");
$KodJenisAkaun is an array and you use it as a string
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.