echo" //i need this echo;
<form class='form' action='zoom.php?img=<?php echo intval($_GET['img']);?>' method='post'> //i dont need echo in here
";

i also tired 
action='zoom.php?img= intval($_GET['img'])'
action='zoom.php?img=$_GET['img'])'

but no luck 

it give me syntar error every time

Dani AI

Generated

had a classic quoting/embedding problem: trying to output HTML from inside PHP while also embedding a PHP expression inside the same quoted string. That pattern easily causes parse errors or broken output. was right to move the GET value into a PHP variable first — that simplifies quoting — but there are a couple of extra points worth doing every time you echo user input into an HTML attribute: validate the value, build or encode the query safely, and escape the final attribute to prevent XSS.

Recommended pattern (validate, build the query, then output the action attribute):

<?php
$img = filter_input(INPUT_GET, 'img', FILTER_VALIDATE_INT);
if ($img === null || $img === false) {
    $img = 0;
}
$action = 'zoom.php?' . http_build_query(array('img' => $img));
?>
<form class="form" action="<?php echo htmlspecialchars($action, ENT_QUOTES, 'UTF-8'); ?>" method="post">

Use filter_input to get/validate the integer input (filter_input docs), http_build_query to safely encode the query string (http_build_query docs), and htmlspecialchars when placing the URL inside an attribute (htmlspecialchars docs).

Quick troubleshooting:

  • Run php -l filename.php to lint for parse errors and check the reported line number.
  • Check the server error log or enable error_reporting(E_ALL)/display_errors during development.
  • Avoid nesting PHP open tags inside an already-open PHP block or inside a quoted string — close PHP to emit raw HTML, or build the value in PHP and then echo the variable.
  • If you intend to pass non-integer data, URL-encode it (or use http_build_query) and always escape for HTML attributes.

Recommended Answers

All 2 Replies

$img = intval($_GET['img']);
echo "<form class='form' action='zoom.php?img=$img' method='post'>";

thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.