url query problem in php

Discussion in 'PHP' started by OPETH, Dec 9, 2007.

  1. #1
    connect.php
    HTML:

    <?php
    
    
    {
    $con = mysql_connect("localhost","root","");
    
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
    
    mysql_select_db("derslerioku", $con);
    
    
    $result = mysql_query("SELECT * FROM dersler where id='".$_GET['id']."'");
    
    
    echo $result['id'];
    
    mysql_close($con);
    }
    ?>
    Code (markup):

    The codes located in above, I add to index.php.
    Menu of my website:
    Lesson1
    Lesson2
    Lesson3
    .
    .
    .
    And I have given a link that like:<a href="index.php?id=1">Lesson1</a>

    But it doesnt work. Please help me!
     
    OPETH, Dec 9, 2007 IP
  2. UnknownFury

    UnknownFury Peon

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Try adding this after the $result bit..

    
    while($r=mysql_fetch_array($result)){
    
    echo $r['id'];
    
    }
    Code (markup):
    Also check that in your database its called 'id' and not 'ID'.
     
    UnknownFury, Dec 9, 2007 IP
  3. selling vcc

    selling vcc Peon

    Messages:
    361
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #3
    what error do you get ?

    FYI :
    
    mysql_connect("localhost","root");
    // is same as
    mysql_connect("localhost","root","");
    
    PHP:
     
    selling vcc, Dec 9, 2007 IP
  4. decepti0n

    decepti0n Peon

    Messages:
    519
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    0
    #4
    mysql_connect(); is the same as mysql_connect('localhost', 'root', ''); I think

    Also, its because $result is a resource, not an array. Use mysql_fetch_assoc or something similar to get it into an array first
     
    decepti0n, Dec 9, 2007 IP
  5. OPETH

    OPETH Peon

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5

    <?php
    
    
    {
    $con = mysql_connect("localhost","root","");
    
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
    
    mysql_select_db("derslerioku", $con);
    
    
    $sorgu= mysql_query("SELECT * FROM dersler");
    
    
    $id = $_GET['id'];
    $alan1 = mysql_result($sorgu,$id,"dersicerik");
    echo "$alan1";
    
    
    mysql_close($con);
    }
    ?>
    Code (markup):
    I solved the problem. Thanks for help!
     
    OPETH, Dec 9, 2007 IP