markl1988 Posted May 3, 2009 Share Posted May 3, 2009 hi i have creating a script in php with a query where enter a staff member first or last name, it needs to search that members record from db using their first or last name entered and display that members id, first name, last name, and contracted_hoursmon_am fields from their record in table in a table when submit form. hwover it is not doing this hope anyone can help please here is the code which doesnt seem to work form action="availablestaffdisplay.php" method="post" name="searhform" class="style6" id="searchform"> <div align="left"> <p class="style7"> </p> </div> <p> <label> name <input name="textfield" type="text" id="textfield" /> </label> <label> <input type="submit" name="submit" id="submit" value="Submit" /> <? //connect to mysql require_once('Connections/mark.php'); //-select the database to use $mydb=mysql_select_db("mark"); if(isset($_POST['submit'])){ if(isset($_GET['go'])){ if(preg_match("/^[ a-zA-Z]+/", $_POST['FirstName'])){ $FirstName=$_POST['FirstName']; //select and query the database table to record particular fields from a record from a table $result = mysql_query("select * ID, FirstName, LastName from staffmember WHERE FirstName LIKE '%" . $name . "%' OR LastName LIKE '%" . $name ."%'"; ); //-run the query against the mysql query function $result=mysql_query($sql); //grab all the field record contain from a specific table content while($r=mysql_fetch_array($result)) if(isset($_GET['by'])){ $letter=$_GET['by']; //-count results $numrows=mysql_num_rows($result); echo "<p>" .$numrows . " results found for " . $letter . "</p>"; //the format is $variable = $Row]; //modify these to match your mysql table columns while ($row = mysql_fetch_array($results)) $FirstName=$Row["FirstName"]; $LastName=$Row["LastName"]; $ID=$Row["ID"]; $contracted_hoursmon_am=$Row["contracted_hoursmon_am"]; //displaying the row echo "$'FirstName' <br> $'LastName' <br> $ID <br> $'contracted_hoursmon_am' <br> "; ?> Link to comment https://forums.phpfreaks.com/topic/156707-php-query/ Share on other sites More sharing options...
Ken2k7 Posted May 3, 2009 Share Posted May 3, 2009 First things first, read rule #13 - http://www.phpfreaks.com/page/forum-rules Second, change <? to <?php Third, is the name of that file availablestaffdisplay.php? Fourth, in your SQL, $name is undefined. $result = mysql_query("select * ID, FirstName, LastName from staffmember WHERE FirstName LIKE '%" . $name . "%' OR LastName LIKE '%" . $name ."%'"; ); Fifth, you should use mysql_real_escape_string(). Sixth, why do you have $_GET['by']? Where did that come from? Link to comment https://forums.phpfreaks.com/topic/156707-php-query/#findComment-825195 Share on other sites More sharing options...
the182guy Posted May 3, 2009 Share Posted May 3, 2009 This script won't even parse. There is a semicolon after the SQL statement which should not be there: $result = mysql_query("select * ID, FirstName, LastName from staffmember WHERE FirstName LIKE '%" . $name . "%' OR LastName LIKE '%" . $name ."%'"; ); Link to comment https://forums.phpfreaks.com/topic/156707-php-query/#findComment-825211 Share on other sites More sharing options...
markl1988 Posted May 4, 2009 Author Share Posted May 4, 2009 First things first, read rule #13 - http://www.phpfreaks.com/page/forum-rules Second, change <? to <?php Third, is the name of that file availablestaffdisplay.php? Fourth, in your SQL, $name is undefined. $result = mysql_query("select * ID, FirstName, LastName from staffmember WHERE FirstName LIKE '%" . $name . "%' OR LastName LIKE '%" . $name ."%'"; ); Fifth, you should use mysql_real_escape_string(). Sixth, why do you have $_GET['by']? Where did that come from? hi i made the chnages you have suggested however it still not retrived a member record when enter there name, do you have any of your own php scripting to do this or do u know any other ways to do this Link to comment https://forums.phpfreaks.com/topic/156707-php-query/#findComment-825546 Share on other sites More sharing options...
Ken2k7 Posted May 4, 2009 Share Posted May 4, 2009 Why is there a if (isset($_GET['go']))? Link to comment https://forums.phpfreaks.com/topic/156707-php-query/#findComment-825639 Share on other sites More sharing options...
revraz Posted May 4, 2009 Share Posted May 4, 2009 You either need to remove the semi colon from the end of the Query or put it in your Quotes. You must not have any error reporting on or you would get an error. $result = mysql_query("select * ID, FirstName, LastName from staffmember WHERE FirstName LIKE '%" . $name . "%' OR LastName LIKE '%" . $name ."%'"); $result = mysql_query("select * ID, FirstName, LastName from staffmember WHERE FirstName LIKE '%" . $name . "%' OR LastName LIKE '%" . $name ."%'"; ); hi i made the chnages you have suggested however it still not retrived a member record when enter there name, do you have any of your own php scripting to do this or do u know any other ways to do this Link to comment https://forums.phpfreaks.com/topic/156707-php-query/#findComment-825648 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.