I'm trying to pass out the variables to the next php form but i cant get it right. But i get this error :Parse error: syntax error, unexpected '?' in D:\XAMPP\htdocs\bagongabnoy\AthanMotorcycleWebsite2\debitgo.php on line 28
here is my code:
<?php
session_start();
include('config.php');
$accname=$_POST['accname'];
$accnum=$_POST['accnum'];
$pin=$_POST['pin'];
$cusid=$_POST['cusid'];
$grandtotal=$_POST['grandtotal'];
$transactioncode=$_POST['transactioncode'];
$trasactiondate=date("m/d/Y");
$status='Completed';
$mode='OnlinePayment';
$resultq = mysql_query("SELECT * FROM tbl_bank_debit WHERE txtAccountNumber = '$accnum'");
while($rows = mysql_fetch_array($resultq))
{
$balance=$rows['intBalance'];
//$pqs=$rows['qtysold'];
//$left=$pql-$qty;
//$solds=$pqs+$qty;
$balupdate=$balance-$grandtotal;
mysql_query("UPDATE tbl_bank_debit SET intBalance='$balupdate' WHERE txtAccountName = '$accname'");
}
echo '<input name="transactioncode" type="hidden" value="'<?php echo $transactioncode;?>' />';
echo '<input name="cusid" type="hidden" value="'<?php echo $cusid;?>' />';
echo '<input name="total" type="hidden" value="'<?php echo $total;?>' />';
echo '<input name="grandtotal" type="hidden" value="'<?php echo $grandtotal;?>' />';
echo '<input name="totalcharge" type="hidden" value="'<?php echo $totalcharge;?>' />';
echo '<input name="portal" type="hidden" value="'<?php echo $portal;?>' />';
echo '<input name="distination" type="hidden" value='<?php echo $distination;?>' />';
/*$resulta = mysql_query("SELECT * FROM athan_products WHERE id = '$id'");
while($row = mysql_fetch_array($resulta))
{
$pprice=$row['price'];
$psize=$row['product_size_name'];
}
$total=$pprice*$qty;
mysql_query("INSERT INTO orderdetails (customer, qty, price, total, partsname, size, transactioncode) VALUES('$memid', '$qty', '$pprice', '$total', '$name', '$psize', '$transcode')");*/
header("location: cashconfirmsub.php");
?>
That is not the way you concatenate Strings in PHP. You aren't allowed to nesting <?php tags.
Instead of
echo '<input name="transactioncode" type="hidden" value="'<?php echo $transactioncode;?>' />';
Do the following:
echo '<input name="transactioncode" type="hidden" value="' . $transactioncode . ' />';
Simply add a . character between the parts you want to concatenate.
Edit:
And to finalize the answer, you should also be cautious about user inputs. They can be evil! In this case you should remove HTML characters via htmlspecialchars():
echo '<input name="transactioncode" type="hidden" value="' . htmlspecialchars($transactioncode) . ' />';
Take a careful look at line 28:
echo '<input name="distination" type="hidden" value='<?php echo $distination;?>' />';
The problem is fairly obvious. Pay attention to quoting.
As a general rule: If an error report gives you a line number then take a good look a that line. Sometimes you can break the line in half and re-run the test to see if it still occurs on the same line or the next one to tell which half of the line the issue is in. For example break your line above like this to test it:
echo '<input name="distination" type="hidden"
value='<?php echo $distination;?>' />';
What you are looking for is called "concatenation".
You can "concatenate" (listen append) 2 strings using a dot :
echo "string1"."string2";
will display "string1string2"
You can also concatenate a string and a variable :
$string2 = "string2";
echo "string1".$string2;
So in your example, it will be :
echo '<input name="transactioncode" type="hidden" value="'.$transactioncode.'" />';
echo '<input name="cusid" type="hidden" value="'.$cusid.'" />';
echo '<input name="total" type="hidden" value="'.$total.'" />';
echo '<input name="grandtotal" type="hidden" value="'.$grandtotal.'" />';
echo '<input name="totalcharge" type="hidden" value="'.$totalcharge.'" />';
echo '<input name="portal" type="hidden" value="'.$portal.'" />';
echo '<input name="distination" type="hidden" value="'.$distination.'" />';
Related
I have the following code:
<?php
$student_no = $_GET['student_no'];
echo '<form name="student" action="PROCESS_FEE007.php" method="POST">';
echo '</br><table>';
echo '**<input name="student_no" type="hidden" value="$student_no" />**';
echo '<td>Amount: </td><td>'.'<input name="amount" type="text" /></td></tr>';
echo '<tr> <td>Remarks: </td><td>'.'<input name="remarks" type="text" /> </td>';
echo '<tr> <td>';
echo '<td>'.'<input type="submit" value="Save"/></td></tr>';
echo '</table>';
echo '</form>';
?>
On the next page PROCESS_FEE007.PHP the value is not received.
Variables are not parsed by interpreter inside single quotes. You should use double quotes or explicit string concatenation.
In your example the value of $_POST['student_no'] will be string '$student_no', not the value of the $student_no variable.
Besides if you're using method="POST" in your form, you can only get the inputs value through the $_POST array.
<?php
$student_no = $_POST['student_no'];
echo '<form name="student" action="PROCESS_FEE007.php" method="POST">';
echo '</br><table>';
echo '**<input name="student_no" type="hidden" value="'.$student_no.'" />**';
echo '<td>Amount: </td><td>'.'<input name="amount" type="text" /></td></tr>';
echo '<tr> <td>Remarks: </td><td>'.'<input name="remarks" type="text" /> </td>';
echo '<tr> <td>';
echo '<td>'.'<input type="submit" value="Save"/></td></tr>';
echo '</table>';
echo '</form>';
?>
parse student_no in form as
<?php
$student_no = $_GET['student_no'];
echo '<form name="student" action="PROCESS_FEE007.php" method="POST">';
echo '</br><table>';
echo '**<input name="student_no" type="hidden" value="'.$student_no.'" />**';
echo '<td>Amount: </td><td>'.'<input name="amount" type="text" /></td></tr>';
echo '<tr> <td>Remarks: </td><td>'.'<input name="remarks" type="text" /> </td>';
echo '<tr> <td>';
echo '<td>'.'<input type="submit" name="submit_save" value="Save"/></td></tr>';
echo '</table>';
echo '</form>';
?>
and on the PROCESS_FEE007.php page use
<?php
if ($_POST['submit_save']){
var_dump($_POST);die();
}
?>
check the attribute "VALUE" of hidden input field. The value is not put in the field.
First make the input field a text box and after fixing the bug make it a hidden field.
may be useful. (I forgot cuz I am out of PHP long time).
try using $_REQUEST instead of get example $student_no = $_REQUEST['student_no'];
I have an HTML form that is echoed from my php script. When I try to pass a hidden variable through the script, the code does not work as intended.
$threadNumber=$row["Tid"];
echo "<center><b>Message# ", $messageNumber , ": </b><br>";
echo $row["Mtitle"] , " in Thread# " , $row["Tid"] , "<br>";
echo "The Message was Written on " , $row["Mdate"] , '<br>';
echo $row["Mbody"];
echo "<br><br>";
echo '<form action="messageReply.php" method="post">';
echo '<textarea name="reply" rows=5 cols=30 placeholder="Reply to the Message?"></textarea>';
echo '<input type="hidden" name="Mtitle" value="<?php echo $row["Mtitle"] ?>">';
echo '<input type="submit" value="Send Message">';
echo '</form>';
The result looks like this:
and when I try to read $_POST["Mtitle"] in the messageReply.php script, I get an error saying such an index does not exist.
Try this:
echo '<input type="hidden" name="Mtitle" value='.$row['Mtitle'].'>';
Your Complete Code (Modified):
$threadNumber=$row["Tid"];
echo "<center><b>Message# ", $messageNumber , ": </b><br>";
echo $row["Mtitle"] , " in Thread# " , $row["Tid"] , "<br>";
echo "The Message was Written on " , $row["Mdate"] , '<br>';
echo $row["Mbody"];
echo "<br><br>";
echo '<form action="messageReply.php" method="post">';
echo '<textarea name="reply" rows=5 cols=30 placeholder="Reply to the Message?"></textarea>';
echo '<input type="hidden" name="Mtitle" value='.$row['Mtitle'].'>';
echo '<input type="submit" value="Send Message">';
echo '</form>';
Note: You are using php in php. Please change it below code:
<?php
echo '<input type="hidden" name="Mtitle" value="'.$row["Mtitle"].'">';
?>
I'm making a search query for my webs, and i get an error for my query after i add the if ($results==0) ......
Object of class mysqli_result could not be converted to int in line 65 which refer to if ($results==0)
$results = $mysqli->query("SELECT * FROM produk2 WHERE $construct" );
if ($results==0)
{
echo "Sorry, there are no matching result for <b>$search</b>.</br></br>1.
Try more general words. for example: If you want to search 'how to create a website'
then use general keyword like 'create' 'website'</br>2. Try different words with similar
meaning</br>3. Please check your spelling";
}
else{
//fetch results set as object and output HTML
while($obj = $results->fetch_object())
{
echo '<div class="product">';
echo '<form method="post" action="cart_update.php">';
echo '<div class="product-thumb"><img src="images/'.$obj->product_img_name.'"></div>';
echo '<div class="product-content"><h3>'.$obj->product_name.'</h3>';
echo '<div class="product-desc">'.$obj->product_desc.'</div>';
echo '<div class="product-info">';
echo 'Price '.$currency.$obj->price.' | ';
echo 'Qty <input type="text" name="product_qty" value="1" size="3" />';
echo '<button class="add_to_cart">Add To Cart</button>';
echo '</div></div>';
echo '<input type="hidden" name="product_code" value="'.$obj->product_code.'" />';
echo '<input type="hidden" name="type" value="add" />';
echo '<input type="hidden" name="return_url" value="'.$current_url.'" />';
echo '</form>';
echo '</div>';
}
}
$mysqli->query don't have the data count until you ask for it
Try like this
if($results ->num_rows == 0){
// no result found
}
I've this problem in which I can't update the cart for some reason. I've looked for many solutions to see if they can solve my problem but no luck. I've 2 files one called cart.php which contains the form and a updatebasket.php file which contains query.
Cart file
<?php
$count = 0;
while ($count < $numrow)
{
$row = $results -> fetch_assoc();
extract($row);
echo"<div>";
echo"<div class='recommended_games'>";
echo "<img src='images/".$gameIMG."' />";
echo "</div>";
echo '<div class="price_tag">';
echo '<div class="price_tag">£'.$gamePrice. '</div>';
echo'</div>';
echo '<div id="update_form"><form action="updatebasket.php" method="POST" name="updateform">';
echo '<input type="text" value="1" name="quantity" id="quantity" />';
echo '<input type="hidden" value="'.$gameID.'" name='.$gameID.' id="gameid" />';
echo '<input type="submit" value="update" />';
echo '</form>';
echo '</div>';
echo"<img class='box1' src='Images/Grey-Banners.png' />";
echo"</div>";
$count = $count + 1;
}
?>
updatebasket file
<?php
session_start();
require "dbconnect.php";
$memberID = $_SESSION['id'];
$quantity = $_POST['quantity'];
$gameID = $_POST['gameid'];
mysqli_autocommit($con,FALSE);
$connect->query($query);
$query = "UPDATE basket SET quantity = ".$quantity." WHERE gameid = ".$gameID." AND id = ".$memberID."";
$results = $connect->query($query);
mysqli_commit($con);
header('Location: cart.php');
?>
Change cart.php to this:
<?php
$count = 0;
while ($count < $numrow)
{
$row = $results -> fetch_assoc();
extract($row);
echo"<div>";
echo"<div class='recommended_games'>";
echo "<img src='images/".$gameIMG."' />";
echo "</div>";
echo '<div class="price_tag">';
echo '<div class="price_tag">£'.$gamePrice. '</div>';
echo'</div>';
echo '<div id="update_form"><form action="updatebasket.php" method="POST" name="updateform">';
echo '<input type="text" value="1" name="quantity" id="quantity" />';
echo '<input type="hidden" value="'.$gameID.'" name="gameid" id="gameid" />';
echo '<input type="submit" value="update" />';
echo '</form>';
echo '</div>';
echo"<img class='box1' src='Images/Grey-Banners.png' />";
echo"</div>";
$count = $count + 1;
}
?>
The big change is this:
BEFORE:
echo '<input type="hidden" value="'.$gameID.'" name='.$gameID.' id="gameid" />';
AFTER:
echo '<input type="hidden" value="'.$gameID.'" name="gameid" id="gameid" />';
php uses the name attribute as the key for post and get, not id.
id is used by javascript, jquery (also javascript), css, and probably a few other things.
But in forms, name is the one you want for the post and get key.
What I'm doing is trying to set up a page where users can see their created tools and delete them whenever they want. I'm querying three different tables and putting the results into an array. Once those values are in an array, a foreach loop goes through and populates a table with all the information in a table, like so:
$counter = 1;
echo '<table>'
foreach ($recent_saved_tools as $key => $value) {
echo '<tr name="item'.$counter.'">';
echo '<td>';
echo '<input type="hidden" name="tablename" value="'.$value['table'].'" />';
echo '<input type="hidden" name="tabledelete" value="'.$value['delete'].'" />';
echo '<input type="hidden" name="tableidfield" value="'.$value['idfield'].'" />';
echo '<input type="hidden" name="tableid" value="'.$value['id'].'" />';
//code to display the tool name and link
echo '<a style="text-decoration:none;" href="'.WEBSITE.'tools/'.$value['URL'].'?saved_data_id='.$value['id'].'">'.$value['display'].'</a><br />';
echo date("m/d/Y H:i:s", $key).'<br />';
echo '</td><td>';
//code to display the delete button
echo ' <input class="cssformbutton bluebutton" type="button" name="delete" id="deletebtn'.$counter.'" value="Delete" /><br /><br /><br /><br /></td>';
$counter ++;
}
echo '</table>';
The problem is whenever I run the SQL query, no matter what button I click it always takes the values from the last table row. I know it has something to do with the way they're named (multiple elements have the same name) but I'm at a loss on how to fix this. Any help would be appreciated.
Here's the query I'm using to delete the item:
$query = 'UPDATE '.$value['table'].' SET '.$value['delete'].' = 1 WHERE '.$value['idfield'].' = '.$value['id'];
$sql->query($query);
EDIT: added delete code
Every row has some inputs which are posted to the server. They have the same names - for every row. You could change it like this:
echo '<input type="hidden" name="tablename'.$counter.'" value="'.$value['table'].'" />';
Then you can use $_POST['tablename'.$rownr] in your delete code.
Doesn't look like you're closing the anywhere...
What results return from the query?
What output are you expecting?
try making it a for loop in stead and adding the variable to the end.
$array;
$counter = count($array);
echo '<table>'
for($i = 0; $i < $counter - 1; $i++) {
echo '<tr name="item'.$i.'">';
echo '<td>';
echo '<input type="hidden" name="tablename" value="'.$value['table']. $i'" />';
echo '<input type="hidden" name="tabledelete" value="'.$value['delete']. $i'" />';
echo '<input type="hidden" name="tableidfield" value="'.$value['idfield']. $i'" />';
echo '<input type="hidden" name="tableid" value="'.$value['id'].'" />';
//code to display the tool name and link
echo '<a style="text-decoration:none;" href="'.WEBSITE.'tools/'.$value['URL'].'?saved_data_id='.$value['id'].'">'.$value['display'].'</a><br />';
echo date("m/d/Y H:i:s", $key).'<br />';
echo '</td><td>';
//code to display the delete button
echo ' <input class="cssformbutton bluebutton" type="button" name="delete" id="deletebtn'.$counter.'" value="Delete" /><br /><br /><br /><br /></td>';
}
echo '</table>';