pauldonnelly23 Posted March 27, 2008 Share Posted March 27, 2008 Hey Everyone, I'm having trouble with my $_GET function. I'm trying to get an ID from the address bar and and add it to a database different from the one that the ID has originally came from. I have create a foreign key in the new database, and when the form im using is posted all entries are posted to the database except the ID from the address bar. Hope you can help, Many Thanks Paul Here is the code: <?php require ("db_config.php"); $connection = @mysql_connect($db_host, $db_user, $db_password) or die("Error With Connecting To Database <br> Contact Admin - info@ninitelife.com"); mysql_select_db($db_name, $connection); $pubdir_id = $_GET["pubdir_id"]; $name = $_POST["txt_name"]; $len = strlen($name); if ($len > 0) { $email = $_POST["txt_email"]; $comment = $_POST["txt_comment"]; $date = time(); $query = "INSERT INTO reviews (review_id, pubdir_id, name, email, comment, date) VALUES (NULL, '$pubdir_id', '$name', '$email', '$comment', '$date')"; mysql_query($query, $connection) or die (mysql_error()); } ?> <html> <head> <title>Reviews</title> </head> <body> <form action="<?php echo $_SERVER[php_SELF]; ?>" method="POST"> <font face="arial" size="1"> Name:<br> <input type="text" name="txt_name"><br><br> Email:<br> <input type="text" name="txt_email"><br><br> Comment:<br> <textarea style="width: 30%" rows=5 name="txt_comment"></textarea> </font> <br><br><input type="submit" value="Submit Comment"> </form> <table bgcolor="#AAAAAA" border="0" width="40%" cellspacing="1" cellpadding="2"> <?php $query = "SELECT * FROM reviews WHERE 'pubdir_id'= 'pubdir_id' ORDER BY date DESC"; $result = mysql_query($query, $connection); for ($i = 0; $i < mysql_num_rows($result); $i++) { $pubdir_id = mysql_result($result, $i, "pubdir_id"); $name = mysql_result($result, $i, "name"); $email = mysql_result($result, $i, "email"); $email_len = strlen($email); $comment = mysql_result($result, $i, "comment"); $comment = nl2br($comment); $date = mysql_result($result, $i, "date"); $show_date = date("H:i:s d/m/Y", $date); if($i % 2) { $bg_color="#EEEEEE"; } else { $bg_color="#EOEOEO"; } echo ' <tr> <td width="100%" bgcolor="'.$bg_color.'"> <font face="arial" size="2">'; if($email_len > 0) { echo'<b>Name:</b> <a href="mailto:'.$email.'">'.$name.'</a>'; } else { echo'<b>Name:</b> '.$name; } echo ' <br> <b>Comment:</b><br> '.$comment.' </font> </td> <td width="1%" valign="top" nowrap bgcolor="'.$bg_color.'"> <font face="arial" size="2"> <b>Date: </b> '.$show_date.' </font> </td> </tr> '; } ?> </table> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/98200-_get-problem-please-help/ Share on other sites More sharing options...
BlueSkyIS Posted March 27, 2008 Share Posted March 27, 2008 nah, here is problem: $query = "SELECT * FROM reviews WHERE 'pubdir_id'= 'pubdir_id' ORDER BY date DESC"; should be $query = "SELECT * FROM reviews WHERE pubdir_id = '$pubdir_id' ORDER BY date DESC"; Quote Link to comment https://forums.phpfreaks.com/topic/98200-_get-problem-please-help/#findComment-502446 Share on other sites More sharing options...
soycharliente Posted March 27, 2008 Share Posted March 27, 2008 Also, DATE is a reserved work in MySQL. You should backtick all of your table and field names. You WILL have problems later trying to get info from that specific field if you don't start enclosing it. <?php $query = "INSERT INTO `reviews` (`review_id`, `pubdir_id`, `name`, `email`, `comment`, `date`) VALUES (NULL, '$pubdir_id', '$name', '$email', '$comment', '$date')"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/98200-_get-problem-please-help/#findComment-502453 Share on other sites More sharing options...
pauldonnelly23 Posted March 27, 2008 Author Share Posted March 27, 2008 Sorry folks, its still isnt adding the address bar ID to the data base. Would you have any other ideas? Do you think the $pubdir_id variable is empty before its Posted? Quote Link to comment https://forums.phpfreaks.com/topic/98200-_get-problem-please-help/#findComment-502468 Share on other sites More sharing options...
BlueSkyIS Posted March 27, 2008 Share Posted March 27, 2008 your using a $_GET, so it should be in the URL in your browser's address bar. Quote Link to comment https://forums.phpfreaks.com/topic/98200-_get-problem-please-help/#findComment-502470 Share on other sites More sharing options...
pauldonnelly23 Posted March 27, 2008 Author Share Posted March 27, 2008 Yeah I understand that, it is in address bar [http://localhost/MajorProject/Week8/review.php?pubdir_id=8] but It still isnt adding to the DB Quote Link to comment https://forums.phpfreaks.com/topic/98200-_get-problem-please-help/#findComment-502475 Share on other sites More sharing options...
conker87 Posted March 27, 2008 Share Posted March 27, 2008 Do a var_dump($_GET) when you submit this form and see if your variable is empty. Quote Link to comment https://forums.phpfreaks.com/topic/98200-_get-problem-please-help/#findComment-502476 Share on other sites More sharing options...
BlueSkyIS Posted March 27, 2008 Share Posted March 27, 2008 problem is you're requiring both GET and POST at the same time. ain't gonna happen. $pubdir_id = $_GET["pubdir_id"]; $name = $_POST["txt_name"]; $len = strlen($name); if ($len > 0) if ($len > 0), then $pubdir_id == '' Quote Link to comment https://forums.phpfreaks.com/topic/98200-_get-problem-please-help/#findComment-502478 Share on other sites More sharing options...
pauldonnelly23 Posted March 27, 2008 Author Share Posted March 27, 2008 problem is you're requiring both GET and POST at the same time. ain't gonna happen. $pubdir_id = $_GET["pubdir_id"]; $name = $_POST["txt_name"]; $len = strlen($name); if ($len > 0) if ($len > 0), then $pubdir_id == '' Ah I see, I didnt know that. Do you know how I would get around this? Quote Link to comment https://forums.phpfreaks.com/topic/98200-_get-problem-please-help/#findComment-502480 Share on other sites More sharing options...
BlueSkyIS Posted March 27, 2008 Share Posted March 27, 2008 you need to include both in a GET or POST, or use sessions to store the value of one so it is known before the other. Quote Link to comment https://forums.phpfreaks.com/topic/98200-_get-problem-please-help/#findComment-502481 Share on other sites More sharing options...
MadTechie Posted March 27, 2008 Share Posted March 27, 2008 you could change <form action="<?php echo $_SERVER[php_SELF]; ?>" method="POST"> to <form action="<?php echo "?pubdir_id=$pubdir_id"; ?>" method="POST"> Quote Link to comment https://forums.phpfreaks.com/topic/98200-_get-problem-please-help/#findComment-502483 Share on other sites More sharing options...
BlueSkyIS Posted March 27, 2008 Share Posted March 27, 2008 wow, that works!?!? very cool! Quote Link to comment https://forums.phpfreaks.com/topic/98200-_get-problem-please-help/#findComment-502489 Share on other sites More sharing options...
pauldonnelly23 Posted March 27, 2008 Author Share Posted March 27, 2008 FANTASTIC!! Thank You Everyone for there help!! Quote Link to comment https://forums.phpfreaks.com/topic/98200-_get-problem-please-help/#findComment-502490 Share on other sites More sharing options...
MadTechie Posted March 27, 2008 Share Posted March 27, 2008 wow, that works!?!? very cool! yep , had to use it a few times, it does save some coding Quote Link to comment https://forums.phpfreaks.com/topic/98200-_get-problem-please-help/#findComment-502493 Share on other sites More sharing options...
conker87 Posted March 27, 2008 Share Posted March 27, 2008 Wouldn't $_SERVER['REQUEST_URI'] do the same thing? Quote Link to comment https://forums.phpfreaks.com/topic/98200-_get-problem-please-help/#findComment-502496 Share on other sites More sharing options...
MadTechie Posted March 27, 2008 Share Posted March 27, 2008 Yes but i have a habbit of filtering input at the start and then rebuild it. Quote Link to comment https://forums.phpfreaks.com/topic/98200-_get-problem-please-help/#findComment-502500 Share on other sites More sharing options...
pauldonnelly23 Posted March 27, 2008 Author Share Posted March 27, 2008 Wouldn't $_SERVER['REQUEST_URI'] do the same thing? Yeah, This also works. Thanks conker87! Quote Link to comment https://forums.phpfreaks.com/topic/98200-_get-problem-please-help/#findComment-502518 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.