Jump to content

[SOLVED] Pass an id to another file - quick question


Aureole

Recommended Posts

Real quick question.

 

On my news page I have a link to the full story and then the short story below.

 

The link to the full story is news/viewfull.php?id=something

 

Now what I need to do is make it so if the id=5 in the url it will query the database and get the fullstory that has an id of 5.

 

Does that make sense?

 

Is it something like...

 

<?php
if (isset($_GET['id'])) {

$theid = $_GET['id'];

$query = "SELECT fullstory FROM news WHERE id=$theid";

// Etc....
?>

 

// Connect to db etc.

 

 

Link to comment
Share on other sites

I have this and it isn't working...

 

<?php

if (isset($_GET['id']))
    {
    $theid = $_GET['id'];

    DEFINE ('DB_USER', '********');
    DEFINE ('DB_PASSWORD', '********');
    DEFINE ('DB_HOST', 'localhost');
    DEFINE ('DB_NAME', '********');

    $connectme = @mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die ('Could not connect to MySQL: ' . mysql_error());
@mysql_select_db (DB_NAME) OR die('Could not select the database: ' . mysql_error() );

    $query = "SELECT full FROM news WHERE id='$theid'";
    $result = @mysql_query($query) or die(mysql_error());

    while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
        {
        echo "{row['full']}";
      }
  }
?>

Link to comment
Share on other sites

I'm new to PHP, take it easy on me... @ hides errors right? Well the first tutorial I read said it's always best to add @ ...so it's a habit I guess...anyway calm down lol, the code I make isn't reliable and I do expect errors, I'm new.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.