Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.

Cheers,
Kirupa

Results 1 to 7 of 7

Thread: Displaying PHP/SQL problems.

  1. #1
    58
    posts
    Registered User

    Displaying PHP/SQL problems.

    Hi!

    I'm having problems displaying some results from a SQL query. I just get the error message. Hope someone can help me with this. i'm kind of a PHP/SQL noob.

    PHP Code:

    if(isset($_POST['send'])) {  
          
       { 
     
       if (isset(
    $_POST['allemerke'])) {
      
      
    $query1 "SELECT FROM `forhandlere` LIKE fylke='$_POST[fylke]' AND funksjon='%$_POST[funksjon]%'";  

    $result mysql_query("$query1") or die('<p class="error">There was an unexpected error grabbing from the database.1</p>'); 

    while (
    $row mysql_fetch_array($result)) {  

        
    $elogo = ($row['logo']);
        
    $ename = ($row['navn']);
        
    $fylke = ($row['fylke']);
        
    $eemail = ($row['merke']);
        
    $efunksjon = ($row['funksjon']);
        
    $eepost = ($row['text']);
        
    $eweb = ($row['web']);
       
        echo(
    '<p>dette vises dersom bare velg alle på merket er haket av.</p>');
        echo (
    '<table style="width:400px;">');
        echo 
    "<tr>";
        echo 
    "<td>";
        echo(
    '<p><img src="'.$elogo.'" /><br />
        <b>'
    .$ename.'</b><br />
        '
    .$fylke.'<br />
        '
    .$eemail.'<br />
        '
    .$efunksjon.'<br />
        '
    .$eepost.'<br />
        <a href="http://'
    .$eweb.'" rel="nofollow" target="_blank">'.$eweb.'</a></p>');
        echo 
    "</td>";
        echo 
    "</tr>";
        echo 
    "</table>";
        
    }



  2. #2
    439
    posts
    Registered User
    Hi, you had a closing bracket missing and I don't think your query was correct either. I've tinkered with your code, try this and see if it works:

    PHP Code:
    <?php

    if(isset($_POST['send']))


        if(isset(
    $_POST['allemerke']))
        {
      
            
    $query1 "SELECT FROM forhandlere  fylke LIKE'"$_POST['fylke']."' AND funksjon LIKE '%".$_POST['funksjon']."%'";  
              
    $result mysql_query($query1) or die('<p class="error">There was an unexpected error grabbing from the database.1</p>'); 

            while (
    $row mysql_fetch_array($result)) 
            {  

                
    $elogo = ($row['logo']);
                
    $ename = ($row['navn']);
                
    $fylke = ($row['fylke']);
                
    $eemail = ($row['merke']);
                
    $efunksjon = ($row['funksjon']);
                
    $eepost = ($row['text']);
                
    $eweb = ($row['web']);
       
                echo(
    '<p>dette vises dersom bare velg alle på merket er haket av.</p>');
                echo (
    '<table style="width:400px;">');
                echo 
    "<tr>";
                echo 
    "<td>";
                echo(
    '<p><img src="'.$elogo.'" /><br /><b>'.$ename.'</b><br />'.$fylke.'<br />'.$eemail.'<br />'.$efunksjon.'<br />'.$eepost.'<br /><a href="http://'.$eweb.'" rel="nofollow" target="_blank">'.$eweb.'</a></p>');
                echo 
    "</td>";
                echo 
    "</tr>";
                echo 
    "</table>";
        
            }
        
        }

    }  

    ?>
    Cheers, hope this helps
    while ( ! ( succeed = try() ) );

  3. #3
    58
    posts
    Registered User

    Thanks a lot!

    Thanks a lot!

    Please don't get bored with me, i'm kind of new here. But this is one of four similar codes, one for each check box from my form.
    My form are holding to check boxes so there is one code for each possibility.

    Here is the boxes:

    Code:
    <input type="checkbox" name="allemerke" id="allemerke" />
    <input type="checkbox" name="allefunksjon" id="allefunksjon" />
    And here is the code:

    1.:
    PHP Code:
    if(empty($_POST['allefunksjon']) and empty($_POST['allemerke'])) {
      
      
    $query "SELECT * FROM `forhandlere` WHERE fylke='$_POST[fylke]' AND (funksjon) LIKE '%$_POST[funksjon]%' AND (merke) LIKE '%$_POST[merke]%'";

    $result mysql_query("$query") or die('<p class="error">There was an unexpected error grabbing from the database.</p>'); 
    2.:
    PHP Code:
    if (isset($_POST['allemerke'])) {

    $query1 "SELECT * FROM `forhandlere` WHERE fylke='$_POST[fylke]' AND (funksjon) LIKE '%$_POST[funksjon]%'"

    $result1 mysql_query("$query1") or die('<p class="error">There was an unexpected error grabbing from the database.1</p>'); 
    3:
    PHP Code:
    if(isset($_POST['allefunksjon']) and isset($_POST['allemerke'])) {
      
      
    $query2 "SELECT * FROM `forhandlere` WHERE fylke='$_POST[fylke]';";  

    $result2 mysql_query("$query2") or die('<p class="error">There was an unexpected error grabbing from the database.2</p>'); 
    4:
    PHP Code:
    if(isset($_POST['allefunksjon'])) {
       
    $query3 "SELECT * FROM `forhandlere` WHERE fylke='$_POST[fylke]' AND (merke) LIKE '%$_POST[merke]%'";  

    $result3 mysql_query("$query3") or die('<p class="error">There was an unexpected error grabbing from the database.3</p>'); 
    Now the problem is that if both chekboxes is checked the results turns up both 1.st and 3. query.

    Any ideas?

    Thansk a lot!

  4. #4
    439
    posts
    Registered User
    Not quite sure what you mean, can't you just create an if/else conditional? i.e:

    PHP Code:
    if(isset($foo) && isset($bar))
    {
     echo 
    'foobar!';
    }else if(empty(
    $foo) && empty($bar)){
    echo 
    'no foobar for you :(';

    while ( ! ( succeed = try() ) );

  5. #5
    58
    posts
    Registered User
    Ok I almost got it to work but still a little problem. I can't get it to display when both check boxes is displayed.
    Thanks a lot.

    Here's the code.
    PHP Code:
    else if(isset($_POST['allefunksjon']) and isset($_POST['allemerke'])) {
      
      
    $query2 "SELECT * FROM `forhandlere` WHERE fylke='$_POST[fylke]';";  

    $result2 mysql_query("$query2") or die('<p class="error">There was an unexpected error grabbing from the database.2</p>'); 

    while (
    $row mysql_fetch_array($result2)) {  

        
    $elogo = ($row['logo']);
        
    $ename = ($row['navn']);
        
    $fylke = ($row['fylke']);
        
    $eemail = ($row['merke']);
        
    $efunksjon = ($row['funksjon']);
        
    $eepost = ($row['text']);
        
    $eweb = ($row['web']);   
          
        echo(
    '<p>dette vises dersom INGEN velg alle på merket er haket av.</p>');
        echo (
    '<div style="align:left; width:400px;">');
        echo(
    '<p><img src="'.$elogo.'" /><br />
        <b>'
    .$ename.'</b><br />
        '
    .$fylke.'<br />
        '
    .$eemail.'<br />
        '
    .$efunksjon.'<br />
        '
    .$eepost.'<br />
        <a href="http://'
    .$eweb.'" rel="nofollow" target="_blank">'.$eweb.'</a></p>');
        echo 
    "</div>";
     

    }


  6. #6
    58
    posts
    Registered User
    Any ideas anyone?

  7. #7
    58
    posts
    Registered User
    ups. that was suposed to be more text to the lets try again

    I've tried working with the code but i cant get it to seperate those to. And again, I'm kind of a newbie with this.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012