+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: sql query

  1. #1
    markl1988 is offline x10Hosting Member markl1988 is an unknown quantity at this point
    Join Date
    May 2009
    Posts
    8

    sql query

    hi

    i am trying to use an sql query which when you enter enter first or last name which excists in the table table, it should search the db and show the results id, first name, last name, and contratced_hoursmon_am fields from the record in database matching name entered on form and name field with a database record. however i am having huge problems executing this query, here is the code i am trying to use.

    <?php // connects to database
    require_once('Connections/mark.php');
    error_reporting(E_ALL);
    ini_set('display_errors', 'On');

    if(isset($_POST['submit'])){
    if(isset($_GET['go'])){
    if(preg_match("/^[ a-zA-Z]+/", $_POST['name'])){
    $name=$_POST['name'];
    // get variables
    if(isset($_POST['ID'])){
    $ID = $_POST['ID'];}
    // Open an sql query

    $sql = "SELECT* ID, FirstName, LastName, contracted_hoursmon_am, FROM staffmember tbl".;
    $result=mysql_query($query);
    $numrows=mysql_num_rows($result);
    // Loop through the results of the query
    while($row=mysql_fetch_array($result)){
    // Get the variable results
    $ID = $conn->$row['ID'];
    $FirstName = $conn->row['FirstName'];
    $LastName = $conn->row['LastName'];
    $contraced_hoursmon_am = $conn->row['contracted_hoursmon_am'];

    while($row=mysql_fetch_assoc($result))

    echo $FirstName=$row["FirstName"];
    echo $LastName=$row["LastName"];
    echo $ID=$row["ID"];
    echo $contracted_hoursmon_am=$row["contracted_hoursmon_am"];
    // print the variables fields retrieved from the record in database from the record with name enterd on form matching a name filed from a record in database
    print_r($var);"$v'ID' <br>$v'FirstName' <br> $v'LastName' <br>$v'contracted_hoursmon_am' <br> ";
    ?>
    <option value="<?=$ID?>" selected><?=($FirstName." ".$LastName)?></option>
    <?php

    }
    // Closes the query

    // Closes connection to database
    ?>

  2. #2
    garrettroyce's Avatar
    garrettroyce is offline Generally Helpful Member garrettroyce is a glorious beacon of lightgarrettroyce is a glorious beacon of light
    Join Date
    Apr 2008
    Location
    IL, USA
    Posts
    3,746

    Re: sql query

    Code:
    $sql = "SELECT* ID, FirstName, LastName, contracted_hoursmon_am, FROM staffmember tbl"; // there's a . here that doesn't belong
    $result=mysql_query($query);
    //$numrows=mysql_num_rows($result); you should check if $result is valid before doing any operation on it
    if (!$result) {
         exit(mysql_error());
    }
    if (mysql_num_rows($result) == 0) {
         exit('No rows found');
    }
    gjr.gr - coming soon: secrets of OCD coding from a self taught tinkerer

  3. #3
    markl1988 is offline x10Hosting Member markl1988 is an unknown quantity at this point
    Join Date
    May 2009
    Posts
    8

    Re: sql query

    now its saying i have a parse error on line 275, not even next to the code next to the </body> for some reason.

  4. #4
    garrettroyce's Avatar
    garrettroyce is offline Generally Helpful Member garrettroyce is a glorious beacon of lightgarrettroyce is a glorious beacon of light
    Join Date
    Apr 2008
    Location
    IL, USA
    Posts
    3,746

    Re: sql query

    You might be missing a ; } ) etc
    gjr.gr - coming soon: secrets of OCD coding from a self taught tinkerer

  5. #5
    markl1988 is offline x10Hosting Member markl1988 is an unknown quantity at this point
    Join Date
    May 2009
    Posts
    8

    Re: sql query

    thanks

    i have found the parse error and solved the other problem howver when i upload page to testing server it has no errors but when i enter a name and submit the form, it displays no reuslts at all for that member name entered on the form for some reason.

  6. #6
    xav0989's Avatar
    xav0989 is offline Community Public Relation xav0989 is just really nice
    Join Date
    Jul 2008
    Location
    ifk
    Posts
    4,438

    Re: sql query

    Quote Originally Posted by markl1988 View Post
    echo $FirstName=$row["FirstName"];
    echo $LastName=$row["LastName"];
    echo $ID=$row["ID"];
    echo $contracted_hoursmon_am=$row["contracted_hoursmon_am"];
    It is quite normal that you don't see anything, as you are doing an echo not on the values, but on the result of the assignment.
    Xavier L | Community Public Relations Manager (Free Hosting Support)
    █ Yes, my position is too cool to even exist!
    How am I helping? Rate this post by clicking the icon below! (this is even better than "liking" a post)
    Terms of Service | Acceptable Use Policy | x10Hosting Wiki

  7. #7
    markl1988 is offline x10Hosting Member markl1988 is an unknown quantity at this point
    Join Date
    May 2009
    Posts
    8

    Re: sql query

    thanks

    so what do u suggest to use to be able to display the reuslts other than the echo fucntion

  8. #8
    garrettroyce's Avatar
    garrettroyce is offline Generally Helpful Member garrettroyce is a glorious beacon of lightgarrettroyce is a glorious beacon of light
    Join Date
    Apr 2008
    Location
    IL, USA
    Posts
    3,746

    Re: sql query

    echo isn't the problem, the problem is PHP evaluates this:
    Code:
    echo $var = $array['index'];
    in two steps:
    Code:
    $var = $array['index'];
    Code:
    echo ???
    The ??? is what $var=$array['index'] is equal to. It's an expression, not a value. This would be what you want to do:
    Code:
    $var=$array['index'];
    $var2=$array['index2'];
    echo $var;
    echo $var2;
    echo 'text';
    echo $var, $var2, 'text'; // or you can do it this way
    gjr.gr - coming soon: secrets of OCD coding from a self taught tinkerer

  9. #9
    markl1988 is offline x10Hosting Member markl1988 is an unknown quantity at this point
    Join Date
    May 2009
    Posts
    8

    Re: sql query

    i tried that solution but still not displaying any records, i dunno what else could be done to solve this.

  10. #10
    garrettroyce's Avatar
    garrettroyce is offline Generally Helpful Member garrettroyce is a glorious beacon of lightgarrettroyce is a glorious beacon of light
    Join Date
    Apr 2008
    Location
    IL, USA
    Posts
    3,746

    Re: sql query

    Try changing your query to this:

    Code:
    $sql = "SELECT ID, FirstName, LastName, contracted_hoursmon_am, FROM staffmember";
    Last edited by garrettroyce; 05-29-2009 at 01:48 PM.
    gjr.gr - coming soon: secrets of OCD coding from a self taught tinkerer

+ Reply to Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. Help with SQL Query..
    By Derek in forum The Marketplace
    Replies: 1
    Last Post: 08-03-2008, 02:32 AM
  2. What's wrong with this SQL Query?
    By Derek in forum The Marketplace
    Replies: 3
    Last Post: 07-23-2008, 10:00 PM
  3. Problems with SQL query
    By anilson1 in forum Free Hosting
    Replies: 3
    Last Post: 04-28-2008, 10:55 PM
  4. [BEG] How to run a SQL query in phpMyAdmin
    By Brandon in forum Tutorials
    Replies: 0
    Last Post: 04-14-2007, 09:17 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers