Jump to content

php query


markl1988

Recommended Posts

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

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.