Jump to content

Shows <?php echo Array; ?> in database


justlukeyou

Recommended Posts

I have peice of code which is designed enter a question into a database and the username of the person who asks the question.

 

However, the code enters <?php echo Array; ?>  into the database and  not 'Tom'.

 

I am using the same code which inserts the category of the question in the database which works.  But the username comes up as <?php echo Array; ?>.  Does anyone know why it shows "array"?

 

 

if($loggedIn) {
    echo "Welcome, ".$user['username'].". <a href=\"logout.php\">Logout</a>.
<table width='300' border='0' align='center' cellpadding='0' cellspacing='1'>
<tr>
<td><form name='form1' method='post' action='phpviewquestion.php'>
<table width='100%' border='0' cellspacing='1' cellpadding='3'>
<tr>
<td colspan='3'><strong>Your Question</strong></td>
</tr>
<tr>
<td width='71'>Question</td>
<td width='6'>:</td>
<td width='600' height='50'><input name='question' type='text' id='question'></td>
<td width='71'>Notes</td>
<td width='6'>:</td>
<td width='600' height='50'><input name='notes' type='text' id='notes'></td>
</tr>
<tr>
<td colspan='3' align='center'><input type='image' name='image' value='Submit' src='http://www.domain.co.uk/images/submitbutton.PNG' name='image' width='100' height='53'></td>
<input name='category' type='hidden' value='Furniture' id='category' >
<input name='questionmaker' type='hidden' value='<?php echo $username; ?>' id='questionmaker' >
</tr>
</table>
</form>
</td>
</tr>
</table>

</div>
"
;
} else {
    echo "Please <a href=\"login.php\">Login</a>.";
}

?>

Link to comment
Share on other sites

It look's like it would input Array['username'] to me.

Did you try?

<input name='questionmaker' type='hidden' value='".$user['username']."' id='questionmaker' >

or

<input name='questionmaker' type='hidden' value='{$user['username']}' id='questionmaker' >

 

looks like it'd work, if your previous code from the first post hasn't changed, and just that line has.

Link to comment
Share on other sites

At the top of the script where you have this...

 

echo "Welcome, ".$user['username']

 

etc.. does that properly show 'Tom' on the webpage, or does it also show 'Array'?  If it shows 'Tom' then it's a simple matter of a typo in your script.

Link to comment
Share on other sites

Hi,

 

It does shows as 'Tom' but I cant see the typo.  If enter "123" then this enters into the database as "123" but it I try to use a string then just shows as "array".

 

if($loggedIn) {
    echo "Welcome, ".$user['username'].". <a href=\"logout.php\">Logout</a>.
<table width='300' border='0' align='center' cellpadding='0' cellspacing='1'>
<tr>
<td><form name='form1' method='post' action='phpviewquestion.php'>
<table width='100%' border='0' cellspacing='1' cellpadding='3'>
<tr>
<td colspan='3'><strong>Your Question</strong></td>
</tr>
<tr>
<td width='71'>Question</td>
<td width='6'>:</td>
<td width='600' height='50'><input name='question' type='text' id='question'></td>
<td width='71'>Notes</td>
<td width='6'>:</td>
<td width='600' height='50'><input name='notes' type='text' id='notes'></td>
</tr>
<tr>
<td colspan='3' align='center'><input type='image' name='image' value='Submit' src='http://www.ukhomefurniture.co.uk/images/submitbutton.PNG' name='image' width='100' height='53'></td>
<input name='category' type='hidden' value='Furniture' id='category' >
<input name='questionmaker' type='hidden' value='{$user['username']}' id='questionmaker' >

Link to comment
Share on other sites

Do I need to declare 'user' on the form?

 

This is the form

 

if($loggedIn) {
    echo "Welcome, ".$user['username'].". <a href=\"logout.php\">Logout</a>.
<table width='300' border='0' align='center' cellpadding='0' cellspacing='1'>
<tr>
<td><form name='form1' method='post' action='phpviewquestion.php'>
<table width='100%' border='0' cellspacing='1' cellpadding='3'>
<tr>
<td colspan='3'><strong>Your Question</strong></td>
</tr>
<tr>
<td width='71'>Question</td>
<td width='6'>:</td>
<td width='600' height='50'><input name='question' type='text' id='question'></td>
<td width='71'>Notes</td>
<td width='6'>:</td>
<td width='600' height='50'><input name='notes' type='text' id='notes'></td>
</tr>
<tr>
<td colspan='3' align='center'><input type='image' name='image' value='Submit' src='http://www.ukhomefurniture.co.uk/images/submitbutton.PNG' name='image' width='100' height='53'></td>
<input name='category' type='hidden' value='Furniture' id='category' >
<input name='questionmaker' type='hidden' value='{$user['username']}' id='questionmaker' >

 

it is declared here as questionmaker

 

// Get values from form 
$category = $_POST['category'];
$question=$_POST['question'];
$notes=$_POST['notes'];
$questionmaker=$_POST['questionmaker'];
$qid = $row['qid'];

// Insert data into mysql 
$sql="INSERT INTO $tbl_name(category, question, notes, questionmaker)VALUES('$category', '$question', '$notes', '$questionmaker')";
$result=mysql_query($sql);

$qid = mysql_insert_id();


 

 

 

 

Link to comment
Share on other sites

Ok lemme see if I got this right, you want in the form element to have it populated automaticly through some echo variable output? but when you submit it doesnt have anything there you get an error, or whatever correct? But if you manually type into the form element the value it works...

 

The value you are trying to output, only outputs "Array" am I correct so far?

 

The vaule thats putting out "Array" is actually echoing out what it is, which is an Array..

 

in that first line you showed in your first post

<?php echo Array; ?>

 

whats the actual $value there? I know it can't be "Array" in a literal sense of the word. So do this, since its an array item,

 

put:

echo "<pre>";
print_r($value);
echo "</pre>";

 

replacing the: $vaule with whatever your $VarName is thats echoing out the word "Array" then copy and paste that here.

Link to comment
Share on other sites

thats likely due to either incorrect variable choice in the print_r statement, or a clash in variable names somewhere through the rest of that particular files variables, or through multiple files that are included in to that file and there variables.

 

 

Link to comment
Share on other sites

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.