-4

What is wrong in this highlighted syntax?

<?php
mysql_connect("localhost", "root", "") or die("could not connect");
mysql_select_db("student") or die("could not connect");


//collect
if(isset($_POST['search'])) {
    $searchq = $_POST['search'];
    $searchq = preg_replace("#[^0-9a-z]#i", "", $searchq)

//here
$query = mysql_query("SELECT * FROM user WHERE registration LIKE '%$searchq%'") or die("could not search!");

    $count = mysql_num_rows($query);
    if($count == o){
        $output = 'There was no search results!';
    }else{
        while($row = mysql_fetch_array($query)) {
            $fname = $row['firstname'];
            $lname = $row['surname'];
            $id = $row['registration'];

            $output .= '<div> '.$id.' '.$fname.' '.$lname.'</div>';

}
?>


<html>
<head>
</head>
<body>

<form action="form.php" method="post">
    <input type="text" name="search" placeholder="search for students.."
    <input type="submit" value=">>" />
</form>


<?php print("$output");?>
</body>
</html>

please help....

Rizier123
  • 58,877
  • 16
  • 101
  • 156
  • 2
    Please, [don't use `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). Learn about [prepared statements](http://en.wikipedia.org/wiki/Prepared_statement) instead, and use [PDO](http://us1.php.net/pdo) or [MySQLi](http://us1.php.net/mysqli). – Jay Blanchard Jan 12 '15 at 17:35
  • See the line above of `//here $query...`. Don't always believe the line number it says the error's on ;-) – Funk Forty Niner Jan 12 '15 at 17:36
  • 1
    You're missing a `;` semicolon go find it! – Rizier123 Jan 12 '15 at 17:36
  • 2
    You are also missing a `}`. Please don't use Stack Overflow to debug your code. – Felix Kling Jan 12 '15 at 17:37
  • 1
    I believe you have an "o" instead of "0" (zero): if($count == o){ – valicu2000 Jan 12 '15 at 17:37
  • So many things wrong with this. – Funk Forty Niner Jan 12 '15 at 17:37
  • 2
    Look it's pretty easy all your answers are here: http://stackoverflow.com/q/12769982/3933332 you just have to read it and find it! I think instead of giving you your answer it's better to learn what the error means, what's going on so next time you can solve this yourself! – Rizier123 Jan 12 '15 at 17:38
  • @FelixKling *"You are also missing a `}`"* - Missing two braces actually. Something that wasn't noted in the "accepted" answer. – Funk Forty Niner Jan 12 '15 at 18:03

1 Answers1

3

You forgot a semi-colon :

//collect
if(isset($_POST['search'])) {
    $searchq = $_POST['search'];
    $searchq = preg_replace("#[^0-9a-z]#i", "", $searchq)

should be

//collect
if(isset($_POST['search'])) {
    $searchq = $_POST['search'];
    $searchq = preg_replace("#[^0-9a-z]#i", "", $searchq);
rm-vanda
  • 3,122
  • 3
  • 23
  • 34
  • 1
    *"Also, looks like the line that directly follows is missing one, too..."* - Being? Who upvoted this? Fix it all, not just 1/2 way ;-) – Funk Forty Niner Jan 12 '15 at 17:38
  • Thanks rm_vanda & others for rectify the code. Actually i am novice in php. so i'm facing this type of problem. If this type of problem is not allowed in stackoverflow then i'll surely left the site. Please let me know. – Nasim Uddin Ahmmad Jan 12 '15 at 17:55
  • @Nasim: Yes, avoid asking questions about syntax errors. The basic syntax is the very least we expect someone to know. – Felix Kling Jan 12 '15 at 18:06