LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 06-20-2007, 12:38 PM   #1
tonedeaf1969
LQ Newbie
 
Registered: Sep 2005
Posts: 8

Rep: Reputation: 0
PHP: build query from form entry, then display results in the same form


Hi all:

I'd appreciate it if someone could help me out a bit with this one. I've built a basic asset tracking database in MySql. I've developed a couple of forms to enter new data, or query the database. The query page displays the results in a basic table.

What I would like to do is display the results in the same form I used to generate the query. Also, I've no idea how to handle multiple results. Clear as mud?

Down the road, it would be nice if I was able to update as well.

Any help would be greatly appreciated.

Thanks

Kevin
 
Old 06-20-2007, 06:20 PM   #2
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
You can display the result in the same form just be setting up the HTML attribute value.

For an edit box you might have something like:

<input type="text" name="userName">

<input type="text" name="userName" value="myName">

so given that, you can do that in PHP
Code:
if (isset($userName))
echo '<input type="text" name="userName" value=' . $userName . '>';
else
echo '<input type="text" name="userName" value=>';
However you should read up on security and learn how to properly sanitise the data.
 
Old 06-21-2007, 04:25 AM   #3
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,134

Rep: Reputation: 218Reputation: 218Reputation: 218
Hi

That example is not so safe - $userName can contain spaces, even Javascript code. What if I typed something nasty:
><script language="javascript">alert('Hello');</script><blink

better way:
PHP Code:
$userName HtmlEntities($_POST['userName']);
echo 
"<input type=text name=userName value=\"$userName\">"
 
Old 06-21-2007, 07:05 PM   #4
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
I totally agree that it's not safe...

The addition of the $_POST is important since that is where the variables are if the form has been posted back to the web server. One common technique would be to take the variables that you are expecting to receive and validate them, then if they are valid store them in another array, then only ever access from that array, $clean is a common name for such an array.
 
Old 06-22-2007, 07:55 AM   #5
tonedeaf1969
LQ Newbie
 
Registered: Sep 2005
Posts: 8

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by graemef
I totally agree that it's not safe...

The addition of the $_POST is important since that is where the variables are if the form has been posted back to the web server. One common technique would be to take the variables that you are expecting to receive and validate them, then if they are valid store them in another array, then only ever access from that array, $clean is a common name for such an array.
Thanks for the tips, I'll give them a shot today. I've been doing a lot of reading on SQL injection security issues.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
To call a new form from Current form in QT Desginer kiranbud Linux - Software 0 11-25-2005 11:56 PM
How do list the results from my search form? Alexander.s Programming 4 05-09-2005 11:01 AM
shell script works form command line but not form crontab saifee General 1 10-14-2004 10:27 AM
how do I copy a whoel folder form one directory to another form the command line? zwyrbla Linux - Newbie 8 08-24-2004 06:40 PM
I want Linux source code for FAT file system in user readable form not in binary form ramya272 Linux - Newbie 5 02-05-2004 07:54 PM


All times are GMT -5. The time now is 11:36 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration