My problem...

Discussion in 'MySQL' started by chmpdog, Jun 22, 2008.

  1. #1
    I have racked my brain for days trying to find a solution, and I hadnt had any luck. So I decided to post here hopefully someone can help.

    I am trying to write a code that will grab a variable from the url, (a $_GET), then check in my MySQL database to see if it exits in a table row. ($row['name']) If it dosent match then it will go to a 404 page, but if it does I would need to get the id of the page ($row['id'])

    Thanks
     
    chmpdog, Jun 22, 2008 IP
  2. CreativeClans

    CreativeClans Peon

    Messages:
    128
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    How about a google search for "PHP Mysql tutorial"?
     
    CreativeClans, Jun 24, 2008 IP
  3. Social.Network

    Social.Network Member

    Messages:
    517
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    35
    #3
    1. Get the URL variable
    2. Select the row WHERE the column value = URL variable
    3. If NULL then redirect to 404 page, else GET row ID

    If you need code samples, please let me know.

    Good luck,
    SN
     
    Social.Network, Jun 24, 2008 IP
  4. Lisa Starks

    Lisa Starks Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I only know how to reply to peoples threads
    I cant post my own ! show me how:)
     
    Lisa Starks, Jun 24, 2008 IP
  5. advancedfuture

    advancedfuture Banned

    Messages:
    481
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    0
    #5
    it should look a little something like this:

    example url = www.examplesite.com/index.php?action=variable

    
    <?php
    
    include 'dbconnect.php'; //php database connection info
    
    $var = $_GET['action'];
    
    $query = "SELECT * FROM table WHERE row = '$var'";
    $results = mysql_query($query) or die ("ERROR WITH QUERY");
    
    if(mysql_num_rows($results) > 0)
    {
    	while($row = mysql_fetch_array($results))
    	{
    		$id = $row['id'];
    	}
    }
    else
    {
    	header( "Location: 404error.html" );
    }
    ?>
    
    Code (markup):
     
    advancedfuture, Jun 24, 2008 IP