I want to add value of product_id inside database using bidupdate.php.
But everytime i try this. It says Error in connection as explained in die function in php. The value of product_id is not passing. I think there is some error in the value phase. Please check it.
<?php
if(isset($_SESSION['user_id'])){
echo '<form id="myForm" method="POST" action="bidupdate.php">';
echo '<input type="hidden" name="product_id" value = "<?php echo '.$_REQUEST['product_id'].'">';
echo '<button input="submit" name="bid">Bid Now</button>';
echo '</form>';
}
?>
You can't call the value in php close within php. that is possible with html. Use this code
<?php
if(isset($_SESSION['user_id'])){
echo '<form id="myForm" method="POST" action="bidupdate.php">';
echo '<input type="hidden" name="product_id" value = "'.$_REQUEST['product_id'].'">';
echo '<button input="submit" name="bid">Bid Now</button>';
echo '</form>';
}
?>
This is Wrong:
echo '<input type="hidden" name="product_id" value = "<?php echo '.$_REQUEST['product_id'].'">';
You cannot use <?php ?> inside PHP code.
Corrected code:
echo '<input type="hidden" name="product_id" value = "'.$_REQUEST['product_id'].'">';
Related
I'm trying to update the table in DB and every row (result) has its own update button which is a form. When i click the button nothing happens because I don't know how to transfer value of id to a form and then to a UPDATE query.
while(list($naziv,$tvrtka_id)=mysqli_fetch_row($resultA))
{
echo "<tr>";
echo "<td>".$naziv."</td>";
echo "<td>"?>
<form action="" method="POST">
<input type="hidden" name="id" value="<?php $tvrtka_id; ?>">
<input type="submit" name="odobriZahtjev" value="Odobri zahtjev">
</form> <?php "</td>";
echo "</tr>";
}
echo "</tbody>";
echo "</table>";
} //this is from a if statment which creates table
if(isset($_POST['odobriZahtjev']))
{
$firmId = $_POST['id'];
$updateAnswers = "UPDATE tvrtka
SET zahtjev = '0', preostaliOdgovori=preostaliOdgovori + 10
WHERE tvrtka.tvrtka_id='$firmId'";
$result=queryDB($connect,$updateAnswers);
}
When button is clicked the value of a request for answers is set to 0 and 10 answers are added to company.
tvrtka_id is the id which is supposed to go to a UPDATE query.
When using a PHP var inside HTML you have to print it to the HTML (using echo in your case).
<input type="hidden" name="id" value="<?php echo $tvrtka_id; ?>">
This will probably solve the problem with your update query when the form is submitted too
I have a submit button for input type = "number", when I change value of input tag, subtotal will be change:
<form action="<?php echo base_url('cart/update') ?>" method="post">
<input type="number" name="qty_<?php echo $row['id'] ?>" value="<?php echo $row['qty']; ?>"/>
<button type="submit">Update</button>
Total: <?php echo number_format($row['subtotal']); ?>
</form>
In Cart controller, this function update qty and change value of $row['subtotal']:
function update(){
$carts = $this->cart->contents();
foreach ($carts as $key => $row){
$total_qty = $this->input->post('qty_'.$row['id']);
$data = array();
$data['rowid'] = $key;
$data['qty'] = $total_qty;
$this->cart->update($data);
}
redirect(base_url('cart'));
}
Then, I want to use a onchange event, but I dont have idea. How to call update function?
I try this:
<input type="number" name="qty_<?php echo $row['id'] ?>" value="<?php echo $row['qty']; ?>" onchange=<?php echo base_url('cart/update')?>/>
Of course, it doesn't work.
Please help.
Thanks.
The onchange attribute executes javascript, so you can't just provide it a URL. You should be able to submit the form via: onchange="this.form.submit()"
I have a SQL query statement that will return a particular set of result. Such as ID, Names, Price. I have no problem with that.
However i am trying to add a link within the echo loop and set ID as the value so that i can post it to another page. Would that be possible ?
while ($row = mysql_fetch_array($result)) {
echo
"".$row{'Url'}."<br>";
echo
"Name:".$row{'Name'}."<br>";
echo
"Price: $ ".$row{'Price'}."<br>";
echo
'<div class = "qwerty" data-countdown= '.$row{'Time'}.'></div>';
echo
"Location:".$row{'Location'}."<br>";
echo
"Description:".$row{'Description'}."<br>";
echo ''.$row{'ID'}.'';
echo 'Show Comments
<form id="displayComments" style="display:none" target="jsScript()" method="post">
<input type="hidden" name="run" value=".$row{'ID'}." />
</form>';
You missed quotes. value="'.$row['ID'].'"
echo 'Show Comments
<form id="displayComments" style="display:none" target="jsScript()" method="post">
<input type="hidden" name="run" value="'.$row['ID'].'" />
</form>';
And php array use [ ]
http://ua2.php.net/manual/en/language.types.array.php
I am trying to make code changing news pages and I am having difficulties.
$_SESSION['page'] doesn't change value and always stays as 1.
Thank you.
<?php
session_start();
if (!isset($_POST['set_page'])) {
$_SESSION['page'] = 1;
}
else {
eval("return '".$_POST['change_page']."';");
}
echo "Page ".$_SESSION['page'];
echo '<form action="test.php" method="post">';
echo '<input type="hidden" name="change_page" value="$_SESSION["page"]++"/>';
echo '<input type="submit" name="set_page" value="Next Page"></form></p>';
?>
Your statement here is wrong ++ operator will work like that change that line like this
echo '<input type="hidden" name="change_page" value="'.$_SESSION["page"]++.'"/>';
and your single quotes, When you embed some variable inside string use double quotes or use concatenation.
I was wondering if it is possible to use a variable from a form as its own URL... its hard to explain in my opinion, heres an example:
matchmaking.php:
$search_summoner = $_POST['search_summoner'];
echo '<form method="post" action="matchmaking.php?search=' . $search_summoner . '">';
echo '<input type="text" name="search_summoner">';
echo '<input type="submit">';
echo '</form>';
As you can see the action sends it back to matchmaking.php but with a variable from the form which was just submitted. The code above, which I have tried, didn't seem to work; So I wondered if anyone else had any ideas on how to do this...
Thanks for the help in advance
using jquery you could set the action parameter like this (add an ID "search" to the form)
$('input[name="search_summoner"]').on('keyup'function(){
$('form#search').attr('action','matchmaking.php?search='+$(this).val());
});
So, while typing, the action parameter will be extended by every character of the typed search string.
Try this;
<?php
if(isset($_POST['search_summoner']) && $_POST['search_summoner'] != '')
{
$search_summoner = $_POST['search_summoner'];
}
else
{
$search_summoner = "";
}
echo $search_summoner; // This displays your Query
?>
<html>
<body>
<form method="post" action=<?php echo $_SERVER['PHP_SELF']; ?>>
<input type="text" name="search_summoner">
<input type="submit">
</form>
</body>
</html>
If I understand you right, I think you want to do something like this:
$search_summoner = $_POST['search_summoner'];
echo '<form method="post" action="matchmaking.php">';
echo '<input type="hidden" name="search" value="'.$search_summoner.'"/>';
echo '<input type="text" name="search_summoner">';
echo '<input type="submit">';
echo '</form>';