3raser Posted November 8, 2009 Share Posted November 8, 2009 Alright, when someone clicks [REPORT] on the index.php, they go to report.php?=id - But how do I get the ID from the URL? Like I click [REPORT] on post id 55 and I go to report.php?=55, how does the page know that it's ID 55? Here's my code: <?php require("global_navigation.php"); ?> <?php $name = $_SESSION['username']; $id = $_POST['id']; { if ($_SESSION['username']) { if (!$id) die("You cannot visit this page from your browser address! You must report a post first!"); $ip = $_SERVER['REMOTE_ADDR']; //protection $before = array('^', '<', '>', '`', '*', '<script>', '</script>', ';DROP TABLE users;', 'users', 'DROP', 'TABLE'); $after = array('', '', '', '', '', '', '', '', '', '', ''); $output = str_replace($before, $after, $message); $connect = mysql_connect("$dbhost","$dbuser","$dbpassword") or die("Connection failed!"); mysql_select_db("$db") or die("Database fail!"); //connect $connect = mysql_connect("$dbhost","$dbuser","$dbpassword") or die("Connection failed!"); mysql_select_db("$db") or die("Database fail!"); //write $write = mysql_query("INSERT INTO reports VALUES ('','$id','$name')") or die(mysql_error()); echo "<div class='box'><font face='arial'><b><span style='color:green'>Successfully reported post ID ".$id."!"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/180729-solved-quick-question-need-help-with-id/ Share on other sites More sharing options...
mikesta707 Posted November 8, 2009 Share Posted November 8, 2009 the url should look like report.php?id=5 (5 being an example id) and then on report.php you can access it by $id = $_GET['id']; variables posted through the URL are in the GET array Quote Link to comment https://forums.phpfreaks.com/topic/180729-solved-quick-question-need-help-with-id/#findComment-953497 Share on other sites More sharing options...
3raser Posted November 8, 2009 Author Share Posted November 8, 2009 Oh, lol, I can't believe I didn't see that. -.- Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/180729-solved-quick-question-need-help-with-id/#findComment-953498 Share on other sites More sharing options...
3raser Posted November 8, 2009 Author Share Posted November 8, 2009 Now when I click it, it still says the error message when id = !$id. <?php require("global_navigation.php"); ?> <?php $name = $_SESSION['username']; $id = $_GET['id']; { if ($_SESSION['username']) { if (!$id) die("You cannot visit this page from your browser address! You must report a post first!"); $ip = $_SERVER['REMOTE_ADDR']; //protection $before = array('^', '<', '>', '`', '*', '<script>', '</script>', ';DROP TABLE users;', 'users', 'DROP', 'TABLE'); $after = array('', '', '', '', '', '', '', '', '', '', ''); $output = str_replace($before, $after, $message); $connect = mysql_connect("$dbhost","$dbuser","$dbpassword") or die("Connection failed!"); mysql_select_db("$db") or die("Database fail!"); //connect $connect = mysql_connect("$dbhost","$dbuser","$dbpassword") or die("Connection failed!"); mysql_select_db("$db") or die("Database fail!"); //write $write = mysql_query("INSERT INTO reports VALUES ('','$id','$name')") or die(mysql_error()); echo "<div class='box'><font face='arial'><b><span style='color:green'>Successfully reported post ID ".$id."!"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/180729-solved-quick-question-need-help-with-id/#findComment-953499 Share on other sites More sharing options...
mikesta707 Posted November 8, 2009 Share Posted November 8, 2009 write print_r($_GET) at the top of your page. Are you sure you are passing the value correctly in your link? The URL should look like report.php?id=5 Quote Link to comment https://forums.phpfreaks.com/topic/180729-solved-quick-question-need-help-with-id/#findComment-953500 Share on other sites More sharing options...
3raser Posted November 8, 2009 Author Share Posted November 8, 2009 Thank you. I accidentally had it at report.php?=$id Topic solved. Quote Link to comment https://forums.phpfreaks.com/topic/180729-solved-quick-question-need-help-with-id/#findComment-953508 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.