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
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
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):