Passing 2 strings from one PHP script to the other using href -
i trying pass 2 strings first.php file second.php file-
in first.php file, tried send data
<?php echo "<a href='second.php?newformat=$statusstring&macaddress=$macaddress'>link</a>"; ?>
and
<a href="second.php?newformat="<?php echo $statusstring; ?> &macaddress=<?php echo $macaddress; ?>link</a>
and
<a href="second.php?newformat=<?php echo urlencode($statusstring);?>&macaddress=<?php echo urlencode($macaddres); ?>"link</a>
i tried of above possibilities. same error -
php parse error: syntax error, unexpected '<' in /var/www/html/first.php on line 176
my $statusstring
- "u=500000;t1=1479394;s=10;r=-33;v=3.7;"
my $macaddres
- "500000"
can tell me how differently do this?
edit 1
i have tried comment line in code, , code works without errors!
edit 2
if(some condition) { $statusstring = "u=".$macaddress.";t1=".$time.";s=10;r=-33;v=".$voltage.";"; <?php echo "<a href='second.php?newformat=$statusstring&macaddress=$macaddress'>link</a>"; ?> }
in second.php file, retrieving these by-
if (isset($_get['newformat'])) { $str = $_get['newformat']; } else $str = 'no data'; if (isset($_get['macaddress'])) { $macaddress = $_get['macaddress']; }
in last edit:
if(some condition) { $statusstring = "u=".$macaddress.";t1=".$time.";s=10;r=-33;v=".$voltage.";"; <?php echo "<a href='second.php?newformat=$statusstring&macaddress=$macaddress'>link</a>"; ?> }
well, explains unexpected <
. you're already in context of php code. can write php code:
if(some condition) { $statusstring = "u=".$macaddress.";t1=".$time.";s=10;r=-33;v=".$voltage.";"; echo "<a href='second.php?newformat=$statusstring&macaddress=$macaddress'>link</a>"; }
no need sprinkle in more <?php ?>
tags, you're confusing php parser.
edit: should url-encode values, since complex:
echo '<a href="second.php?newformat=' . urlencode($statusstring) . '&macaddress=' . urlencode($macaddress) . '">link</a>';
Comments
Post a Comment