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."!"; } } ?> 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 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! 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."!"; } } ?> 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 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. 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
Archived
This topic is now archived and is closed to further replies.