hello! am trying to do a simple search engine, but whenever the user types a search term, the script returns the error: unidentified variable: name. name was the input name in the html code. ie (input name="name"). thanks.

<?php

$db = mysql_connect("localhost", "root", "");

mysql_select_db("room_p7", $db);

$query = "select name, course from members where name ='$name'";
$result = mysql_query($query);

while($record=mysql_fetch_assoc($result)){

        while(list($fieldname, $fieldvalue) = each($record)){

            echo $fieldname."\t".$fieldvalue."\t\t\t";
            }

    echo "<br><br>";

    }
?>

Recommended Answers

Where are you defining $name variable before using it? Do you mean something like $name = $_POST("name"); ? Of course using MySQL without validations or/and prepared statements is really a bad way to do things (PHP has PDO).

Jump to Post

All 2 Replies

Where are you defining $name variable before using it? Do you mean something like $name = $_POST("name"); ? Of course using MySQL without validations or/and prepared statements is really a bad way to do things (PHP has PDO).

yes! thanks. though i had already figured that out.

Be a part of the DaniWeb community

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