How can I echo the product_name? - php

Php3:
function createOrder()
{
echo $_POST['member_name']."<br/>";
echo $_POST['member_email']."<br/>";
echo $_POST['member_phone']."<br/>";
echo $_POST['product_id']."<br/>";
echo $products[[$_POST['product_id']-1]['product_name']]."<br/>";//how can i echo this row
echo $_POST['quantity']."<br/>";
I can print out including member_name,email,phone,and product_id but product_name still show blank in web page

you can try the below code.
index_value = $_POST['product_id']-1;
$products[index_value]['product_name'];
I hope it help!

Related

Disable select option when other specifig value is selected

I have a question by these given information:
private function loadIntervallOptions($intervallid = 1, $intervallfactor=1){
echo "<select name='intervallfactor'>";
for($intervallnumber=1;$intervallnumber<10;$intervallnumber++){
$checked = "";
if($intervallnumber== $intervallfactor){
$checked = "selected";
}
echo "<option $checked>$intervallnumber</option>";
}
echo "</select>";
echo "<select name='intervallid'>";
for($i=0;$i<count($this->todo_intervall);$i++){
echo "<option value='{$this->todo_intervall[$i]->getintervallid()}' ";
if($this->todo_intervall[$i]->getIntervallid() == $intervallid){
echo "selected";
}
echo ">{$this->todo_intervall[$i]->getIntervall()}</option>";
}
echo "</select>";
}
What I want to do:
If intervallid=1 I want to hide the select 'intervallfactor'. Is this possible?
Thank you in advance!
EDIT:
I'm trying this but it won't work
$('.intervallid').change(function(e) {
if ($('.intervallid').val()==1){
$('.intervallfactor').attr('disabled','disabled');
}
else{
$('.intervallfactor').removeAttr('disabled');
}
});
$('.intervallid').trigger('change');
You are trying to reference the html element using a class name .intervallid which doesnt exist.
either you should use $('select[name="intervalid"]) or add an id to the select from php and, use that to reference the element.
PHP
echo "<select name='intervallid' id='intervall_id'>";
JS
$('#intervall_id').attr('disabled', 'true')

How to display the php values into html table?

I have almost did the displaying of values.But i am getting an extra td I hope the complete code is right.
Can anyone see it once.
php
<?php
session_start();
$link = mysqli_connect('localhost','root','','hoteldetails');
$sno[]="";
$roomImage[]="";
$roomNo[] = "";
$hotelName[]="";
$roomPrice[]="";
$loc[]="";
if(isset($_POST['sub']))
{
// mysqli_s(elect_db($link, "hotels");
$location=$_POST['searchVal'];
$sql = "select * from roomdetails where Location = '$location'";
$sqldata= mysqli_query($link ,$sql);
while($row = mysqli_fetch_array($sqldata)){
$sno[]=$row['S.No'];
$roomImage[] = $row['RoomImage'];
$roomNo[] = $row['RoomNo'];
$hotelName[] = $row['HotelName'];
$roomPrice[] = $row['RoomPrice'];
$loc[] = $row['Location'];
}
//two arrays to display ,$combine = array_combine($one,$two);
}
?>
html
<?php
echo "<table border='1'>";
echo "<tr><th>Hotel</th><th>Location</th></tr>";
foreach($sno as $id => $key):
echo "<tr>";
echo "<td>";?><img src="<?php echo $roomImage[$id];?>" height="100" width="100"><?php echo "</td>";
echo "<td>".$roomNo[$id]."</td>";
echo "<td>".$hotelName[$id]."</td>";
echo "<td>".$roomPrice[$id]."</td>";
echo "<td>".$loc[$id]."</td>";
echo "</tr>";
endforeach;
echo "</table>";
//echo $html;
?>
Is there anything wrong in it . Please is this process is right to display the values from mysql into html.
First, format your code, using tools like http://phpbeautifier.com for example.
Next, you have lines that contain both an echo and a ?> ... <?php instruction that tells php to echo stuff without any PHP parsing.
This is quite unreadable and unmaintainable.
You should better go for some "templating-like" practices using only HTML and using PHP only to output some vars, like this:
<?php
foreach ($data as $item) {
?>
<tr>
<td>Name: <?php echo $item['name']; ?></td>
<td>Price: <?php echo $item['price']; ?></td>
</tr>
<?php
}
This would drastically improve readability, maintainability, and especially your capacity of debugging the code.
And finally, you should take care of your php.ini configuration and check that display_errors is set to 1 and error_reporting is set to E_ALL.
This way, any error like PHP - Notice : Undefined index ... will be shown in the output so you can debug it.

How to pass the name of the file as a parameter to the controller?

how can i pass the id as the name.I used this code.
<?php
$i = 1;
foreach ($view as $row)
{
echo "<tr>";
echo "<td>".$i."</td>";
echo "<a href="<?php echo base_url();?>admin/play/songs/<?php echo $row->audio"><td>". $row->audio . "</td>";
$i++;
echo "</tr>";
}
?>
I want to play the song when user press the name of the song.but i am not able to pass the name of the song to my controller "play".so please help and this is my controller where i want to pass the data.
class Play extends CI_Controller {
public function songs($name){
$data['name'] = $name;
$this->load->view('admin/play',$data);
}
You should grab id instead of name it will make your job easier.
<?php
$i = 1;
foreach ($view as $row)
{
echo "<tr>";
echo "<td>".$i."</td>";
echo "<a href="<?php echo base_url();?>admin/play/songs/<?php echo $row->id"><td>". $row->audio . "</td>";
$i++;
echo "</tr>";
}
?>
First of all you should know that you can pass the url you want after base_url as a parament in base_url like
base_url('admin/play/songs/');
Secondly you can pass anything to controller via this method
base_url('admin/play/songs/{$row->audio}');
Just excited to know if it works

jQuery code that has been written does not pass correct value based on clicking

I have dynamic list of item from database.
I generate the list using the while loop and echo it inside php.
The problem is the jQuery somehow only recognize the first item eventhough I click on the second item. I want to remove the clicked item directly after the ajax call is success.
this is my PHP code
while ($rowresult = mysqli_fetch_array($result)){
$id = $rowresult['id'];
$name = $rowresult['name'];
$brand= $rowresult['brand'];
$price = $rowresult['price'];
$qty = $rowresult['itemQuantity'];
$desc = $rowresult['description'];
$img = $rowresult['itemImage'];
echo "<div class=\"col-md-12\">";
echo "<div id=\"cartHeader\" class=\"rowresult cartInfo\">";
echo "<div class=\"col-md-12\">";
echo "<input type=\"text\" id=\"idValue\" name=\"idValue\" value=\" $id \"/>";
echo "<span class=\"remove\">×</span>";
echo "<p> $brand $name </p>";
echo "<div class=\"col-md-4\">";
echo "<img src=\"$img\" alt=\"Product Image\" width=\"50px\" height=\"50px\"></a>";
echo "</div>";
echo "<div class=\"col-md-8\">";
echo "<span class=\"cartDesc\"> $desc </span> <br>";
echo "<strong><span class=\"cartDesc\"> RM$price </span></strong>";
echo "</div>";
echo "</div>";
echo "</div>";
echo "</div>";
}
and this is my jQuery code
$(".removeAnchor").click(function(event){
event.preventDefault();
var itemID = $('#idValue').val();
var self = $(this);
$.ajax({
type: 'POST',
url: 'delete_item.php',
data: {itemID:itemID},
success: function(data){
$("#cartHeader").css({"background" : "red"});
console.log(itemID);
}
});
});
this is my delete_item.php
<?php
$title = "Item Details";
session_start();
include "config.php";
$itemID = $_POST['itemID'];
?>
P.S. I am also using bootstrap
Can somebody tell me how come when I click item that is from 1st row onward will still return value that is belong to 1st item?
ANy help given is highly appreciated
The quick and dirty way to fix the problem is:
var itemID = $(this).parent().find("#idValue").val();
Generally you should try keeping id attribute values unique accros much wider scope then just the element's parent.

$_GET OR escape string being unpredictable. Please explain?

i simply pass 3 values to the URL and while testing i was trying to echo them back to the screen but it will only echo each value once even though i have set it to echo at various points. once i escape the value it wont let me echo it. Why is this?
<?php
session_start();
if (isset($_SESSION['SESSION_C']) && ($_SESSION['SESSION_C']==true))
{
$getyear = $_GET["Year"];
echo $getyear; (IT WILL ECHO AT THIS POINT)
$getyear = mysql_real_escape_string($getyear);
echo $getyear; (BUT WONT ECHO HERE)
$getsite = $_GET["Site"];
echo $getsite;
$getsite = mysql_real_escape_string($getsite);
echo $getsite;
$getsite = str_replace(' ', '', $getsite);
echo $getsite;
$getdoc = $_GET["Doc"];
echo $getdoc;
$getdoc = mysql_real_escape_string($getdoc);
echo $getdoc;
}
else
{
echo "sessionerror";
}
?>
mysql_real_escape_string() requires a open connection to mysql. Otherwise it will return false. I guess var_dump($getdoc); will give you boolean(false).
You'll have to call mysql_connect() before that code.

Categories