473,802 Members | 1,960 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

12 New Member
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=@mysq l_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
11 11806
MMcCarthy
14,534 Recognized Expert Moderator MVP
This question is being moved to the PHP forum.

ADMIN
May 11 '07 #2
Motoma
3,237 Recognized Expert Specialist
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=@mysq l_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=@mysq l_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
captainmerton
12 New Member
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
captainmerton
12 New Member
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
5,821 Recognized Expert Expert
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
captainmerton
12 New Member
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
5,821 Recognized Expert Expert
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
captainmerton
12 New Member
It works. Many Thanks pbmods.
May 12 '07 #9
pbmods
5,821 Recognized Expert Expert
It works. Many Thanks pbmods.
You are many welcome. But be careful; they spend really quickly!
May 12 '07 #10

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

Similar topics

5
4626
by: Phillip T. Murphy | last post by:
Well, after half pulling my hair out messing with this, I am thinking it is not possible. I did research and found references to "sub-queries" not possible in MySQL (I am using 4.0.18-32 with PHP 4). But, not sure if I am breaking that rule or not. Psuedo code of what I am trying to do... <?php $sql = "select * from table1";
7
5076
by: garbagecatcher | last post by:
Hello, here's my problem: On my web server I generate a file, I need to send this file to a different web server. I have no control over the other web server. The only way they accept files is through input type="file"
6
2065
by: Walter | last post by:
Hi, The user has to type his name into input a input field (type = text). This name must be passed to another ASP file. I did this but nothing happened: <form id=ins method="post" onsubmit="return doit()"> Type your name:<input id=txt1 type="text"> <INPUT id=smt TYPE="submit"> </form>
12
2172
by: Jim Tome | last post by:
Hi, I am trying to change and pass the value of a hidden input type on a form tag to a cgi processing script based on the value of a checkbox within the form: function CheckBoxes () { if (document.MyForm.CheckBox1.checked) { document.MyForm.recipient.value = "2"; document.MyForm.submit();
0
19295
by: IamtheEvster | last post by:
Hi All, I am currently using PHP 5 and MySQL 5, both on Fedora Core 5. I am unable to call a MySQL stored procedure that returns output parameters using mysql, mysqli, or PDO. I'm having a hell of a time with it... The following comes from phpinfo(): PHP Version: 5.1.2 mysql Client API version: 5.0.18 mysqli Client API version: 5.0.18
1
7734
by: zwieback89 | last post by:
Hi, I have a org tree with hierarchical display of employees built using classic asp and vbscript. I also have list of radio buttons for report names. I have 1 select box with dates in it. Then I click on the submit button to view the reports in Crystal. But
3
1699
by: brock797 | last post by:
hey im just starting to learn php and mysql, i am using CentOS 5 and have all the neccisary programs compiled correctly (apache, php, mysql, etc) i can use mysql from the command line with no flaws, however when i try to connect to mysql from php i get nothing, no errors no text at all just a blank page...i have a mysql_connect.php file and the php file i have created to access and change database variables, theres supposed to be an input box...
2
1923
by: adamace5o | last post by:
hi, i am trying to use a hidden form as a method of storing varibles for use throughout an online quiz site. I am using mysql to hold data about the users ie user id username and user password etc. The information is input into a visible form and then when the user clicks the submit button, a validatelogin.php script is run which takes the data from the input and checks it against the mysql database. I want to know if there is a way of...
7
4452
by: Jack Gray | last post by:
I have a form requiring data input for all fields. When any field is left blank and the data is submitted, the cgi file generates a new form which is populated with data already input and an error message to fill in the missing data. An anomaly occurs with the reprinted form. One field often requires input of more than one word from the original form. However, the reprinted form populates the text field with only the first word of the string....
0
9699
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9562
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10309
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10068
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9119
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6840
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5496
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5625
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2968
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.