whiskedaway Posted September 24, 2008 Share Posted September 24, 2008 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! Quote Link to comment https://forums.phpfreaks.com/topic/125599-solved-probably-a-really-dumb-mistake/ Share on other sites More sharing options...
Adam Posted September 24, 2008 Share Posted September 24, 2008 $row = mysqli_fetch_assoc($result); .. returns an array. you need to use: $row['realname'] in: VALUES ('$row['realname']', Adam Quote Link to comment https://forums.phpfreaks.com/topic/125599-solved-probably-a-really-dumb-mistake/#findComment-649364 Share on other sites More sharing options...
whiskedaway Posted September 24, 2008 Author Share Posted September 24, 2008 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')"; Quote Link to comment https://forums.phpfreaks.com/topic/125599-solved-probably-a-really-dumb-mistake/#findComment-649370 Share on other sites More sharing options...
peranha Posted September 24, 2008 Share Posted September 24, 2008 Try this $sql = "INSERT INTO news (username, date, title, post) VALUES ('{$row['realname']}', '$date', '$addtitle', '$addblog')"; Added the {} to the value Quote Link to comment https://forums.phpfreaks.com/topic/125599-solved-probably-a-really-dumb-mistake/#findComment-649371 Share on other sites More sharing options...
Adam Posted September 24, 2008 Share Posted September 24, 2008 OR if that doesn't work: VALUES ('" .$row['realname']. "', Quote Link to comment https://forums.phpfreaks.com/topic/125599-solved-probably-a-really-dumb-mistake/#findComment-649374 Share on other sites More sharing options...
whiskedaway Posted September 24, 2008 Author Share Posted September 24, 2008 Wonderful, peranha's suggestion worked a treat. Thanks guys! Quote Link to comment https://forums.phpfreaks.com/topic/125599-solved-probably-a-really-dumb-mistake/#findComment-649376 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.