I have this piece of code:
<?php
$counter = 0;
while ($row = mysql_fetch_array($bim_coupons_price)){?>
<div class="clone">
<div id="start_date_countdown">
<span>No</span>
<input id="start_datetimepicker<?php echo $counter?>" type="text" name="start_date_countdown[]" value="<?php if(isset($_POST['start_date_countdown'][0])){echo $_POST['start_date_countdown'][0];}else{echo $row['start_date_countdown'];}?>"/>
</div>
<div id="end_date_countdown">
<span>Līdz</span>
<input id="end_datetimepicker<?php echo $counter?>" type="text" name="end_date_countdown[]" value="<?php if(isset($_POST['end_date_countdown'][0])){echo $_POST['end_date_countdown'][0];}else{echo $row['end_date_countdown'];}?>"/>
</div>
<div id="price_container">
<span>Cena</span>
<input type="text" id="price_new" name="price_new[]" value="<?php echo $row['price_new']?>"/>
</div>
</div>
<div style="clear:both;"></div>
<?php $counter++; } ?>
Problem is there that this while loop will executes 3 times and I need to change $_POST['start_date_countdown'][0]) every time to $_POST['start_date_countdown'][1]), $_POST['start_date_countdown'][2]) etc...
How I can do that?
Just change $_POST['INDEX_KEY'][0] to $_POST['INDEX_KEY'][$counter]. INDEX_KEY pertains to start_date_countdown and end_date_countdown
Well u are already are using variable $counter.You can make it $_POST['start_date_countdown'][$counter]
Related
I have a page which is showing around 3000 entries. what i am trying to do is when i click on filter button the data of only that entry will change. but currently, when i click on filter button the data of all the entries are changing.
here is my code:-
<?php
include("config.php");
$sql="SELECT * FROM inventory_details where status ='0' limit 0,100";
$query=mysqli_query($conn, $sql);
while($row=mysqli_fetch_assoc($query)){
$id = $row['id'];
$inventorybackground = $row['inventorybackground'];
$inventorycolor = $row['inventorycolor'];
$firm_name = $row['firm_name'];
$position = $row['position'];
$city = $row['city'];
$catagory_name = $row['catagory_name'];
$supplier = $row['supplier'];
if (isset($_POST['update'])){
$position=$_POST['position'];
$update_query="UPDATE inventory_details SET position ='$position' WHERE id='$id'";
$run_update=mysqli_query($conn, $update_query);
}
?>
<div class="container">
<div class="row" style="background-color: <?php echo $inventorybackground; ?> !important; color: <?php echo $inventorycolor; ?>; padding-top: 10px;">
<form class="form-horizontal" method="post" enctype="multipart/form-data">
<div class="col-md-1 inventory-data">
<input type="text" class="form-control" id="id" name="id" value="<?php echo $id;?>" disabled>
</div>
<div class="col-md-3 inventory-data">
<input type="text" class="form-control" id="firm_name" name="firm_name" value="<?php echo $firm_name;?>" disabled>
</div>
<div class="col-md-1 inventory-data">
<input type="text" class="form-control" id="position" name="position" value="<?php echo $position;?>">
</div>
<div class="col-md-1 inventory-data">
<input type="text" class="form-control" id="city" name="city" value="<?php echo $city;?>" disabled>
</div>
<div class="col-md-2 inventory-data">
<input type="text" class="form-control" id="catagory_name" name="catagory_name" value="<?php echo $catagory_name;?>" disabled>
</div>
<div class="col-md-2 inventory-data">
<input type="text" class="form-control" id="supplier" name="supplier" value="<?php echo $supplier;?>" disabled>
</div>
<div class="col-md-2 inventory-data">
<button type="submit" name="update" value="update" class="btn btn-primary">Filter</button>
</div>
</form>
</div>
</div>
<?php } ?>
Currently, i am only trying to change the position and I think, this problem is because of loop.
Please help me out, Thanks in advance.
When you click the button, the entire list is updated on your loop to list the rows.
Add this code at your page to detect the form POST to do the update:
if ($_SERVER["REQUEST_METHOD"] === "POST") {
// perform update here
$id = $_POST['id'];
$position = $_POST['position'];
$update_query="UPDATE inventory_details SET position ='$position' WHERE id='$id'";
$run_update=mysqli_query($conn, $update_query);
}
Edit:
Your input can't be disabled, try to use input hidden to pass id to POST:
<input type="hidden" id="id" name="id" value="<?php echo $id;?>">
If you need to show the id on input text, change the name to different name istead of id, because it will be used from input hidden
while($row=mysqli_fetch_assoc($query)){
This has ending bracket on the end. So you are basically looping through all the data and updating it all. Do the update query outside of loop.
$update_query="UPDATE inventory_details SET position ='$position' WHERE id='$id'";
You have SQL injection vulnerability here, please use prepared statements.
https://www.w3schools.com/php/php_mysql_prepared_statements.asp
If id is integer, you dont have to put quotation marks around it
I want to block access to a PHP page.
I'm doing that with this way: If you been logged in, PHP check if exist a cookie, and doing echo the HTML, else it's redirecting you to login page.
Here is the code but when I'm trying to set value attribute equal to a PHP variable, I'm getting back the php code ex.""
The PHP code inside the selection tag, isn't working either!
<?php
if(isset($_COOKIE['User_Email_Cookie'])) {
session_start();
$name =$_SESSION['User_FullName'];
$phone =$_SESSION['User_Phone'];
echo '<!DOCTYPE html>
<html>
<body>
<h1 class="Title">Reserve a table now!</h1>
<center>
<form action="reservation2.php" method="post">
<div class="App">
<div class="User">
<h2 style="text-align:left;"> Contact:</h2>
<input type="text" id="Name" placeholder="Full Name" value="<?php echo $name ?>" required>
<input type="tel" id="Phone" placeholder="Phone" value="<?php echo $phone ?>" required>
</div>
<div class="DatePeople">
<h2> Choose the Date:</h2>
<input type="date" id="Date" name="TableDate">
<select name="Time" class="time">
<option>19:00</option>
<option>19:30</option>
<option>20:00</option>
<option>20:30</option>
<option>21:00 </option>
<option>21:30</option>
<option>22:00</option>
</select>
<h2 style="margin-top:0px;">Choose Table, People: <a target="_blank" href="media/diagram.png"><img src="media/info.png" width="23px"></a></h2>
<select name="TableNum" class="table">
<?php
include \'connectDb.php\'; #Eisagwgi stoixeiwn gia syndesi me ti vasi
$result=mysqli_query($con,"SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.Columns WHERE
TABLE_NAME = \'available\' AND COLUMN_NAME NOT IN (\'Date\', \'Time\')");
while($row = mysqli_fetch_array($result)) {
echo \'<option>\'.$row[0].\'</option>\';
}
?>
</select>
<input type="number" id="seats" name="People" min="2" max="8" value="4" >
</div>
</div>
<div>
<input type="submit" name="Submit" value="Reserve">
<a class="button" href="logout.php">Log out</a>
</div> </center>
</form>
else {
header("location: reservation.php");
}
The issue is that you echo the html, and inside that echo you combine "inner" php tags (value="<?php echo $name ?>" instead of value="' . $name . '" for example).
Change:
echo '<!DOCTYPE html>
To:
?><!DOCTYPE html>
And at the end, where you have:
</form>
Replace it with
</form></body></html><?php
The above code allows you combine html markup, by closing the php tags in the correct place, without you having to echo it with php.
Read the documentation for more details.
Please try this code
<?php
if(isset($_COOKIE['User_Email_Cookie'])) {
session_start();
$name =$_SESSION['User_FullName'];
$phone =$_SESSION['User_Phone'];
?>
<!DOCTYPE html>
<html>
<body>
<h1 class="Title">Reserve a table now!</h1>
<center>
<form action="reservation2.php" method="post">
<div class="App">
<div class="User">
<h2 style="text-align:left;"> Contact:</h2>
<input type="text" id="Name" placeholder="Full Name" value="<?php echo $name ?>" required>
<input type="tel" id="Phone" placeholder="Phone" value="<?php echo $phone ?>" required>
</div>
<div class="DatePeople">
<h2> Choose the Date:</h2>
<input type="date" id="Date" name="TableDate">
<select name="Time" class="time">
<option>19:00</option>
<option>19:30</option>
<option>20:00</option>
<option>20:30</option>
<option>21:00 </option>
<option>21:30</option>
<option>22:00</option>
</select>
<h2 style="margin-top:0px;">Choose Table, People: <a target="_blank" href="media/diagram.png"><img src="media/info.png" width="23px"></a></h2>
<select name="TableNum" class="table">
<?php
include \'connectDb.php\'; #Eisagwgi stoixeiwn gia syndesi me ti vasi
$result=mysqli_query($con,"SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.Columns WHERE
TABLE_NAME = \'available\' AND COLUMN_NAME NOT IN (\'Date\', \'Time\')");
while($row = mysqli_fetch_array($result)) {
echo \'<option>\'.$row[0].\'</option>\';
}
?>
</select>
<input type="number" id="seats" name="People" min="2" max="8" value="4" >
</div>
</div>
<div>
<input type="submit" name="Submit" value="Reserve">
<a class="button" href="logout.php">Log out</a>
</div> </center>
</form>
<?php
else {
header("location: reservation.php");
}
?>
i have been displaying two session messages in one page, rating. One message is displayed in every refresh showing the likes and dislikes. the other message in displayed once the rating form is submitted, the problem is once i submit the rating form the message displaying the rating isn't displayed. why is so??? can't i use two sessions in a page?? thanks
coding
<?php
if(!empty($_SESSION['error_msg'])){?>
<div style="text-align: center"><?php echo $_SESSION['error_msg'];?></div>
<?
session_unset($_SESSION['error_msg']);
}
?>
if(!empty($_SESSION['rate_msg'])){
echo $_SESSION['rate_msg'];
session_unset($_SESSION['rate_msg']);
}
?>
<form name="rating_form" action="" method="post">
<input type="hidden" name="g_id" value="<?php echo $ratings['gallery_id'];?>"/>
<input type="hidden" name="g_image" value="<?php echo $ratings['gallery_image'];?>"/>
<div style="text-align: center">
<input type="radio" name="rating" value="Hot" onclick="document.rating_form.submit();">Hot</input>
<input type="radio" name="rating" value="Not" onclick="document.rating_form.submit();">Not</input>
</div>
</form>
sorry i think my code is a bit confusing
my actual code looks like this
<div class="top_model">
<h1>Model Ratings</h1>
<?php
if(!empty($_SESSION['error_msg'])){?>
<div style="text-align: center"><?php echo $_SESSION['error_msg'];?></div>
<?
session_unset($_SESSION['error_msg']);
}
?>
<ul class="homemodel_thumbs">
<div style="text-align: right">
</div>
<?php
if(!empty($ratingArr)){
foreach($ratingArr as $ratings){
?>
<li><img src="<?php echo base_url();?>images/gallery/large/<?php echo $ratings['gallery_image'];?>" alt="<?php echo $ratings['gallery_image'];?>" class="center_image"/>
<p> </p>
<?php
if(!empty($_SESSION['rate_msg'])){
echo $_SESSION['rate_msg'];
//session_unset($_SESSION['rate_msg']);
}
?>
<form name="rating_form" action="" method="post">
<input type="hidden" name="g_id" value="<?php echo $ratings['gallery_id'];?>"/>
<input type="hidden" name="g_image" value="<?php echo $ratings['gallery_image'];?>"/>
<div style="text-align: center">
<input type="radio" name="rating" value="Hot" onclick="document.rating_form.submit();">Hot</input>
<input type="radio" name="rating" value="Not" onclick="document.rating_form.submit();">Not</input>
</div>
</form>
</li>
<?php
}
}
?>
</ul>
this problem is solved. of the two session message for the one i used php session while for the another one i used code igniter session. sorry if i haven't mentioned i am using ci. anyways thanks everyone for the help :)
You're unsetting your rating message after you display it:
session_unset($_SESSION['rate_msg']);
This means it's not available after you've posted back the form unless you re-populate it again.
Remove this and i suspect it'll work.
You have an excess ?> :
<?php
if(!empty($_SESSION['error_msg'])){?>
<div style="text-align: center"><?php echo $_SESSION['error_msg'];?></div>
<?
session_unset($_SESSION['error_msg']);
}
if(!empty($_SESSION['rate_msg']))
{
echo $_SESSION['rate_msg'];
session_unset($_SESSION['rate_msg']);
}
?>
You don't open php tag for last statement, (or unnesesery close it) it's treated as html
<?php
if(!empty($_SESSION['error_msg'])){?>
<div style="text-align: center"><?php echo $_SESSION['error_msg'];?></div>
<?php
session_unset($_SESSION['error_msg']);
}
?>
if(!empty($_SESSION['rate_msg'])){
echo $_SESSION['rate_msg'];
session_unset($_SESSION['rate_msg']);
}
?>
EDIT
<?php
// < HERE IS PHP >
if(!empty($_SESSION['error_msg'])){?>
<div style="text-align: center"><?php echo $_SESSION['error_msg'];?></div>
<!-- HERE IS HTML -->
<?
// < HERE IS PHP >
session_unset($_SESSION['error_msg']);
}
?> <!-- CLOSED PHP - NOW IT'S HTML - YOU SHOULD REMOVE IT -->
<!-- THIS IS NOT EXECUTED - BECAUSE IT'S HTML NOW -->
if(!empty($_SESSION['rate_msg'])){
echo $_SESSION['rate_msg'];
session_unset($_SESSION['rate_msg']);
}
?> <!-- THIS IS NOT PHP TAG BECASUE THERE IS NOT OPEN TAG -->
<form name="rating_form" action="" method="post">
<input type="hidden" name="g_id" value="<?php echo $ratings['gallery_id'];?>"/>
<input type="hidden" name="g_image" value="<?php echo $ratings['gallery_image'];?>"/>
<div style="text-align: center">
<input type="radio" name="rating" value="Hot" onclick="document.rating_form.submit();">Hot</input>
<input type="radio" name="rating" value="Not" onclick="document.rating_form.submit();">Not</input>
</div>
</form>
I have a form with 10 similar rows of data required. The form collects product codes, descriptions and quantities. I loop through 10 rows and use arrays to collect the information.
$code = array();
$description = array();
$quantity = array();
<?php
for($i=0; $i<10; $i++){
?>
<div class="quote-row">
<div class="quote-id">
<?php echo $i+1; ?>
</div>
<div class="quote-code">
<input type="text" class="quotecode" name="<?php echo $code[$i]; ?>" />
</div>
<div class="quote-description">
<input type="text" class="quotedescription" name="<?php echo $description[$i]; ?>" />
</div>
<div class="quote-quantity">
<input type="text" class="quotequantity" name="<?php echo $quantity[$i]; ?>" />
</div>
</div>
<?php
}
?>
On the following page, I then use $_POST['code'], $_POST['description'], $_POST['quantity'] to carry the data forward and attempt to use it.
My issue is that the data doesn't appear to be arriving?
Using the for loop, will I still be able to submit the form and take all the data forward?
Hope this is as informative as possible, thanks!
You are giving value of array in name attribute. Your array is empty so your name is empty too.
Try this:
<?php
for($i=0; $i<10; $i++){
?>
<div class="quote-row">
<div class="quote-id">
<?php echo $i+1; ?>
</div>
<div class="quote-code">
<input type="text" class="quotecode" name="code[]" />
</div>
<div class="quote-description">
<input type="text" class="quotedescription" name="description[]" />
</div>
<div class="quote-quantity">
<input type="text" class="quotequantity" name="quantity[]" />
</div>
</div>
<?php
}
?>
name[ ] format automatically make your data an array.
The key to use with the $_POST array is whatever you put in the name="" attribute. Based on the code you provided the names aren't code, description, and quantity but whatever the actual codes, descriptions, and quantities of the items are. You probably want to do this instead:
$code = array();
$description = array();
$quantity = array();
<?php
for($i=0; $i<10; $i++){
?>
<div class="quote-row">
<div class="quote-id">
<?php echo $i+1; ?>
</div>
<div class="quote-code">
<input type="text" class="quotecode" name="code[]" value="<?php echo $code[$i]; ?>" />
</div>
<div class="quote-description">
<input type="text" class="quotedescription" name="description[]" value="<?php echo $description[$i]; ?>" />
</div>
<div class="quote-quantity">
<input type="text" class="quotequantity" name="quantity[]" value="<?php echo $quantity[$i]; ?>" />
</div>
</div>
<?php
}
?>
There are several places where code needs to be updated to work as you expect it.
The most important being that the inputs are using the wrong attributes to store the name and value.
For example, the input element needs to look something like this for each of your inputs:
<input type="text" class="quotecode" name="code[]" value="<?php echo $code[$i]; ?>" />
After, adding a submit button and the surrounding form tags you can then proceed to inspect the variables in next page using PHPs $_POST or $_GET variables.
Hi there. Can anyone please tell me how to arrange the list of checkboxes of cuisines label which is retrieved from the data base and when it is displaying it is not in the order coming side by side all together I want it to be displayed in a 3 by 3 format. Here is the code for that:
<div id="frmform">
<form name="frmrestaurant" id="frmrestaurant" method="post" onsubmit="" enctype="multipart/form-data">
<p class="msgsignup">Add Restaurant</p>
<div id="iderror"></div>
<div class="topinputs">
<div> <label for="restaurant_name" class="name">Restaurant Name :</label><input type="text" name="restaurant_name" size="32" id="restaurant_name" value="<?php echo $row->restaurant_name; ?>" class="validate[required,custom[onlyLetter],length[0,100]] text-input" /> </div>
</div>
<div> <label for="website" class="name">Website :</label><input size="32" type="text" name="website" id="website" value="<?php echo $row->website; ?>" class="validate[required,length[0,100]] text-input" /> </div>
<div> <label for="budget" class="name">Budget :</label>
<?php echo $this->lists['budget'];?>
</div>
<div> <label for="idcuisine" class="cuisine" >Cuisine:</label>
<?php echo $this->lists['cuisine'] ;?>
<div> <label for="idcategory" class="category">Category:</label>
<?php echo $this->lists['category'];?>
</div>
The lists of cuisine and category is not displaying properly.
Thanks.
It could be done with php right logic
<tr>
<?php
while($ofetch=$db->fetchNextObject($query))
{
$j++;
?>
<td width="33%">
<input type="checkbox" name="service[]" id="service" value="<?php echo $ofetch->service_id?>" /> some text
</td>
<?php if($j%3==0) { echo "</tr><tr>";}
}
?>
</tr>