Display item details after clicking on element - php

I am working on a project where we have a few items in the database that are displayed on a website and that works fine code is below:
<form method="post" action="store.php?action=add&ItemNo=<?php echo $products['ItemNo']; ?>">
<a href="product.php"><div class="products">
<img src="<?php echo $products['img'];?>" class="img-responsive"/>
<!-- this connects to the database and gets the image of item -->
<h4><?php echo $products['ItemName'];?></h4>
<h3>$ <?php echo $products['Price'];?></h3>
<input type="text" name="Quantity" class="form-control" value="1"/>
<!-- This creates an box where the default qnt is set to 1 -->
<input type="hidden" name="ItemName" value="<?php echo $products['ItemName']; ?>" />
<input type="hidden" name="Price" value="<?php echo $products['Price']; ?>" />
<input type="submit" name="addtocart" style="margin-top:5px;" class="btn btn-info"
value="Add to Cart"/>
<!-- this creates the btn that adds item to cart -->
</div>
</a>
</form>
Now I am trying to show more details about each product. All I want is when the user clicks any item they will be sent to item.php page where there will be more details about that specific item.
At this moment I got all info displaying in item.php and I am stuck.
I do not know how to word this question, maybe that is why I cannot find any help out on Google. I am new to PHP as I just started with it few weeks ago.

firstly
<a href="product.php?id=<?php echo $products['ItemNo']; ?>">
then on product.php check the url for $_GET['id'] and use that in your query.
SELECT * from foo where id=$id
but dont use the raw id or a non parametrised query unless you like being hacked

Related

Post Method only posting last value fetched from database

I am displaying list of items(multiple entries) from database on one page. I am trying to post all those values fetched from the database to another php file to add item to cart.
But when I press 'add to cart' button for any item in the list, it is only sending last item through POST. I know it is because of while loop, but I don't know correct way to implement it?
<form action="php/addToCart.php" method= "POST">
<?php
while($product=mysqli_fetch_assoc($featured)):
?>
<div class="col-md-5">
<h4><?= $product['title'] ?></h4>
<image src="php/marketplace_images/<?= $product['image'];?>" alt="<?= $product['title'];?>" height="300" width="300"/>
<p class="lprice"> Price $ <?= $product['price'];?></p>
<p class="desc"> Description: <?= $product['description'];?></p>
<p class="bname"> Brand Name: <?= $product['brandname'];?></p>
<input name="title" type="hidden" value="<?= $product['title'] ?>" />
<input name="price" type="hidden" value="<?= $product['price'] ?>" />
<input name="brandname" type="hidden" value="<?= $product['brandname'] ?>" />
<input name="image" type="hidden" value="<?= $product['image'] ?>" />
<input name="featured" type="hidden" value="<?= $product['featured'] ?>" />
<button type="submit" class="btn btn-success" data-toggle="modal" name="add">Add To Cart</button>
</div>
<?php endwhile;
?>
You're ending up with a single form with n (as many as items) fields with the same name, that are no longer separate. E.g. you'll have n fields named "title", n fields named "price" etc.
You'd never know which title belongs to which price.
Plus, the code you show only shows the rendering of the form, not what you're doing with it on submission (but that wouldn't make it better, as you can't distinguish between all the different inputs). If that code expects one title, it might take the last, or a random one.
So, if you want to send just a single item: Move your <form> and </form> into the while loop, so that you end up with a number of forms that can be individually submitted. In general I'd recommend against posting all of the data and just limit yourself to an id of an item, but that's beyond the scope of this question (but imagine what happens when I manipulate the price to 0 before submitting the item to the cart)

Pass variables to another php page using a button

So if someone is logged in my script reads the values and stores it and sets it as variables then I'm trying to make a registration page for something that members can register in.
The script is simple
<div id="english1"><p id="english1p">تأكد من بياناتك ثم اضغط رز الموافقة</p><br>
<form class="register2" action="includes/register2.inc.php" method="post" name="register2form"
<p class="username">اسم المستخدم: <?php echo htmlentities($_SESSION['username']); ?></p>
<p class="email">الايميل: <?php echo htmlentities($_SESSION['email']); ?></p>
<p class="age">السن: <?php echo htmlentities($_SESSION['age']); ?></p>
<p class="coursetype">الكورس المراد التسجيل فيه: <?php echo $coursename; ?></p>
<p class="paymethod">طرق الدفع:</p><ol><li>طريقة</li>
<li>طريقة</li>
<li>طريقة</li>
</ol>
<p class="sure">للتأكيد اضغط تسجيل</p>
<input class="register2button"
type="button"
value="تسجيل"
onclick="" />
</div>
Ignore the letters you don't understand, it's arabic.
So the script reads variables and then I want when the member clicks the submit button, the page POST the variables to includes/register2.inc.php without input as the variables are already set.
How can I do that?
If you want to keep your <p> tags you can store all the variables you want to pass to the next page in <input type="hidden" value="some value" /> These boxes will not be shown on the page, but will pass along data with any request you send to your server.
You can store your value in hidden element and pass it to next page.
<form action="page name" method="post">
<input type="hidden" name="username" value="<?php echo htmlentities($_SESSION['username']); ?>" />
<p class="username"> username : <?php echo htmlentities($_SESSION['username']); ?></p>
<input type="submit" name="submit" value="submit" >
</form>
Inside the form, instead of p you should use input for each parameter:
<input type="text" name="username" value="<?php echo htmlentities($_SESSION['username']); ?>"/>
You can kept this input hidden also like:
<input type="hidden" name="username" value="yourvalue"/>
These input field value won't pass in next page in $_POST if you will use p you have to use input for this.

how to add a remove button to file upload in joomla?

i'm new in coding joomla components i'm coding my first component at all and starting my knowledge from 0 in PHP
in my component i have 4 file uploaders (3 for images/pdf/etc.. and 1 for videos) and i would like to add a button to remove the file in case the person doesn't want the file anymore
can help me in this ?
here's the code of the form page:
<div class="control-group">
<div class="control-label"><?php echo $this->form->getLabel('video'); ?></div>
<div class="controls"><?php echo $this->form->getInput('video'); ?></div>
</div>
<?php if (!empty($this->item->video)) : ?>
[View File]
<?php endif; ?>
<input type="hidden" name="jform[video]" id="jform_video_hidden" value="<?php echo $this->item->video ?>" /> <input type="hidden" name="jform[ordering]" value="<?php echo $this->item->ordering; ?>" />
<input type="hidden" name="jform[state]" value="<?php echo $this->item->state; ?>" />
<input type="hidden" name="jform[checked_out]" value="<?php echo $this->item->checked_out; ?>" />
<input type="hidden" name="jform[checked_out_time]" value="<?php echo $this->item->checked_out_time; ?>" />
Any further information you need ask and i'll provide it
In your controller file, you should add a function called deleteImage that will delete the image from the filesystem. In your layout file (your view's template, as in "default.php"), you should add a link next to each uploaded file that goes like this:
index.php?option=com_pressrelease&task=deleteImage&id=imageId

editing HTML in Joomla pages

I'm no too used to or familiar with the Joomla system. SO I kind of need your help here. Here's my problem.
I'm building a site, but the template came with problems and the template makers refuse to accept they made a mistake. AS Templates Don't buy from these guys unless you don't care about being on your own if something happens.
Anyway, basically, the site's buttons are all out of alignment. I tried fixing them through CSS but no luck. Some things can't be fixed in the CSS files because they belong to the HTML part of it. But as some of you may know, Joomla is PHP not HTML. So my question is how do I fix an HTML line of code in Joomla?
To be specific:
I have this code in my site
<form name="logoutForm" method="post" action="/">
<button class="btl-buttonsubmit"onclick="document.logoutForm.submit();" name="Submit" style="">Log out</button>
<input type="hidden" value="com_users" name="option">
<input type="hidden" value="user.logout" name="task">
<input type="hidden" value="aW5kZXgucGhwP0l0ZW1pZD0xMDE=" name="return">
<input type="hidden" value="1" name="7b6cc3e246acff3e3943410a6f4919cf">
</form>
Since this is not PHP code or CSS I cant find it anywhere
Here are the screenshots of my two trouble areas
and
Thanks again
I'm re-editing this to add the code for the search results. Please review for me, refer to the screenshot as well to see what I see or go to my site and search for anything
<?php
defined('_JEXEC') or die;
$lang = JFactory::getLanguage();
$upper_limit = $lang->getUpperLimitSearchWord();
JHtml::_('bootstrap.tooltip');
?>
<form id="searchForm" action="<?php echo JRoute::_('index.php?option=com_search');?>" method="post">
<div class="btn-toolbar">
<div class="btn-group pull-left">
<input type="text" name="searchword" placeholder="<?php echo JText::_('COM_SEARCH_SEARCH_KEYWORD'); ?>" id="search-searchword" size="30" maxlength="<?php echo $upper_limit; ?>" value="<?php echo $this->escape($this->origkeyword); ?>" class="inputbox" />
</div>
<div class="btn group pull-left">
<button name="Search" onclick="this.form.submit()" class="button btn btn hasTooltip" title="<?php echo JText::_('COM_SEARCH_SEARCH');?>"><span class="icon-search"></span></button>
</div>
<input type="hidden" name="task" value="search" />
<div class="clearfix"></div>
</div>
<div class="searchintro<?php echo $this->params->get('pageclass_sfx'); ?>">
<?php if (!empty($this->searchword)):?>
<p><?php echo JText::plural('COM_SEARCH_SEARCH_KEYWORD_N_RESULTS', '<span class="badge badge-info">'. $this->total. '</span>');?></p>
<?php endif;?>
</div>
<fieldset class="phrases">
<legend><?php echo JText::_('COM_SEARCH_FOR');?>
</legend>
<div class="phrases-box">
<?php echo $this->lists['searchphrase']; ?>
</div>
<div class="ordering-box">
<label for="ordering" class="ordering">
<?php echo JText::_('COM_SEARCH_ORDERING');?>
</label>
<?php echo $this->lists['ordering'];?>
</div>
</fieldset>
<?php if ($this->params->get('search_areas', 1)) : ?>
<fieldset class="only">
<legend><?php echo JText::_('COM_SEARCH_SEARCH_ONLY');?></legend>
<?php foreach ($this->searchareas['search'] as $val => $txt) :
$checked = is_array($this->searchareas['active']) && in_array($val, $this->searchareas['active']) ? 'checked="checked"' : '';
?>
<label for="area-<?php echo $val;?>" class="checkbox">
<input type="checkbox" name="areas[]" value="<?php echo $val;?>" id="area-<?php echo $val;?>" <?php echo $checked;?> >
<?php echo JText::_($txt); ?>
</label>
<?php endforeach; ?>
</fieldset>
<?php endif; ?>
<?php if ($this->total > 0) : ?>
<div class="form-limit">
<label for="limit">
<?php echo JText::_('JGLOBAL_DISPLAY_NUM'); ?>
</label>
<?php echo $this->pagination->getLimitBox(); ?>
</div>
<p class="counter">
<?php echo $this->pagination->getPagesCounter(); ?>
</p>
<?php endif; ?>
</form>
mmm yea I can see what you mean. The template does have some issues. And that is not only your problem there are many places were you need to edit your stylesheet. But it's very hard to eyeball all of them and wrap all the solutions in one answer.
But as an advice you can use firebug if you are using firefox or google developer tools by pressing ctrl shift j to open them. You can edit some of your content live and see the changes that are needed to be done in specific places and then you just do them.
For example I found at the section CONTACT the upper right banner has it title popping out of the template. The fix is located in /templates/as002035/css/tmpl.custom.css line 11 by setting the padding to 0 0 20px.
When Creating an account a modal box splashes into my face. You need to fix that by editing the width and the height of that window again by using those tools.
Finally i cant see the logout button " form " since I can't register to your website due to the mail that was not sent in my e-mails. So probably you need a developer to fix all of these things.
I hope I helped a bit.
Besides the (good) advice already provided, there is a missing answer to your question: where does the HTML markup come from?
You will find it in one of two places: first check your template overrides (which I think is the case looking at your question), which would be located in
/templates/as002035/html/com_users/login/default_logout.php (logout component)
/templates/as002035/html/mod_login/ (login|logout module)
if they are not present, then the default Joomla layouts are in
/components/com_users/views/...
/modules/mod_login/tmpl
Added after clarification below, this is the answer the the comments.
you're missing a class "button" so the line of the module should be:
<input type="submit" value="Log out" class="button btn btn-primary" name="Submit">
instead of
<input type="submit" value="Log out" class="btn btn-primary" name="Submit">
(see the added "button"?). Did you find the template ? is it in the overrides? if you can just make that change you'll get the module fixed. As for the component logout form, http://www.guhlmotors.com/index.php?option=com_users
<button class="button btn" type="submit">Log out</button>
instead of
<button class="button" type="submit">Log out</button>

How to re-populate a form?

I have a user form that creates a drop down menu in Wordpress php. The form clears after it's submitted. How can I re-populate the form, when the edit pencil icon is clicked so the original info can be edited? As it is, because the form is cleared, it starts another menu.
There is one category and multiple names.
Thank you...if you need info, I will post it. I'm trying...
-A
I'm having a problem with this...as I mentioned, there is an "edit button" that creates a stupid edit form that some guy designed. I would like to repopulate the original form users filled out. I'm almost there. The info is is filled in boxes but they randomly overlay the drop down menu. It's not hitting inside the original form. "pp-website-edit" is the name of the "edit button".
<div class="pp-website-edit">
<form id="cat-edit-<?php echo $x; ?>" action="<?php $_SERVER['PHP_SELF'] ?>" method="post">
<input type="hidden" name="edit-category" value="<?php echo $indicat; ?>">
<INPUT TYPE="image" SRC="<?php bloginfo('url'); ?>/wp-content/themes/nebula/neb-style/images/arrow_045_small.png" HEIGHT="14" WIDTH="14" BORDER="0" ALT="Submit Form">
</form>
</div>
<div class="pp-website-edit">
<form id="wat-edit" action="<?php $_SERVER['PHP_SELF'] ?>" method="post">
<input type="hidden" name="edit-website" value="1">
<input type="hidden" name="ed-w-cat" value="<?php echo $indicat; ?>">
<input type="hidden" name="ed-w-label" value="<?php echo $finalresult[$y][name]; ?>">
<input type="hidden" name="ed-w-url" value="<?php echo $finalresult[$y][url]; ?>">
<INPUT TYPE="image" SRC="<?php bloginfo('url'); ?>/wp-content/themes/nebula/neb-style/images/arrow_045_small.png" HEIGHT="14" WIDTH="14" BORDER="0" ALT="Submit Form">
</form>
============================================================================
Site Category
Site Titles
Website url's
Forms that keep their values utilize some sort of peristance, either cookies, or a combination of querying the database for the values.
Either way you would need to then echo our the value inside the <input> tag.

Categories