I am trying to find out and track what browser and if a proxy is being used when I receive form submissions. I have the following code below:
<?php
$browser = $_SERVER['HTTP_USER_AGENT'];
$ip_address = $_SERVER['REMOTE_ADDR'];
if (array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER)) {
$ip_address = array_pop(explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']));
}
?>
For example I tried the below but it does not work. It is not submitting any data with my form.
What am I doing wrong?
echo ('<input type="hidden" name="browser" value="' . $browser . '" />' );
echo '<input type="hidden" name="browser" value="'.$browser.'">'
What am I doing wrong?
You are not referencing the variable with a $
You need to correctly escape the variable value from the string
Try printf
printf('<input type="hidden" name="browser" value="%s">', $browser);
You are combining echo and print (which both do the same) into one call. For another thing, you haven't closed the input element HTML (notice the final greater than sign I've added):
echo ('<input type="hidden" name="browser" value="' . $browser . '" />' );
Try this way
echo ("<input type='hidden' name='browser' value='".$browser."'");
echo ('<input type="hidden" name="browser" value="'.$browser.'">');
Try with this -> value="'.$browser.'" something like that
Related
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.'" />';
Hello people i just wanted to ask this that how to do make the below code in PHP
<input type="text" name="SteamID64">
when the person enters and clicks the button then it should fill that value in the below
<?php
$xml=simplexml_load_file("http://steamcommunity.com/profiles/<STEAMID64 HERE>?xml=1");
echo $xml->steamID . "<br>";
echo $xml->onlineState . "<br>";
echo $xml->privacyState . "<br>";
echo $xml->avatarFull . "<br>";
echo $xml->body;
?>
I am sorry if i have done this question wrong i am new here
Use $_POST to get the id:
$format = "http://steamcommunity.com/profiles/%s?xml=1";
$url = sprintf($format, $_POST["SteamID64"]);
$xml=simplexml_load_file($url);
I'm assuming you've got the form set up correctly, something like:
<form action="TheTarget.php" method="post">
<input type="text" name="SteamID64" />
<input type='submit' value='submit' />
</form>
if (isset($_POST['SteamID64'])) {
$id = $_POST['SteamID64'];
$xml = simplexml_load_file("http://steamcommunity.com/profiles/{$id}?xml=1");
}
I have selected data from mysql and inserted them into a radio button form which is looped as shown:
if($num_rows) {
echo '<form name="fixtureform" method="POST" action="index.php">';
while ($row = mysql_fetch_assoc($result)) {
echo $row["home_team"] . " vs " . $row["away_team"]. '<br />' . " Home" . '<input type="radio" name="win'.$row["home_id"].'" value="'.$row["home_id"].'"/>' ." Draw" . '<input type="radio" name="'.$row["home_id"].$row["away_id"].'" value="draw"/>' ." Away" . '<input type="radio" name="win'.$row["away_id"].'" value="' . $row["away_id"] . '"/>' .'<br />';
}
echo '<input type="Submit" Name="Submitacc" Value="Submit your teams">';
echo '</form>';
} else {
echo "There are no fixtures today ";
}
I then have an if statement for submitted values:
if($_POST['Submitacc']=='Submit your teams') {
}
How would I say if the selected name of the radio button is win.$row[home_id] - insert value into mysql table. I'm struggling with the fact I can't get $row[home_id] outside of the loop?
thanks in advance
Try as below
$i=0;
while ($row = mysql_fetch_assoc($result)) {
echo $row["home_team"] . " vs " . $row["away_team"]. '<br />' . " Home" . '<input type="radio" name="result['.$i.']" value="h_'.$row["home_id"].'"/>' ." Draw" . '<input type="radio" name="result['.$i.']" value="draw"/>' ." Away" . '<input type="radio" name="result['.$i.']" value="a_' . $row["away_id"] . '"/>' .'<br />';
$i++;
}
In Your PHP
foreach($_POST['result'] as $value){
if($value == 'draw') {
//do stuff
}
else {
$apart = explode('_',$value);
if($apart[0]=='h'){
//home team win
echo $apart[1];
}
else {
//away team win
echo $apart[1];
}
}
}
use this
echo"<input name='win' type='radio' value='".$row['home_id']."' />";
Because your radios have different names they are all separate and all being submitted, I recommend naming them all "result" and giving them values of "win", "draw" and "loose" respectively.
<label>Win: <input type="radio" name="result" value="win" /></label>
<label>Draw: <input type="radio" name="result" value="draw" /></label>
<label>Loose: <input type="radio" name="result" value="loose" /></label>
<input type="hidden" name="home_team" value="<?php echo $row['home_team']; ?>" />
<input type="hidden" name="away_team" value="<?php echo $row['away_team']; ?>" />
You can access the value with $_POST['result'] and since you know the home team and away team you can handle the data accordingly
i think a diferent usage of the radio button mechanic shuold be used in this case.
in your example you are creating 3 diferent instances of a radio button for each row, instead create one instance of a radio button set with diferent values depending on the answer given
like:
<input type="radio" name="game'.$row["game_id"].'" value="'.$row["home_id"].'">
<input type="radio" name="game'.$row["game_id"].'" value="draw">
<input type="radio" name="game'.$row["game_id"].'" value="'.$row["away_id"].'">
this means that the variable $_POST["game1"] will have the value of the winner or draw that was selected for game which is game_id 1
hope this helps you
Change your element name to win.home without the id, since you will get it by the value.
Then go like:
if(isset($_POST['win.home'])) { }
Edit:
If you want to do it like this, try this:
3 radio buttons, named win.home, draw, win.away plus a unique id (mysql id?) like win.home.1234 then you can use as many games as you want. You can get the id back with explode() later.
Then the values:
1st: $row["home_id"] . "-" . $row["away_id"]
2nd: draw
3rd: $row["away_id"] . "-" . $row["home_id"]
Then when processing the form:
Split the value with explode() at the -. So the first id is always the winner.
So i have these radio buttons in XHTML that I want to put into a PHP function to generate and I can't get it to work.
In XHTML it looks like this and is working;
<p><input type="radio" value="<? echo blabla; ?>" name="radioA" checked="checked" /></p>
<input type="hidden" value="<? echo $value; ?>" name="hiddenA[]" />
In PHP I need to set the "radioA" and "hiddenA" to variables respectively "radioB"/"hiddenB", "radioC"/"hiddenC" and so on for my code to work. This is what I have so far but it is not working. The first radio name is a string, but the second one is array. Thanks in advance.
function radio($Radio, $Array) {
echo '<p><input type="radio" value="$value>" name="$Radio" />', $value, '</p>';
echo '<input type="hidden" value="$value" name="$Array" />';
}
I guess what I'm trying to do is to return the name of the variable as a string. $_POST['hiddenA'] ===> hiddenA[]
Basic php syntax:
$a = 'hello';
echo '$a'; // outputs the literal characters $ and a
echo "$a"; // outputs "hello"
You have a few syntax issues here:
function radio($Radio, $Array) {
echo '<p><input type="radio" value="$Value>" name="$Radio" />', $Value, '</p>';
echo '<input type="hidden" value="$Value" name="$Array" />';
}
You have to use "" not '' when embedding variables:
echo "My name is {$name}.";
In PHP the . character is used to append strings not ,
echo "My name is " . $name . " and I am cool";
If you try to echo an array you will get the word Array not the array itself. Instead you can echo a value in the array:
echo "$array[0]";
You are trying to use a variable that is not defined in your example: $Value. This would give you an VariableUndefined exception.
It is generally bad practice to use capital letters at the start of variable names in PHP. So $Array should be $array.
With these in mind you code should look something like:
function radio($radio, $array) {
$value1 = $array[0];
$value2 = $array[1];
echo "<p><input type=\"radio\" value=\"$value1>\" name=\"$radio\" />$value1</p>";
echo "<input type=\"hidden\" value=\"$value2\" name=\"$value2\" />";
}
From the sounds of your example you need a for loop somewhere.
i'm trying to select values from the database and place each and every one on a separate text input field. my code works properly, however, when i tried to display a string on a text field, the string is cut or trimmed on its very first space character. for example:
value #1: "my-picture.jpg"
value #2: "my name"
if i were to place the two values above and insert them inside a text field, the output would be like this:
value #1: my-picture.jpg
value #2: my
this is the code i'm working on:
<?php
$counter = 0;
while ($newArray = mysqli_fetch_array($res, MYSQLI_ASSOC)) {
echo "
<input type='text' value=".$newArray['my_picture'].">
<input type='text' value=".$newArray['my_name'].">
";
?>
What is wrong? Thanks for any help.
You need to quote your values in your HTML form:
echo '
<input type="text" value="'.$newArray['my_picture'].'">
<input type="text" value="'.$newArray['my_name'].'">
';
Also for good measure it would be a good idea to use htmlentities() or htmlspecialchars() on the values in your variables to encode special characters:
echo '<input type="text" value="' . htmlentities($newArray['my_picture']) . '">
<input type="text" value="' . htmlentities($newArray['my_name']) . '">';
Try viewing the source.. That says:
<input type='text' value=the content of your variable>
Where 'the content of your variable' needs to be surrounded by quotes, naturally. So; change it into:
<?php
$counter = 0;
while ($newArray = mysqli_fetch_array($res, MYSQLI_ASSOC)) {
echo '<input type="text" value="' . $newArray['my_picture'] . '">';
echo '<input type="text" value="' . $newArray['my_name'] . '">';
}
?>
You need to surround your value with quotes. Something like
echo "
<input type='text' value='".$newArray['my_picture']."'>
<input type='text' value='".$newArray['my_name']."'>
";