#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    10
    Rep Power
    0
    In the following form, I CAN search by "id" but NOT "name" or anything else, and when I try to search by "name" it just spits out the contents of the entire db.


    »HTML FORM«


    <html>

    <head>
    <title>View Your Problem Status</title>
    </head>

    <body bgcolor="#0F128B">
    <div align="center"><center>

    <table border="0" width="70%" cellspacing="0" cellpadding="0" bgcolor="#FFFFFF">
    <tr>
    <td width="100%" bgcolor="#0F128B" valign="middle" align="left"><img src="http://database.techsonic.com/images/helpdesk.jpg"
    width="87" height="619" alt="Help Desk"></td>
    <td width="100%"><img src="http://database.techsonic.com/images/cornertop.jpg" width="873" height="20" alt>
    <table border="0" width="100%" bgcolor="#FFFFFF" cellspacing="0" cellpadding="0">
    <tr>
    <td>

    <form action="searchform.php" method="GET">

    </td>
    <td width="100%"><p align="center"><font face="arial" color="Navy" size="4"><b>View
    Problem Status</b></font><big><big><big> </big></big></big></p>
    <hr size="1" width="60%" noshade>
    <p align="center"><em>You can use any of the following fields to view your status</em></p>
    <p align="center"></td>
    </tr>
    </table>
    <table border="0" width="100%" bgcolor="#FFFFFF" cellspacing="0" height="325">
    <tr>
    <td width="33%" height="25"><p align="right">Get my status by reference number </td>
    <td width="67%" height="25"><input type="text" name="id" value size="10"> </td>
    </tr>
    <tr>
    <td width="33%" height="25"><p align="right">Get my status by name</td>
    <td width="67%" height="25"><input type="text" name="name" value size="20"></td>
    </tr>
    <tr>
    <td width="33%" height="25"><p align="right">Get my status by my phone extension</td>
    <td width="67%" height="25"><input type="text" name="extension" value size="20"></td>
    </tr>
    <tr>
    <td width="33%" height="25"><p align="right"></td>
    <td width="67%" height="25"><input type="hidden" name="entry_description" value=""></td>
    </tr>
    <tr>
    <td width="31%" height="21"></td>
    <td width="69%" height="21"></td>
    </tr>
    <tr>
    <td width="31%" height="21"></td>
    <td width="69%" height="21"><input type="submit" value="View Status !"></td>
    </form>
    </tr>

    <tr>
    <td width="31%" height="21"></td>
    <td width="69%" height="21"></td>
    </tr>
    <tr>
    <td width="31%" height="21"></td>
    <td width="69%" height="21"><p align='left'><a href='http://database.techsonic.com/'>Go back...</a></p></td>
    </tr>

    <tr>
    <td width="31%" height="21"></td>
    <td width="69%" height="21"></td>
    </tr>
    <tr>
    <td width="31%" rowspan="2" height="82"></td>
    <td width="69%" height="21"></td>
    </tr>
    <tr>
    <td width="69%" height="59"></td>
    </tr>
    </table>
    <p align='center'> | <a href='http://database.techsonic.com/'
    onMouseOver="window.status='Take Me To The Home Page !'; return true"
    onMouseOut="window.status=' '">Home</a> |

    <a href="http://database.techsonic.com/submitform/submitformtest.php"
    onMouseOver="window.status='Submit A New Problem To The Help Desk'; return true"
    onMouseOut="window.status=' '">New Entry</a> |

    <a href="http://database.techsonic.com/search"
    onMouseOver="window.status='Search The Help Desk For A Similar Problem You Are Having'; return true"
    onMouseOut="window.status=' '">Search Database</a> |

    <a href="http://database.techsonic.com/admin/"
    onMouseOver="window.status='Click Here To Administer The Help Desk (I.S. Only)'; return true"
    onMouseOut="window.status=' '">Entry Management </a> |</p>

    <p align="center">| <a href="http://database.techsonic.com/employeedb/empsearch.html"
    onMouseOver="window.status='Click Here For The Company Directory'; return true"
    onMouseOut="window.status=' '">Employee Search</a> |

    <a href="http://database.techsonic.com/about/"
    onMouseOver="window.status='Click Here For Information About The Help Desk'; return true"
    onMouseOut="window.status=' '">About</a> |</p>

    <p align="center">| <a href="http://database.techsonic.com/help/"
    onMouseOver="window.status='Click Here If You Need Assistance Using The Help Desk'; return true"
    onMouseOut="window.status=' '">Help</a> |</p>

    <p align="center"></p>
    <hr size="1" width="60%" noshade>
    <p align="center"><font face="arial" color="Navy" size="3"><b>Questions/Problems ? Get
    Help <em><a href="http://database.techsonic.com/help"
    onMouseOver="window.status='Click Here To Get Help'; return true"
    onMouseOut="window.status=' '">Here</a></em></b></font></p>
    <p></p>
    <p align="center"></p>
    <p></p>
    <p></p>
    <br>
    <br>
    <p><img src="http://database.techsonic.com/images/cornerbottom.jpg" width="873" height="20" alt></td>
    </tr>

    </table>
    </center></div>
    </body>
    </html>

    »SEARCHFORM.PHP«

    <html>

    <body bgcolor="#0F128B">
    <?php
    /*
    search form for "problem status"
    */

    include 'mail.inc'; // Use this for all mail procedures



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

    mysql_select_db("helpdesk",$db);

    if ($id == "")
    {$id = '%';}

    if ($name == "")
    {$extension = '%';}

    if ($extension == "")
    {$name = '%' ;}

    if ($entry_description == "")
    {$entry_description = '%' ;}


    $result = mysql_query("SELECT id, name, extension, CONCAT(LEFT(entry_description,75),'...') as first75 FROM helpdesk WHERE id LIKE '$id%'
    AND name LIKE '$name%'
    AND extension LIKE '$extension%'
    AND entry_description LIKE '$entry_description%'");

    if ($myrow = mysql_fetch_array($result)) {





    //Display page for user



    .........


    Any Ideas ? I've tried just about everything...


    Honky


  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Posts
    7
    Rep Power
    0
    What up honky,
    /* always wanted to say that */
    I had the same problem a while back.
    First off, require something from the client with some error checking. Make them have to give you their Name or something...
    then I would suggest to break the query up into possible parts of a variable so you don't have stuff in there you don't need.... i mean all the %s. That is the problem not your code.... just the query. i would use a variable and if elseif and concatenate the $query so if you are missing variables the $query just skips them.... giving you the query you need with out all the AND where hangin with nothing in there....

    example:
    if (($id == "") && ($name == "" ) && ($entry_description == "" ) && ($extension == "" )){
    print("You Must Select at Least One Field.<br><a href="javascript:history.go(-1)">Click here to go Back.</a>");
    exit();
    }

    $query = "SELECT id, name, extension, CONCAT(LEFT(entry_description,75),'...') as first75 FROM helpdesk WHERE " ;

    if ($id){
    $query .= "manufacturer = '$manufacturer' and " ;
    }
    if ($name){
    $query .= "item_type = '$item_type' and " ;
    }

    //and so on and so on till you get what you need
    //then chop off the space and the last and....
    //so your query is all happy and pretty

    $fianl_query = substr($query, 0, strlen($query)-4) ;

    hope that helps dude..
    let me know if it helped
    ccbcreg

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by honkyusa:
    In the following form, I CAN search by "id" but NOT "name" or anything else, and when I try to search by "name" it just spits out the contents of the entire db.


    »HTML FORM«


    <html>

    <head>
    <title>View Your Problem Status</title>
    </head>

    <body bgcolor="#0F128B">
    <div align="center"><center>

    <table border="0" width="70%" cellspacing="0" cellpadding="0" bgcolor="#FFFFFF">
    <tr>
    <td width="100%" bgcolor="#0F128B" valign="middle" align="left"><img src="http://database.techsonic.com/images/helpdesk.jpg"
    width="87" height="619" alt="Help Desk"></td>
    <td width="100%"><img src="http://database.techsonic.com/images/cornertop.jpg" width="873" height="20" alt>
    <table border="0" width="100%" bgcolor="#FFFFFF" cellspacing="0" cellpadding="0">
    <tr>
    <td>

    <form action="searchform.php" method="GET">

    </td>
    <td width="100%"><p align="center"><font face="arial" color="Navy" size="4"><b>View
    Problem Status</b></font><big><big><big> </big></big></big></p>
    <hr size="1" width="60%" noshade>
    <p align="center"><em>You can use any of the following fields to view your status</em></p>
    <p align="center"></td>
    </tr>
    </table>
    <table border="0" width="100%" bgcolor="#FFFFFF" cellspacing="0" height="325">
    <tr>
    <td width="33%" height="25"><p align="right">Get my status by reference number </td>
    <td width="67%" height="25"><input type="text" name="id" value size="10"> </td>
    </tr>
    <tr>
    <td width="33%" height="25"><p align="right">Get my status by name</td>
    <td width="67%" height="25"><input type="text" name="name" value size="20"></td>
    </tr>
    <tr>
    <td width="33%" height="25"><p align="right">Get my status by my phone extension</td>
    <td width="67%" height="25"><input type="text" name="extension" value size="20"></td>
    </tr>
    <tr>
    <td width="33%" height="25"><p align="right"></td>
    <td width="67%" height="25"><input type="hidden" name="entry_description" value=""></td>
    </tr>
    <tr>
    <td width="31%" height="21"></td>
    <td width="69%" height="21"></td>
    </tr>
    <tr>
    <td width="31%" height="21"></td>
    <td width="69%" height="21"><input type="submit" value="View Status !"></td>
    </form>
    </tr>

    <tr>
    <td width="31%" height="21"></td>
    <td width="69%" height="21"></td>
    </tr>
    <tr>
    <td width="31%" height="21"></td>
    <td width="69%" height="21"><p align='left'><a href='http://database.techsonic.com/'>Go back...</a></p></td>
    </tr>

    <tr>
    <td width="31%" height="21"></td>
    <td width="69%" height="21"></td>
    </tr>
    <tr>
    <td width="31%" rowspan="2" height="82"></td>
    <td width="69%" height="21"></td>
    </tr>
    <tr>
    <td width="69%" height="59"></td>
    </tr>
    </table>
    <p align='center'> | <a href='http://database.techsonic.com/'
    onMouseOver="window.status='Take Me To The Home Page !'; return true"
    onMouseOut="window.status=' '">Home</a> |

    <a href="http://database.techsonic.com/submitform/submitformtest.php"
    onMouseOver="window.status='Submit A New Problem To The Help Desk'; return true"
    onMouseOut="window.status=' '">New Entry</a> |

    <a href="http://database.techsonic.com/search"
    onMouseOver="window.status='Search The Help Desk For A Similar Problem You Are Having'; return true"
    onMouseOut="window.status=' '">Search Database</a> |

    <a href="http://database.techsonic.com/admin/"
    onMouseOver="window.status='Click Here To Administer The Help Desk (I.S. Only)'; return true"
    onMouseOut="window.status=' '">Entry Management </a> |</p>

    <p align="center">| <a href="http://database.techsonic.com/employeedb/empsearch.html"
    onMouseOver="window.status='Click Here For The Company Directory'; return true"
    onMouseOut="window.status=' '">Employee Search</a> |

    <a href="http://database.techsonic.com/about/"
    onMouseOver="window.status='Click Here For Information About The Help Desk'; return true"
    onMouseOut="window.status=' '">About</a> |</p>

    <p align="center">| <a href="http://database.techsonic.com/help/"
    onMouseOver="window.status='Click Here If You Need Assistance Using The Help Desk'; return true"
    onMouseOut="window.status=' '">Help</a> |</p>

    <p align="center"></p>
    <hr size="1" width="60%" noshade>
    <p align="center"><font face="arial" color="Navy" size="3"><b>Questions/Problems ? Get
    Help <em><a href="http://database.techsonic.com/help"
    onMouseOver="window.status='Click Here To Get Help'; return true"
    onMouseOut="window.status=' '">Here</a></em></b></font></p>
    <p></p>
    <p align="center"></p>
    <p></p>
    <p></p>
    <br>
    <br>
    <p><img src="http://database.techsonic.com/images/cornerbottom.jpg" width="873" height="20" alt></td>
    </tr>

    </table>
    </center></div>
    </body>
    </html>

    »SEARCHFORM.PHP«

    <html>

    <body bgcolor="#0F128B">
    <?php
    /*
    search form for "problem status"
    */

    include 'mail.inc'; // Use this for all mail procedures



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

    mysql_select_db("helpdesk",$db);

    if ($id == "")
    {$id = '%';}

    if ($name == "")
    {$extension = '%';}

    if ($extension == "")
    {$name = '%' ;}

    if ($entry_description == "")
    {$entry_description = '%' ;}


    $result = mysql_query("SELECT id, name, extension, CONCAT(LEFT(entry_description,75),'...') as first75 FROM helpdesk WHERE id LIKE '$id%'
    AND name LIKE '$name%'
    AND extension LIKE '$extension%'
    AND entry_description LIKE '$entry_description%'");

    if ($myrow = mysql_fetch_array($result)) {





    //Display page for user



    .........


    Any Ideas ? I've tried just about everything...


    Honky

    [/quote]

  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    10
    Rep Power
    0
    I can't see how that would solve my query problem. I'll give it a try though
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Posts
    6
    Rep Power
    0
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by honkyusa:
    I can't see how that would solve my query problem. I'll give it a try though[/quote]

    I know it's kind of obvious, have you tried dumping the sql onto the screen, then looking at it and running it against the databse, get it to work, then go back and chnage your code to produce the correct sql.

  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Posts
    7
    Rep Power
    0
    i agree.....
    test the query on the command line.... if it files with all the % then you must look at the form .... but i am thinking the query is just a tricky one.
    *shrugs*
    ccbcreg

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by winzurf:
    I know it's kind of obvious, have you tried dumping the sql onto the screen, then looking at it and running it against the databse, get it to work, then go back and chnage your code to produce the correct sql.

    [/quote]

  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    10
    Rep Power
    0
    I'm having probs with the code. How do I properly terminate the query string ? right now, when I run this script it gives me a blank page, no errors

    <html>
    <?
    $db = mysql_connect("localhost", "web", "web");

    mysql_select_db("helpdesk",$db);


    if($submit){
    if (($id == "") && ($name == "" ) && ($entry_description == "" ) && ($extension == ""
    )){
    print("You Must Select at Least One Field.<br><a
    href="javascript:history.go(-1)">Click here to go Back.</a>");
    exit();
    }

    $query = "SELECT id, name, extension, CONCAT(LEFT(entry_description,75),'...') as
    first75 FROM helpdesk WHERE " ;

    if ($id){
    $query .= "id = '$id' " ;
    }
    if ($name){
    $query .= "name = '$name' " ;
    }
    if ($extension){
    $query .= "extension = '$extension' " ;
    }
    $query .=";";
    $final_query = substr($query, 0, strlen($query)-4) ;

    $result = mysql_query($final_query);

    if ($myrow = mysql_fetch_array($result)) {


    echo"<table border='1' width='100%' <tr bgcolor="d7deff"><tr><td width='7%'>id</td><td width='18%'>Name</td><td width='10%'>Extension</td><td width='65%'>Problem Description</td></tr>";

    //Crank out the table results

    $num = mysql_num_rows($result);

    $i=0;
    while ($i<$num) {

    $id=mysql_result($result,$i,"id");
    $name=mysql_result($result,$i,"name");
    $extension=mysql_result($result,$i,"extension");
    $first75=mysql_result($result,$i,"first75");

    //Alternate row colors in the table
    print ($i%2)?"<tr bgcolor="D7DEFF">":"<tr bgcolor="C2CCFF">";

    print "<td>$id</td><td>$name</td>";
    print "<td>$extension</td><td><a href='http://database.techsonic.com/admin/editdb.php?id=$id'>$first75</a></td>";

    ++$i;

    }
    }
    }
    ?>
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    10
    Rep Power
    0
    WTF, the query works fine when I dump it to the command line. Ok, then your right, it has to be the form.... but what ?
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Posts
    7
    Rep Power
    0
    honky......
    what up dude..
    sounds like your query is cool..... and if your form is passing the correct info..... i would make sure of this by just printing the variables at the top of the page that get passed to the query......
    btw you didn't close the table in the code above that could f*ck up in netscape....


    so
    1. pass the varialbes and print them to screen so you can see that your form isn't all gizzed up.
    2. make sure your query (you already did this) works with those variables
    3. make sure your display code is straight.... looks funky but working.... i try this man,...... works for me....


    $row1 = "#ffffff";
    $row2 = "#ebebeb";
    $rowcolor = $row1;

    while (($row = mysql_fetch_object($result))){

    printf("<tr bgcolor="%s">
    <td valign="top"><font face="Arial" size="-2">%s</font></td>
    <td valign="top"><font face="Arial" size="-2">%s</font></td>
    <td valign="top"><font face="Arial" size="-2">%s</font></td>
    <td valign="top"><font face="Arial" size="-2">%s</font></td></tr>",
    $rowcolor, $row->item_code, $row->item_number, $row->manufacturer, $row->description) ;
    if ($rowcolor == $row1){
    $rowcolor = $row2;
    }else{
    $rowcolor = $row1;
    }

    you know the saying "less is more"
    hope that helps man.....
    ccbcreg


    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by honkyusa:
    WTF, the query works fine when I dump it to the command line. Ok, then your right, it has to be the form.... but what ?[/quote]



    [This message has been edited by ccbcreg (edited November 21, 2000).]
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    10
    Rep Power
    0
    This hole problem was based on the fact that I'm semi-dyslexic. Check out the following code fragment:


    if ($id == "")
    {$id = '%';}

    if ($name == "")
    {$extension = '%';}

    if ($extension == "")
    {$name = '%' ;}

    if ($entry_description == "")
    {$entry_description = '%' ;}

    Problem solved..... Sorry for taking up everyones time,


    The dyslexic Honky

IMN logo majestic logo threadwatch logo seochat tools logo