Jump to content

Recommended Posts

I just can't work it out. Basically, what I'm trying to do is access the members database and grab the realname information. My user logged in with a username on the previous PHP page, and it's saved in session. However, instead of the database saving the realname, it keeps saving "Array" instead.

 

Here's my code:

<?php

    session_start();

    if (@$_SESSION['auth'] != "yes") {

        header("Location: index.php");
        exit();
    }

    include("logs.inc");

    switch (@$_POST['do']) {

    case "add":

        $cxn = mysqli_connect($host, $user, $password, $dbname) 
               or die ("Connection failed.");

        $sql = "SELECT realname FROM members
                WHERE username = '{$_SESSION['logname']}'";
        $result = mysqli_query($cxn, $sql)
                  or die ("Couldn't execute query 2.");
        $row = mysqli_fetch_assoc($result);
        extract ($row);

        $addtitle = $_POST['addtitle'];
        $addblog = $_POST['addblog'];
        $date = date("Y-m-d");

        $sql = "INSERT INTO news (username, date, title, post)
                VALUES ('$row', '$date', '$addtitle', '$addblog')";
        $result = mysqli_query($cxn, $sql)
                  or die ("Couldn't execute query.");

        header("Location: successadd.php");

    break;

    default:

    include("addnews.inc");

}
?>

 

Any help would be really appreciated!

Link to comment
https://forums.phpfreaks.com/topic/125599-solved-probably-a-really-dumb-mistake/
Share on other sites

Thanks for your quick reply. However, I've just changed it like you said, and I'm now getting this error message:

 

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/.reet/whiskedaway/blog/add.php on line 32

 

Line 31 and 32 are the lines that look like this:

        $sql = "INSERT INTO news (username, date, title, post)
                VALUES ('$row['realname']', '$date', '$addtitle', '$addblog')";

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.