PHP to ASP

Discussion in 'Programming' started by psradich, Jul 19, 2007.

  1. #1
    OK I'm one of those designers that on occasion have to do the development myself. I'm no guru but it usually works. Not this time. I had a simple search function fully working in PHP but when the client switched servers on me ASP was required.

    Now I can't my PHP code to translate to ASP. Here is the code it reads a URL variable from a form via the POST method and performs a search on the database yielding the results.

    Can anyone help me rewrite this for ASP and an access database?

    <?php
    $search=$_POST["search"];
    mysql_select_db($database_login, $login);
    $query_Recordset3 = "SELECT * FROM pmp WHERE dateadded LIKE '%$search%' OR filename LIKE '%$search%' OR discrip LIKE '%$search%'";
    $Recordset3 = mysql_query($query_Recordset3, $login) or die(mysql_error());
    $row_Recordset3 = mysql_fetch_assoc($Recordset3);
    $totalRows_Recordset3 = mysql_num_rows($Recordset3);
    ?>

    Thanks
     
    psradich, Jul 19, 2007 IP
  2. ProgrammersTalk

    ProgrammersTalk Peon

    Messages:
    684
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You will need OBDC
     
    ProgrammersTalk, Jul 19, 2007 IP
  3. AstarothSolutions

    AstarothSolutions Peon

    Messages:
    2,680
    Likes Received:
    77
    Best Answers:
    0
    Trophy Points:
    0
    #3
    classic ASP or ASP.Net?
     
    AstarothSolutions, Jul 20, 2007 IP
  4. psradich

    psradich Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Clasic ASP and I know I need to use OBDC I just can't get it to work correctly

    This is what I have

    <%
    Dim Recordset1
    Dim Recordset1_cmd
    Dim Recordset1_numRows
    'dim search

    search = CStr(Request("search"))

    Set Recordset1_cmd = Server.CreateObject ("ADODB.Command")
    Recordset1_cmd.ActiveConnection = MM_files_STRING
    Recordset1_cmd.CommandText = "SELECT * FROM pmp WHERE dateadded LIKE '& search &' OR filename LIKE ' & search & ' OR discrip LIKE '& search &'"
    Recordset1_cmd.Prepared = true

    Set Recordset1 = Recordset1_cmd.Execute
    Recordset1_numRows = 0
    %>

    I think I'm close but I could be way off. Please Help.

    Thanks
     
    psradich, Jul 20, 2007 IP
  5. KalvinB

    KalvinB Peon

    Messages:
    2,787
    Likes Received:
    78
    Best Answers:
    0
    Trophy Points:
    0
    #5
    KalvinB, Jul 20, 2007 IP
  6. psradich

    psradich Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I don't have a problem connecting to the database. I guess my question is how to call the url variable in the WHERE statement?
     
    psradich, Jul 20, 2007 IP
  7. amf-flt

    amf-flt Active Member

    Messages:
    100
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    58
    #7
    Off the top of my head, one thing I see wrong is that you aren't putting "*" around the search string (which is what Access likes where mySQL wants "%"). So you want to do

    search = "*" & search & "*"

    before the query string that includes it. Then the LIKE portions will work better.
     
    amf-flt, Jul 20, 2007 IP