localhost Posted July 12, 2006 Share Posted July 12, 2006 Ahh! I have been trying to figure this out but just can't get it, this file is called newthread.php. So when I go to newthread.php?fid=1 it needs to insert into the database, fid as $FID which is equal to $_REQUEST['fid'];Below is the code, it seems to be inserting it as 0 no matter what! Please if anyone can help It will be much appreciated![code=php:0]<?phpsession_start();include('inc/connect.php');/* ****** IF SUBMIT IS HIT AND REQUIRED FIELDS ARE NOT EMPTY ****** */if(isset($_POST['submit']) && !empty($_POST['title']) && !empty($_POST['post'])){$FID = $_REQUEST['fid'];$title = $_POST['title'];$post = $_POST['post'];$date = date('m-d-Y');$query = "INSERT INTO topics (`id`, `fid`, `title`, `post`, `poster`, `date`) VALUES ('', '$FID', '$title', '$post', 'Guest', '$date')";$result = mysql_query($query) or die(mysql_error());if($result){echo "<script>window.location=\"index.php\"</script>";} }?><form action="newthread.php" method="POST">Thread title:<br /><input type="text" name="title" /><br />Post:<Br /><textarea name="post" rows="20" cols="50"></textarea><br /><input type="submit" name="submit" value="Post" /></form>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/14424-inserting-as-0-when-not-supposed-to-be/ Share on other sites More sharing options...
ShogunWarrior Posted July 12, 2006 Share Posted July 12, 2006 But if you are posting the form, then where will the fid be coming from?PHP won't remember the FID that was in the URL when you accessed the page, try putting this into the form, under the <FORM> tag:[code]<input type="hidden" name="fid" value="<?=((isset($_REQUEST['fid']))?($_REQUEST['fid']):(''))?>" />[/code] Quote Link to comment https://forums.phpfreaks.com/topic/14424-inserting-as-0-when-not-supposed-to-be/#findComment-57009 Share on other sites More sharing options...
localhost Posted July 12, 2006 Author Share Posted July 12, 2006 $FID = $_REQUEST['fid']; checks the url for ?fid=x and that makes $FID x. no your method doesnt work. Quote Link to comment https://forums.phpfreaks.com/topic/14424-inserting-as-0-when-not-supposed-to-be/#findComment-57014 Share on other sites More sharing options...
play_ Posted July 12, 2006 Share Posted July 12, 2006 try replacing $_request['fid'] with $_GET['fid'] Quote Link to comment https://forums.phpfreaks.com/topic/14424-inserting-as-0-when-not-supposed-to-be/#findComment-57031 Share on other sites More sharing options...
localhost Posted July 13, 2006 Author Share Posted July 13, 2006 get and request do the same thing, it doesnt work with either :-./ Quote Link to comment https://forums.phpfreaks.com/topic/14424-inserting-as-0-when-not-supposed-to-be/#findComment-57042 Share on other sites More sharing options...
localhost Posted July 13, 2006 Author Share Posted July 13, 2006 anybody else? this is the first spot ive gotten stuck at.. Quote Link to comment https://forums.phpfreaks.com/topic/14424-inserting-as-0-when-not-supposed-to-be/#findComment-57055 Share on other sites More sharing options...
cmgmyr Posted July 13, 2006 Share Posted July 13, 2006 try global $fid; instead of your requestthat might get it Quote Link to comment https://forums.phpfreaks.com/topic/14424-inserting-as-0-when-not-supposed-to-be/#findComment-57056 Share on other sites More sharing options...
localhost Posted July 13, 2006 Author Share Posted July 13, 2006 like...if(isset($_POST['submit']) && !empty($_POST['title']) && !empty($_POST['post'])){$FID = global $fid; $title = $_POST['title'];$post = $_POST['post'];$date = date('m-d-Y');$query = "INSERT INTO topics (`id`, `fid`, `title`, `post`, `poster`, `date`) VALUES ('', '$FID', '$title', '$post', 'Guest', '$date')";$result = mysql_query($query) or die(mysql_error());i get this error with that:Parse error: parse error, unexpected T_GLOBAL in C:\wamp\www\newthread.php on line 9 Quote Link to comment https://forums.phpfreaks.com/topic/14424-inserting-as-0-when-not-supposed-to-be/#findComment-57059 Share on other sites More sharing options...
cmgmyr Posted July 13, 2006 Share Posted July 13, 2006 [code]if(isset($_POST['submit']) && !empty($_POST['title']) && !empty($_POST['post'])){global $fid; $title = $_POST['title'];$post = $_POST['post'];$date = date('m-d-Y');$query = "INSERT INTO topics (`id`, `fid`, `title`, `post`, `poster`, `date`) VALUES ('', '$FID', '$title', '$post', 'Guest', '$date')";$result = mysql_query($query) or die(mysql_error());[/code] Quote Link to comment https://forums.phpfreaks.com/topic/14424-inserting-as-0-when-not-supposed-to-be/#findComment-57061 Share on other sites More sharing options...
localhost Posted July 13, 2006 Author Share Posted July 13, 2006 still inserts fid as 0 when the link is newthread.php?id=1 Quote Link to comment https://forums.phpfreaks.com/topic/14424-inserting-as-0-when-not-supposed-to-be/#findComment-57066 Share on other sites More sharing options...
kenrbnsn Posted July 13, 2006 Share Posted July 13, 2006 Let's go back to your original code:[code]<?phpsession_start();include('inc/connect.php');/* ****** IF SUBMIT IS HIT AND REQUIRED FIELDS ARE NOT EMPTY ****** */if(isset($_POST['submit']) && !empty($_POST['title']) && !empty($_POST['post'])){$FID = $_REQUEST['fid'];$title = $_POST['title'];$post = $_POST['post'];$date = date('m-d-Y');$query = "INSERT INTO topics (`id`, `fid`, `title`, `post`, `poster`, `date`) VALUES ('', '$FID', '$title', '$post', 'Guest', '$date')";$result = mysql_query($query) or die(mysql_error());if($result){echo "<script>window.location=\"index.php\"</script>";} }?><form action="newthread.php" method="POST">Thread title:<br /><input type="text" name="title" /><br />Post:<Br /><textarea name="post" rows="20" cols="50"></textarea><br /><input type="submit" name="submit" value="Post" /></form>[/code]You are only doing the update when the form has been submitted. In the code for the form, nowhere do you pass the value of the fid back to the processing script. You keep on insisting that [code]<?php $FID = $_REQUEST['fid']; ?>[/code] will give it to you. It won't if you don't have it either on the URL or in the form. If you invoke this script with the link "newthread.php?id=1", your script will not set anything to that value, since you don't reference either $_GET['id'] or $_REQUEST['id']. ShofgunWarrior was on the rught track in reply #1.What you need to do is either[list][*]Put the id from the URL on the action URL of the form:[/list][code] <form action="newthread.php?fid=<?php echo $_GET['fid'] ?>" method="POST">[/code][*]Or make it into a hidden field in the form[code]<form action="newthread.php" method="POST"><input type="hidden" name="fid" value="<?php echo $_GET['id'] ?>">[/code][list][/list]Either method will pass the value from the link used to invoke the script back to the script to process the form.Ken Quote Link to comment https://forums.phpfreaks.com/topic/14424-inserting-as-0-when-not-supposed-to-be/#findComment-57089 Share on other sites More sharing options...
localhost Posted July 13, 2006 Author Share Posted July 13, 2006 THANK YOU VERY MUCH! I have been looking for this solution for a while, now it's working well. If there was a rep system then I would give you some. Quote Link to comment https://forums.phpfreaks.com/topic/14424-inserting-as-0-when-not-supposed-to-be/#findComment-57093 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.