php - The below code is working for others but not for me -
when seek search in form shows me error variables...
class="lang-html prettyprint-override"><form action="search.php" method="get"> <input type="text" size="25" name="search" placeholder="search site"> <input type="submit" name="submit" value="search"></form> <?php include("includes/connect.php"); if(isset($_get['submit'])){ $search_id = $_get['search']; $query = "select * posts post_title '%search_id%'"; $run = mysql_query($query); while ($row=mysql_fetch_array($run)){ $post_id = $row['post_id']; $post_title = $row['post_title']; $post_image = $row['post_image']; $post_content = $row['post_content']; } ?> <h2> <a href="pages.php?id=<?php echo $post_id; ?>"> <?php echo $post_title; ?></a> </h2> <center><img src="images/<?php echo $post_image; ?>" width="100" height="100"></center> <p align="justify"><?php echo $post_content; ?></p> <?php } ?>
i think problem loop function. don't know how resolve this...
you forgot $-sign in statement:
$query = "select * `posts` `post_title` '%$search_id%'";
btw: don't utilize mysql_query anymore, deprecated. utilize mysqli or pdo instead. :)
you're vulnerable mysql injections. seek escape $_get
value: mysql_real_escape_string($_get['search'])
also, you're overwriting variables in while loop, because phone call variables outside while loop. set variables within while loop this:
while ($row=mysql_fetch_array($run)){ $post_id = $row['post_id']; $post_title = $row['post_title']; $post_image = $row['post_image']; $post_content = $row['post_content']; ?> <h2> <a href="pages.php?id=<?php echo $post_id; ?>"><?php echo $post_title; ?></a> </h2> <center> <img src="images/<?php echo $post_image; ?>" width="100" height="100"> </center> <p align="justify"> <?php echo $post_content; ?> </p> <?php }//<--- 1 closes while loop }//<--- 1 closes if statement ?>
php html
No comments:
Post a Comment