SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Addict
    Join Date
    Jan 2007
    Posts
    296
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    If Statement Trouble

    I am trying to combine an if statement with a case statement which is needed to determine which submit button the user has clicked on the form from the previous page.

    The form page

    Code:
    <FORM ACTION="ordersearchresults.php" METHOD="GET" NAME="frmSearchCriteria">
    
    <table class="searchtable">
                          <tr>
                             <td class="leftside">Choose Category :</td>
    <td>
    <select name="type">
    <option value="ordernumber">OrderNumber</option>
    <option value="partnumber">PartNumber</option>
    <option value="accountname">AccountName</option>
    </select>
    </td>
    </tr>
    
    <tr>
                             <td class="leftside">Enter Keyword:</td>
    <td><input type="text" name="keyword"></td>
    </tr>
    
    <tr>
    
    <td class="leftside"><INPUT TYPE="Submit" name="exact match" VALUE="Exact Match"></td>
    <td class="leftside"><INPUT TYPE="Submit" name="contains" VALUE="Contains"></td>
    </tr>
    </FORM>

    The following page is where I am getting my error

    Code:
    <?php
    
    
    require_once('databaseconnection.php'); 
    
    $keywordentered = $_GET['keyword']; 
     
    switch($_GET['type']) {
      case 'ordernumber':
      if ($_GET['contains']) {
         $result = odbc_exec($odbc, "SELECT * FROM orderpartnumbertable WHERE Order_No LIKE '".$keywordentered."%'"); }
    	 else {
    	 $result = odbc_exec($odbc, "SELECT * FROM orderpartnumbertable WHERE Order_No LIKE $keywordentered" ); }
        break;
      case 'partnumber':
       if ($_GET['contains']) {
         $result = odbc_exec($odbc, "SELECT * FROM orderpartnumbertable WHERE Part_No LIKE '".$keywordentered."%'"); }
    	 else {
    	 $result = odbc_exec($odbc, "SELECT * FROM orderpartnumbertable WHERE Part_No LIKE $keywordentered"); }
        break;
      case 'accountname':
        if ($_GET['contains']) {
         $result = odbc_exec($odbc, "SELECT * FROM orderpartnumbertable WHERE Account_Name LIKE '".$keywordentered."%'"); }
    	 else
    	 $result = odbc_exec($odbc, "SELECT * FROM orderpartnumbertable WHERE Account_Name LIKE $keywordentered" ); 
        break;
    }
    
    echo '<table class="table">';
    echo '<tr><th>Order Number</th><th>Part Number</th><th>Part Description</th><th>Order Quantity</th><th>Order Date</th><th>Account Name</th><th>More Info</th></tr>';
    while (($row = odbc_fetch_array($result)) !== false) {
    echo '<tr>';
    echo '<td>' . $row['Order_No'] . '</td>';
    echo '<td>' . $row['Part_No'] . '</td>';
    echo '<td>' . $row['Part_Description'] . '</td>';
    echo '<td>' . $row['Order_Qty'] . '</td>';
    echo '<td>' . $row['Order_Date'] . '</td>';
    echo '<td>' . $row['Account_Name'] . '</td>';
    echo '<td>' . '<a href="ordersearchdetails.php?fnp_site=' . rawurlencode($row['FNP_Site']) . '">More Info</a>' . '</td>'; 
    echo '</tr>';
    }
    echo '</table>'; 
    ?>
    The lines in red are where the error is occurring and here is the error
    Code:
    Warning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1., SQL state 07001 in SQLExecDirect in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\swiftdist\ordersearch\ordersearchresults.php on line 30
    This relates to the first red line but the second red line brings up the same error.

  2. #2
    Chessplayer kleineme's Avatar
    Join Date
    Apr 2004
    Location
    Germany
    Posts
    608
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just a guess: you don't have quotation marks around $keywordentered in those red lines.
    Never ascribe to malice,
    that which can be explained by incompetence.
    Your code should not look unmaintainable, just be that way.

  3. #3
    SitePoint Addict
    Join Date
    Jan 2007
    Posts
    296
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't have it on my first one either are they needed??? I have tried various ways but it still doesn't work, what is the correct way to create that line???

    Cheers

  4. #4
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,804
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    You stil need sinqle quotes around the variable....

    PHP Code:
     $result odbc_exec($odbc"SELECT * FROM orderpartnumbertable WHERE Part_No LIKE '$keywordentered'"); } 
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  5. #5
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up

    May I suggest a more efficient way of doing it?

    PHP Code:
    <?php
    require_once('databaseconnection.php'); 
    $keywordentered $_GET['keyword']; 
    $possarray = array("ordernumber" => "Order_No""partnumber" => "Part_No""accountname" => "Account_Name");
    if (
    $_GET['contains']) {
        
    $querystring "SELECT * FROM orderpartnumbertable WHERE %s LIKE '%%%s%%'";
    }else{
        
    $querystring "SELECT * FROM orderpartnumbertable WHERE %s LIKE '%s'";
    }
    $result mysql_query(sprintf($querystring$_GET['type'], $possarray[$keywordentered]));
    echo 
    "<table class=\"table\">\n<tr><th>Order Number</th><th>Part Number</th><th>Part Description</th><th>Order Quantity</th><th>Order Date</th><th>Account Name</th><th>More Info</th></tr>";
    while (
    $row odbc_fetch_array($result)) {
        echo 
    '<tr>';
        
    $displayarray = array("Order_No""Part_No""Part_Description""Order_Qty""Order_Date""Account_Name");
        foreach(
    $displayarray as $value){
            
    printf("<td>%s</td>"$row[$value]);
        }
        
    printf("<td><a href=\"ordersearchdetails.php?fnp_site=%s\">More Info</a></td>\n</tr>"rawurlencode($row['FNP_Site']));
    }
    echo 
    "</table>"
    ?>
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  6. #6
    SitePoint Addict
    Join Date
    Jan 2007
    Posts
    296
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cheers for the help guys I will look into them examples and see what I get.

    I now have another simple error i think. I am trying to pass 2 values via a link but can't get it to work with 2 variables in the code.

    Code:
    echo '<td>' . '<a href="ordersearchdetails.php?fnp_site=' . rawurlencode($row['FNP_Site']) . & Order_No='. rawurlencode($row['Order_No'])' . '">More Info</a>' . '</td>';
    I am getting the following error


    Parse error: parse error, unexpected '&' in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\swiftdist\ordersearch\ordersearchresults.php on line 49


    I have tried various ways but can't get it to work so any help most appreciated.

    Cheers

  7. #7
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    you're missing a quote after the first variable:
    PHP Code:
    echo '<td><a href="ordersearchdetails.php?fnp_site=' rawurlencode($row['FNP_Site']) . '&Order_No='rawurlencode($row['Order_No'])' . '">More Info</a>' . '</td>'; 
    However, for readability I would suggest using printf():
    PHP Code:
    printf("<td><a href=\"ordersearchdetails.php?fnp_site=%s&Order_No=%s\">More Info</a></td>"rawurlencode($row['FNP_Site']), rawurlencode($row['Order_No'])); 
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  8. #8
    SitePoint Addict
    Join Date
    Aug 2007
    Posts
    365
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you also have a extra quote after the second varible

    PHP Code:
    echo '<td><a href="ordersearchdetails.php?fnp_site=' rawurlencode($row['FNP_Site']) . '&Order_No='rawurlencode($row['Order_No']) . '">More Info</a>' '</td>'

  9. #9
    SitePoint Addict
    Join Date
    Jan 2007
    Posts
    296
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cheers for the help guys most appreciated.


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
  •