Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5

Thread: Id receiver php

  1. #1
    New to the CF scene
    Join Date
    Apr 2012
    Posts
    8
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Id receiver php

    Hello, I have this code that takes the id and send it to the showFullArticle.php:

    Code:
    $rs_result = mysql_query ($sql,$mysql_connection);
    while ($row = mysql_fetch_assoc($rs_result)) {
    ?>
        <div><a href="showFullArticle.php?id=<?php echo $row["id"];?>" target="Article">
            <?php echo $row['title']; ?></a>
        </div>
        <div class="description"><?php echo $row["description"];?></div>
    <?php
    };
    ?>
    I put that code in the showFullArticle.php file:

    Code:
    <?php
    $id = $_GET["id"];
     echo $id;
    $mysql_connection = mysql_connect("host", "user", "password") or die ('Eror: ' .mysql_error());
    $database_myconnection = "database";
    $query = "select * from tablename where id = '".$id."'";
    if (mysql_query($query)) {
    echo " 
    
    '".$title."'
    
    ";
    }
    mysql_close($mysql_connection);
    ?>
    but something is wrong. mysql data are not displayed. Can you please help me? Thank you in advance!
    Last edited by grebud; 04-11-2012 at 09:06 AM.

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,266
    Thanks
    6
    Thanked 48 Times in 48 Posts
    You connect to the database there, but you're not selecting one.

    PHP Code:
    $mysql_connection mysql_connect("host""user""password") or die ('Eror: ' .mysql_error());
    $database_myconnection "database";
    mysql_select_db($database_myconnection,$mysql_connection) or die('Failed to select database: 'mysql_error()); 
    Also, echo out $query and see if that's getting filled with $id.
    Last edited by Nightfire; 04-11-2012 at 10:37 AM.

  • Users who have thanked Nightfire for this post:

    grebud (04-11-2012)

  • #3
    Regular Coder
    Join Date
    Apr 2004
    Posts
    298
    Thanks
    0
    Thanked 23 Times in 23 Posts
    Aside...

    1. you can simplify this

    PHP Code:
    $query "select * from tablename where id = '".$id."'"
    to this
    PHP Code:
    $query "select * from tablename where id = '$id'"

    2. Do you want to display the title and the article?

    PHP Code:
    $query "select * from tablename where id = '$id'";
    $result mysql_query($query);
    $row mysql_fetch_array($result);
    echo 
    $row['title'] . "<br>";
    echo 
    nl2br($row['article']); 

  • Users who have thanked litebearer for this post:

    grebud (04-11-2012)

  • #4
    New to the CF scene
    Join Date
    Apr 2012
    Posts
    8
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Great! It worked perfectly! Thank you very much Nightfire and litebearer!

  • #5
    New to the CF scene
    Join Date
    Apr 2012
    Posts
    8
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Great! It worked perfectly! Thank you very much Nightfire and litebearer!
    Last edited by grebud; 04-11-2012 at 11:42 PM.


  •  

    Posting Permissions

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