Kaboom Posted November 10, 2009 Share Posted November 10, 2009 OKay so I coded my own blog source because i -thought that would be cool but I have a slight problem in development ... see you can login, goto your profile, register, view stuff and whatever and it all works peachy BUT the posting a new article is messed up. The user can post an article and all is fine, no errors, everything seems to run smoothly but when you check the post in the DB, you can see the whole post EXCEPT the author. Now the form they are using to login saves there session as that user id, like if my username was kaboom and im user #5, it logs me in as user #5. Now I need the post.php (what it uses to save the post from newpost.php) to save either the authors username OR their id so I can load that from a group later when displaying posts.. Here is my code, see if you understand whats going wrong: <?php $path = $_SERVER['DOCUMENT_ROOT']; $path .= "/core/config.php"; include_once($path); $path = $_SERVER['DOCUMENT_ROOT']; $path .= "/core/func.php"; include_once($path); $path = $_SERVER['DOCUMENT_ROOT']; $path .= "/core/english.php"; include_once($path); function name($name) { global $db_id; $query="select count(*) from users where name='".$name."'"; $result=mysql_query($query, $db_id); $row=mysql_fetch_row($result); return (bool)$row[0]; } $usr=user($_GET[".$name."]); $subject=clean($_POST["subject"]); $name=clean($_SESSION["name"]); $inhoud=clean($_POST["inhoud"]); if (($_POST['post'])&&($_SESSION["code"]==$_POST["code"])) { $query="insert into `babys` (`poster`, `subject`, `content`, `date`) values('".$name."', '".$subject."', '".$inhoud."', now())"; $result = mysql_query($query); if ($result) header('Location: index.php'); else msg("Failed.".mysql_error()); } else { msg($lang['incorCode']); } ?> Why isn't it saving the userid or the username too? Please help <3 Link to comment https://forums.phpfreaks.com/topic/181001-posting-into-database-saving-name/ Share on other sites More sharing options...
Kaboom Posted November 10, 2009 Author Share Posted November 10, 2009 Okay i got userids now Edit: nevermind, it's just putting 0's in now Link to comment https://forums.phpfreaks.com/topic/181001-posting-into-database-saving-name/#findComment-954940 Share on other sites More sharing options...
mrMarcus Posted November 10, 2009 Share Posted November 10, 2009 well, i don't see anywhere where $_SESSION['name'] is being set. Link to comment https://forums.phpfreaks.com/topic/181001-posting-into-database-saving-name/#findComment-954946 Share on other sites More sharing options...
Kaboom Posted November 10, 2009 Author Share Posted November 10, 2009 well, i don't see anywhere where $_SESSION['name'] is being set. Okay I changed it so usr$=user(..whatever); now so that that calls the user thing right? Its $_GET["name"] which needs to call from function name i think ... ugh so confusing! It's only saving 0 in the username spot now! Link to comment https://forums.phpfreaks.com/topic/181001-posting-into-database-saving-name/#findComment-954952 Share on other sites More sharing options...
dgoosens Posted November 10, 2009 Share Posted November 10, 2009 if the name is in the $_SESSION then why are you using $_GET['name'] instead of $_SESSION['name'] ? Link to comment https://forums.phpfreaks.com/topic/181001-posting-into-database-saving-name/#findComment-954957 Share on other sites More sharing options...
Kaboom Posted November 10, 2009 Author Share Posted November 10, 2009 if the name is in the $_SESSION then why are you using $_GET['name'] instead of $_SESSION['name'] ? Well ... here is what I have now <?php $path = $_SERVER['DOCUMENT_ROOT']; $path .= "/core/config.php"; include_once($path); $path = $_SERVER['DOCUMENT_ROOT']; $path .= "/core/func.php"; include_once($path); $path = $_SERVER['DOCUMENT_ROOT']; $path .= "/core/english.php"; include_once($path); function name($name) { global $db_id; $query="select count(*) from users where name='".$name."'"; $result=mysql_query($query, $db_id); $row=mysql_fetch_row($result); return (bool)$row[0]; } $usr=user($_GET["name"]); $subject=clean($_POST["subject"]); // $name=clean($_SESSION["name"]); $inhoud=clean($_POST["inhoud"]); if (($_POST['post'])&&($_SESSION["code"]==$_POST["code"])) { $query="insert into `babys` (`poster`, `subject`, `content`, `date`) values('".$usr."', '".$subject."', '".$inhoud."', now())"; $result = mysql_query($query); if ($result) header('Location: index.php'); else msg("Failed.".mysql_error()); } else { msg($lang['incorCode']); } ?> I commented that one out now. It's only saving "0" into the username no matter what acc I use to post with Link to comment https://forums.phpfreaks.com/topic/181001-posting-into-database-saving-name/#findComment-955005 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.