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
https://forums.phpfreaks.com/topic/231741-shows-in-database/
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
https://forums.phpfreaks.com/topic/231741-shows-in-database/#findComment-1192353
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
https://forums.phpfreaks.com/topic/231741-shows-in-database/#findComment-1192361
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
https://forums.phpfreaks.com/topic/231741-shows-in-database/#findComment-1192363
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
https://forums.phpfreaks.com/topic/231741-shows-in-database/#findComment-1192487
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
https://forums.phpfreaks.com/topic/231741-shows-in-database/#findComment-1192508
Share on other sites

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.