We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,301 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

unidentified variable: name

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>";

    }
?>
2
Contributors
2
Replies
1 Hour
Discussion Span
1 Year Ago
Last Updated
3
Views
collinskawere
Newbie Poster
12 posts since Nov 2011
Reputation Points: 12
Solved Threads: 0
Skill Endorsements: 0

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).

jkon
Posting Whiz
383 posts since Jan 2009
Reputation Points: 124
Solved Threads: 63
Skill Endorsements: 4

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

collinskawere
Newbie Poster
12 posts since Nov 2011
Reputation Points: 12
Solved Threads: 0
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0644 seconds using 2.66MB