By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,708 Members | 2,080 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,708 IT Pros & Developers. It's quick & easy.

PHP: using input=hidden type data from form to get MySQL data

P: 12
I am new to PHP but have been using it for about a week. I'm having no trouble using html forms to recall data from a MySQL table when the input type=text but i cant seem to find a way of recalling the data from the MySQL table when the input type=hidden.

Here's the form code:

[PHP]
<?php $action = $_REQUEST['action'];
$epic = $_REQUEST['epic']; ?>

<TR>
<TD>

<?php echo $action; ?>

<INPUT TYPE="HIDDEN" NAME="action" VALUE="

<?php
echo $action; ?>

"></TD>
<TD>

<?php
echo $epic; ?>

<INPUT TYPE="HIDDEN" NAME="epic" VALUE="

<?php
print $epic; ?>

" SIZE="4"></TD>
<TD><INPUT TYPE="TEXT" NAME="volume" SIZE="5"></TD>
<TD> </TD>
<TD> </TD>
</TR>
</TABLE>
<P><INPUT TYPE="SUBMIT" VALUE="Get Quote"</P>
</FORM>
[/PHP]

And the DB call:

<?php $getquote=@mysql_query("SELECT EPIC,SharePrice FROM SharePrices WHERE EPIC = '$epic'");

The variable $epic is passed through first time in the URL from another page and is then displayed in the form as text but stored as hidden data as i dont want the user the ability to change it. The data comes back fine if I remove the where clause from the select or plug in a value eg. EPIC=ABC or set $epic=ABC before the query. The problem however is the data contained in $epic after it is passed through. i have used echo to display it and it looks ok. i have used various string function to remove spaces etc but all to no avail. The field EPIC is defined as CHAR(4) on the MySQL table and is the primary key.

Anybody got any help?

Cheers.
May 11 '07 #1
Share this Question
Share on Google+
11 Replies


MMcCarthy
Expert Mod 10K+
P: 14,534
This question is being moved to the PHP forum.

ADMIN
May 11 '07 #2

Motoma
Expert 2.5K+
P: 3,235
My typical approach to situations like this is to set my MySQL query to a variable before I perform the query. That way I can see what, exactly my query is, and this allows me to copy and paste EXACTLY what is being sent via PHP.

Try this:

[PHP]
<?php
$qry = "SELECT EPIC,SharePrice FROM SharePrices WHERE EPIC = '$epic'";
echo $qry;
$getquote=@mysql_query($qry);
[/PHP]

The other thing that I should mention is that all error messages returned from your mysql_query() call are being suppressed, so you will not know if there is an error in your query. Remove the @ sign if you feel there may be an issue with the MySQL syntax.

I am new to PHP but have been using it for about a week. I'm having no trouble using html forms to recall data from a MySQL table when the input type=text but i cant seem to find a way of recalling the data from the MySQL table when the input type=hidden.

Here's the form code:

<?php $action = $_REQUEST['action'];
$epic = $_REQUEST['epic']; ?>

<TR>
<TD>

<?php echo $action; ?>

<INPUT TYPE="HIDDEN" NAME="action" VALUE="

<?php
echo $action; ?>

"></TD>
<TD>

<?php
echo $epic; ?>

<INPUT TYPE="HIDDEN" NAME="epic" VALUE="

<?php
print $epic; ?>

" SIZE="4"></TD>
<TD><INPUT TYPE="TEXT" NAME="volume" SIZE="5"></TD>
<TD> </TD>
<TD> </TD>
</TR>
</TABLE>
<P><INPUT TYPE="SUBMIT" VALUE="Get Quote"</P>
</FORM>

And the DB call:

<?php $getquote=@mysql_query("SELECT EPIC,SharePrice FROM SharePrices WHERE EPIC = '$epic'");

The variable $epic is passed through first time in the URL from another page and is then displayed in the form as text but stored as hidden data as i dont want the user the ability to change it. The data comes back fine if I remove the where clause from the select or plug in a value eg. EPIC=ABC or set $epic=ABC before the query. The problem however is the data contained in $epic after it is passed through. i have used echo to display it and it looks ok. i have used various string function to remove spaces etc but all to no avail. The field EPIC is defined as CHAR(4) on the MySQL table and is the primary key.

Anybody got any help?

Cheers.
May 11 '07 #3

P: 12
Thanks for for the help. Took your advice and assigned my query to a variable first and also removed the @. Now i'm printing out th query I see that if assign a value to $epic before the query:

$epic=ABC;

I always get my data back and the query shows as:

SELECT EPIC,SharePrice FROM SharePrices WHERE EPIC = 'ABC'

However if i remove $epic=ABC; the query looks like:

SELECT EPIC,SharePrice FROM SharePrices WHERE EPIC = ' ABC '

with a space before and after the ABC. i tried TRIM($epic) but this made no difference. Any ideas?
May 11 '07 #4

P: 12
echo substr($epic,4,3);

This shows the data as ABC. I havent added spaces in front of this as far as I am aware anywhere. TRIM doesnt seem to remove the spaces.
May 11 '07 #5

pbmods
Expert 5K+
P: 5,821
Check the source that it outputs. It looks like you should have a whole bunch of [undesired] newline characters in there.
May 11 '07 #6

P: 12
There seems to be 4 blanks spaces in front of the variable $epic when its recalled from a url using REQUEST. However it has &amp to split up the variables. Is it just coinidence that this is 4 long. How can i strip out the blank spaces?
May 12 '07 #7

pbmods
Expert 5K+
P: 5,821
There seems to be 4 blanks spaces in front of the variable $epic when its recalled from a url using REQUEST. However it has &amp to split up the variables. Is it just coinidence that this is 4 long. How can i strip out the blank spaces?
[HTML]
<INPUT TYPE="HIDDEN" NAME="action" VALUE="



<?php

echo $action; ?>



"></TD>
[/HTML]
Should be:

[HTML]
<INPUT TYPE="HIDDEN" NAME="action" VALUE="<?php echo $action; ?>"></TD>
[/HTML]

etc.

Tabs and newlines in an input's value field count, just like they do in between <textarea> tags.
May 12 '07 #8

P: 12
It works. Many Thanks pbmods.
May 12 '07 #9

pbmods
Expert 5K+
P: 5,821
It works. Many Thanks pbmods.
You are many welcome. But be careful; they spend really quickly!
May 12 '07 #10

Motoma
Expert 2.5K+
P: 3,235
pbmods for the win!

It works. Many Thanks pbmods.
May 13 '07 #11

P: 1
how can i send input hidden data one page to another page and then send to database? can somebody help me?
Mar 31 '17 #12

Post your reply

Sign in to post your reply or Sign up for a free account.