SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: Search Function

  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2005
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation Search Function

    hey I having a problem wth search it is not allowing me to search what I want it is just coming up with errors

    this the code I have done so far

    search.php
    PHP Code:
     <? 

    $conn 
    mysql_connect("localhost","root","") or die("Could Not Connect To The Database"); 
            
    mysql_select_db("aziz",$conn) or die("Could Not Select The Database"); 

    if (
    $_POST['submitForm']) {
    $sql "INSERT INTO search (text) VALUES '".$_POST['text']."'";
    mysql_query($sql) or die("Couldn't update information.");
    }

    if (
    $title == ""
    {
    $title 'Nothing!';} 

    if (
    $text == ""
    {
    $text 'nothing';} 

    $result mysql_query ("SELECT * FROM azizpassword WHERE text LIKE '%$text%'"); 

    if (
    $row mysql_fetch_array($result)) { 

      PRINT 
    "<font face=tahoma size=2>Your search for <b>$text</b> returned the following results:<br><br>"

    do { 
      
    $record_text $row[3]; 
      
    $text_limit substr($record_text0300); 
      PRINT 
    "<font face=tahoma size=2><b>"
      print 
    "<a href=\"solution.php?id=$row[id]\">$row[title]</a>"
      print (
    "</b> "); 
      print (
    "<br>"); 
      print 
    $text_limit
      print (
    "...<p>"); 
    } while(
    $row mysql_fetch_array($result)); 
    } else { 

    PRINT 
    "<font face=tahoma size=2>Your search for <b>$text</b> returned 0 results:<br><br>"


    ?> 
    search: 
    <input type=password name=pass>
    <br>
    <br>
    <input type=submit value=Search></form></body></html>
    basically, its not functioning properly. What i want it to do, is return a view of what i search. This is a table that i already have working:

    tableview.php
    PHP Code:
    <?php 
            $conn 
    mysql_connect("localhost","root","") or die("Could Not Connect To The Database"); 
            
    mysql_select_db("aziz",$conn) or die("Could Not Select The Database"); 
              
    if(isset(
    $_GET['action'])) { 
    if(
    $action == "delete") { 
    $user_id $_GET['user_id']; 
    $delete mysql_query("delete from azizpassword where user_id = '$user_id'") or die(mysql_error()); 
    # you can then put a header("Location: ..."); to go somewhere else 
        


        
    $result=mysql_query("SELECT user_id,az_firstname,az_surname,username FROM azizpassword ORDER BY user_id;"); 
          
        
    $i=0
        while( 
    $row=mysql_fetch_array($result) ) 
        { 
            if(
    $i>0
            { 
                echo 
    "<tr valign=top>"
                echo 
    "<td bgcolor=#93B0B4 colspan=4><img src=img/blank.gif wuser_idth=1 height=1></td>"
                echo 
    "</tr>"
            } 
            echo 
    "<tr valign=center>"
            echo 
    "<td width=100 class=table><b>".$row['user_id']."</b></td>"
            echo 
    "<td width=100 class=table><a href=\"edituser.php?id=".$row['user_id']."\">".$row['az_surname']."</a></td>"
            echo 
    "<td width=100 class=table>".$row['az_firstname']." </td>"
            echo 
    "<td width=100 class=table><i>".$row['username']."</i> </td>"
            
    //echo "<td width=100 class=table><i><a href=\"?action=delete&user_id=".$row['user_id']."\"> delete: ".$row['username']."</a></i> </td>"; 
            
    echo "<td width=100 class=table><i><a href=\"?action=delete&user_id=".$row['user_id']."\" onclick=\"if(confirm('Are you sure you want to delete the entry?')) return true; else alert('Delete canceled.');return false;\"> delete: ".$row['username']."</a></i> </td>"


            echo 
    "<td class=table></td>"
            echo 
    "</tr>"
            
    $i++; 

        } 

        echo 
    "<tr valign=bottom>"
            echo 
    "<td bgcolor=#93B0B4 colspan=6 height=8></td>"
            echo 
    "</tr>"
    echo
    "<h4>To Edit a User please click on the users Surname.</h4>";
          
    ?>
    any suggestions as to why my search isn't working properly???? is there a way to include the search in the tableview.php i posted using code from the search.php file? linking the two with an if-else statement?? that would be a better option

    Inevitably i would like the results to come out the same way as they do in the tableview.php file i pasted above.

    If someone can help me out with this i'd be very greatful, thanks a lot in advance.

  2. #2
    SitePoint Addict DM3Dan's Avatar
    Join Date
    Sep 2004
    Location
    Albany, NY
    Posts
    204
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am looking at your code, but just as a quick note, you used short tags in search.php .

    Ok, first off, is
    PHP Code:
    echo "<td bgcolor=#93B0B4 colspan=4><img src=img/blank.gif wuser_idth=1 height=1></td>"
    proper code? I have never heard of wuser_idth=1, but that just might be me sucking .

    Second, in 'search.php' did you ever open the <form> tag? I see </form>, but no opening tag.

    Hopefully, I hoped somewhat, too bad $i != 'good at php'!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •