Jump to content

Posting into database (saving name)


Kaboom

Recommended Posts

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

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!

 

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 :(

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.