SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Member
    Join Date
    Sep 2011
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Index.php needs to show a record from database

    Hi,

    Hopefully this is the simpliest question ever. I have just produced my first php content managed site.
    Basically the index.php needs to show the record from the data base with the ID of 1. Obviously when the browser loads the site it only looks for index.php and would not include the record id on the end of it. Hence it would only load the empty default page I've created to disploay records in.
    Is there a way round this? There must be, surely!

    Any help would be fantastic.

  2. #2
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    72 Post(s)
    Tagged
    0 Thread(s)
    Priming a Variable.

    PHP Code:
    $id = (isset($_GET['id'])) ? $db->real_escape_string($_GET['id']) : 1
    Explanation: The line reads: "If $_GET['id'] is set (exists on the end of your URL), use the database object to escape the string (if you're using procedural, this will change into mysql(i)_real_escape_string() and set $id to that. If it isnt, set $id to 1."

    Ternary Operator
    isset
    mysqli_real_escape_string
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  3. #3
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    PHP Code:
    <?php
    // change POST to GET if you are using that method ie index.php?id=1
    if( ! isset($_POST['id']) ){
    $_POST['id'] = 1;
    }

    // carry on with script

  4. #4
    SitePoint Member
    Join Date
    Sep 2011
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    First of all many thanks for your very speedy replies.

    I have this on the in the <head> of the file, is it the right bit?

    $colname_pages = "-1";
    if (isset($_GET['cms_id'])) {
    $colname_pages = $_GET['cms_id'];

    and are you suggesting I change it to:

    $colname_pages = "-1";
    if (isset($_POST['cms_id'])) {
    $colname_pages = $_POST['cms_id']=1;

    The method i'm useing is index.php?cms_id=3

    Thanks again

  5. #5
    SitePoint Member
    Join Date
    Sep 2011
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Missed out an explanation mark

    $colname_pages = "-1";
    if ( ! isset($_POST['cms_id'])) {
    $colname_pages = $_POST['cms_id']=1;
    }

    This works great, thank you again very much.

  6. #6
    SitePoint Member
    Join Date
    Sep 2011
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Again,

    Sorry, my index.php now displays the right record when it opens, but unless I put the whole url in, the browser doesn't access index.php, maybe because it is looking for an index.html.

    For example

    www.mysite.co.uk - doesn't load anything but

    www.mysite.co.uk/index.php - does work.

    How do I get the browser to acknowledge the index.php?

    Have a good weekend.

  7. #7
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    That looks like an apache setting, you want the default to be index.php rather than index.html.

    They might both be set, if index.html contains nothing just delete it and try again.

  8. #8
    SitePoint Wizard silver trophybronze trophy Stormrider's Avatar
    Join Date
    Sep 2006
    Location
    Nottingham, UK
    Posts
    3,133
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    That is more to do with your server setup - Apache needs to be set up to look for index.php. Maybe there is an index.html or something that is being loaded in preference?


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
  •