Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




Displaying Text Fields On User Input


How would I echo a particular amount of text fields depending on how many the user selects from a drop down menu that I have already created. For example say the user selects 4 or whatever other number from a drop down menu how would I echo 4 or whatever the amount of text fields for a user to input text into? An example would be an airline website were you select how many people are travelling and then it echo fields for those people to enter their names.




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Text Input Of Date And Timestamp Fields
I'm working on a PHP frontend for a PostgreSQL db and I'm looking for the
best way to create date or timestamp inputs. Let's take a date in the
format yyyy-mm-dd as an example. This is too error prone, I know my users
will do it wrong

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

Right now I'm thinking about something like this:

<input type="text" size="4" name="y_fieldname">-
<input type="text" size="2" name="m_fieldname">-
<input type="text" size="2" name="d_fieldname">

but this is IMO a very ugly solution, because after the SUBMIT I have to
glue all the parts together before inserting the values into the db.
Something like this:

<input type="text" format="yyyy-mm-dd" name="fieldname">

Give User A Choice Of Fields To Search With Full Text/Boolean?
I want to give the user the option of searching a combination of the fields $Topic, $Subtopic, $Theswords in Boolean/Full Text. The problem is if I make any of the fields empty prior to the query, I get a MySql syntax error message. The user has the option of selecting fields via checkboxes, but when the field is not selected the user will get the error message because the variable is empty in the query statemtnt.

Are there any code suggestions for avoiding the error message when a field is not selected by the user to be searched? Code:

Fill Fields When User Selects User From DB
I have a field with a selectbox which contains a list of client names and several other fields which display information from the DB.

I need to be able to make the fields change to the appropriate information when a user is selected from the select box. Can anybody please give me an example of a bit of code that will do this?

Duplicate Input In 2 Form Fields
Hope to check the input in two form fields:

input in "emailto" form field: a@a.com
input in "emailfrom" form field: a@a.com, b@b.com, c@c.com

I hope to remove the duplicated input "b@b.com" in "emailfrom" form output and then keep only the remaining part of the string. How can I do that? I have though a way in combining the two fields input as an array and then use "array_unique" to check the duplicate. And then, to separate the two fields input again.

Search 2 Fields In A Mysql Table Using Only 1 Input Box
I would like to search 2 fields in a table using only 1 input box in php, at the moment I have 2 input boxes one for the Town search and one for the County searh, I would like 1 input box that would search the 2 fields. Here is my PHP Code:

Combining Data From Two Fields, Displaying With Another Table
What I am trying to do is pull data from two tables and display it on one page. The code below doesn't display any errors, but all it prints is the results from the first query. Ideas? Thanks.

(I also need to somehow put a variable in for the warranty table data so it is tied to the product_status table data. You can see there is a WHERE in the first query of pid, but no WHERE in the second query. That is a seperate question, though. It would make this way too long, so I will post it separately). PHP Code:

PHP Displaying Info Input On HTML Form
I'm in an exercise where I've created an order form in HTML. The form displays properly and allows me to input certain test order info just fine. The relevant lines in the HTML form are: Code:

User Input...
I have a form with a field that expects user to input HTML tags. I know I have to use htmlspecialchars for that input but what if the user inputs PHP code? I've looked at the help file and I can only find strip_tags which removes both PHP and HTML tags.

If a user wants to crash/corrupt/hack into your site by entering PHP code, what kind of things can he type? Must he include PHP tags to work? If he must use PHP tags, I could just write a function to remove only the PHP tags and not the HTML tags.

User Input?
Is there a way to get user input from a php script that doesn't have to do
with html? I would like to ask the user(me) to input a directory(preferably
in a gui way such as a folder selection dialog) to do some work with. Is
this possible when running the script directly on my comp(not off a
server(remote or local))?

The script is a management thing that I'd like to create to help generate
some html code. Essentially I want it to scan a dir(but don't want to hard
code it) and have it generate a list of links for the files in that
dir(which are images). Maybe even asking for a description for each.

Even if it was a little shell program to change the directory(sorta like
dos) would be much better than having to enter in the directory name by
hand.

Php User Input
When running PHP as a binary, is there a way to ask for user input?

Validation Function For All User Fields?
Hi,

I'm wondering if anybody knows of a function or statement similar to perls read(STDIN, $input, $ENV{'CONTENT_LENGTH'}); to read in a forms content string so that I can manipulate each variable/value pair independently of their values.

The reason for this is that I have a complex application form which has many inputs and I would like to put these values through a validation filter without explicitly naming them individually.

My other option is to make an array of the variable names and use this in a for loop to go through each variable/value pair. This is fine but it would be handier to let PHP do that for me.

Verifying User Input
I want to be able to search through a string that gets filled into my form. Make sure there are no quotes, semicolons and that kind of thing, that will mess up my database query. PHP Code:

What To Strip From User Input:
I recently suffered massive bot attacks against my contact page.
Someone sent me over 350 e-mails from my form in less than a couple of
hours. As this form only sends e-mail to an address dedicated for
this purpose, this isn't more than an inconvenience. In re-writing it,
I decided to write better stripslash and strip_tags functions of my
own. I have the function stripping out left and right angle brackets,
and forward and back slashes. I replace these with blanks (I am the
only one that views these e-mails and I think I can figure out what
was meant). That should break most script and malicious html tags.

What else should I watch for and strip? I thought it might be wise to
replace "=" signs with blanks. Should I worry about words like
"query" or "fopen"?

Part of my solution to preventing bot attacks against my form is to
force manual input by varying the name="" values. I have eighteen
different possibilities for each field on the form. I choose which to
use randomly. I check each possibility when processing to see if it
is set and send posters to a 404 page if they post to the wrong or all
possible variables. I also include a random string of 5 digits as an
authorization code in a hidden field. I use mysql database to let the
processing page know what variables and authorization code to expect,
associated with the poster's ip. Use the wrong authorization code and
you go to the 404 page. If your ip doesn't show up on in the
database, you get a "404 page not found." I delete records from the
database after processing, including old, unused entries where someone
left without completely filling out the form. Does anyone see any
reason that won't work to thwart the bots?

User Input Validation
I am intending to make a form on a page, on pushing submit the forms gets posted  onto itself so that it checks for empty fields and prompts user to get all fields filled, BUT the filled value should stay, I did this easily on ASP, but could not figure out in PHP. Code:

User Input Filtering
I have a comments system. In this comment system, people can enter certain strings, and it will break my page layout. Such as repeated characters with no spaces. It will just blow the table way out of proportion and completely ruin my layout. How can I break their input up if such a thing happens? Also, how can you number an array of data that is being withdrawn from the database DESC? Such as..

Quote1. itemnumber1
2. itemnumber2
3. itemnumber3
4. itemnumber4

Checking User Input
I want to check to see if there's only letters and numbers in a field, how would I go about doing this?

Filtering User Input...
I want to take text that a user inputs and store it into a variable.  That's the easy part.
I have and array of 30 elements that I want to store the inputted text into.

So.. here's an example...
- I want a user to enter text.
- I'll store it into a variable like $inputText.
- I want to split the text from $inputText into 30 equal sections and store each section into an element in the variable.
- I don't care if the words get separated during the filter, as long as the whitespaces stay where they are.

Could anyone give me some tips to help me get started or point me towards a tutorial or something?

Security With User Input And Sessions
I have two sort of related questions, if anyone would be so kind as to answer:

1. When I do an form for input (into a database) that is used for subsequently displaying on a web page, is there a function written to parse out all dodgy stuff, like putting HTML tags that could break the page, or filter out SQL that could corrupt or invalidate the entry or is there a regular expression that someone has already done to cover all areas?

2. If I am displaying data from a database and using sessions and the like, should I be putting something like this in my code (I found it in the php manual):

header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // past
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
// always modified
header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header ("Pragma: no-cache"); // HTTP/1.0

Cleaning Up User Form Input In Php
Does anyone please know why when trying to clear up user input that has been entered into a form, php only clears up most of it and not all?

For example, using stripslashes to remove all slashes from a variable after a user has submitted quotation marks ("") into a form.

The quotation marks cause the variable being parsed to contain slashes.

e.g. a user enters """""" into a form , the variable returned to php becomes """""

So if I only wanted the quotation marks, I thought the stripslashes function would achieve this.
However, it only removes 3 of the 5 slashes leaving 2 unwanted slashes behind.

Calling A Function Through User Input.
So heres yet another question to a problem where I would have no idea
where to look for the answer for so I turn to you :)

Say my sites administrator wants to write a news update or blog or
whatever. Something like this

"Added a new gallery from my trip to Phuket, enjoy:
[GID=24]
If you liked it tell me."

I want the [GID=24] to get replaced by my galery loading function
(very nifty and handy) so it would turn into something like this

echo "Added a new gallery from my trip to Phuket, enjoy:
".galery($GID)."
If you liked it tell me.";

I chose this [GID=24] because it is similar to burning board code. I
would also like to include a command like [PID=45] witch would run my
picture function.

Cleaning User Input, Is This Safe Enough?
I've written a small function that cleans up all user input before entering it to the DB. I'm wondering, is this sufficient or am I missing someting?

function clean_text($text) {

$text = str_replace("<", "&lt;", $text);
$text = str_replace(">", "&gt;", $text);
$text = strip_tags($text);
$text = htmlspecialchars($text, ENT_NOQUOTES);
$text = mysql_real_escape_string($text);

return $text;
}

Custom Fields - When User Submits It Goes To Admin's Email Or PM
I would like to create another page on my phpBB that would have customizable fields that users could enter information into and then submit the page. The info would then be sent to the Admin's email or PM. Here's a screenshot to illustrate, this would be a registration for a car show:
<snip>

Any ideas how to add these custom fields and then submit to an email or PM?

Checking User Input With Eregi Function
The function below (ExpressionTest.php) is for checking user input. The function is supposed to permit only alphabetical characters, the apostrophe ('), and the dash (-) for the "FirstName" variable. For some reason the script below will permit the dash to be used but gives the message "Please enter a valid first name." message when the FirstName variable includes an apostrophe.

I have tried switching places for the dash and the apostrophe. But if I place the apostrophe first in the string and the dash second in the string I still get the same message. PHP Code:

How To Get User Input For A Variable Without Using Forms Or Tables
I have created forms and taken user input from the forms into php variables. When validating the fields, if i find my conditions not satisfied on the php variable, i ignore the database connectivity and display error message and having the user to go back to the page and correct the error.

Is there a way i can correct the error without going back to the page, and getting the particular user input without having to create another form or table for input into the php variable.

How Can Arrays Be Dynamic With User And Administrative Input.
Can someone please show me how by examples - how scalar and associatie arrays can be dynamic with the user and administrative imput.

How Do You Do TCL Exec Command On PHP Script That Uses User Input?
The TCL command I am using will do a command-line action on a PHP
script:

set cannotRunPHP [catch {
eval "exec php -q $root/scripts/info/php/info.php"
} errMsg]

I have to do it this way as both the TCL script and the PHP script run
as CLI. However, "info.php" requires user input to run; this causes
the TCL script calling the PHP script to hose up and die.

Is there a way I can do this so that the TCL script can call the PHP
script without any problems? Is there an alternate way of calling the
PHP script other than using exec were that to solve this issue?



Unable To Insert User Input Into Ms Sql Database.
i have tried to insert user input into ms sql database but still unable to do so. my code has no errors in it. its just that the user input cannot be submitted into the ms sql database. Code:

What To Use In PHP To Make User Input Safe For MySQL Query?
I believe that you want to escape certain characters in a query, like quotes, backslash, semi-colon, etc. Is there a function in PHP to do all this for you and make the string safe to use as a query string?

User Local Time Diplay In Input Field
I'm wondering how can I have the local time of a user into a input field, it might sound or be stupid but even after my search I couldn't find a code si9mple enough, without any bla bla which each not my need.

Dynamically Creating URLS Based On User Input !
I am looking to create pages on the fly or dynamically based on user input. For example if i have www.example.com and they visit this and enter 'bob' in a textfield and press submit they create www.example.com/bob.html . How would I go about this ? I am guessing I need to create a folder when submit is pressed in my website directory ?

Stripslashes() And Text Fields
I have got a file that acts as an news edit form for people to edit info pulled from a database.

There are a few fields but specifically a title and a content field, both of which pull existing content from the db and set this as the initial value of the fields in the form.

When i echo these to the page i run the stripslashes function on both fields.

When both entries in the database have inverted commas stored in the fields only the text area will display them. The text field shows nothing. I have checked the table and the data is there stored correctly, (ran addslashes on ther way in).

I can echo them straight to the page but not to the text field. Strange?

The code is:

<td><input size="50" maxlength="250" type="text" name="auntyTitle" value="<? echo stripslashes($rows->auntyTitle); ?>"></td>
</tr>
<tr>
<td><textarea name="auntyContent" cols="40" rows="10"><? echo stripslashes($rows->auntyContent); ?></textarea></td>

Cleaning User Input (Removing HTML/stripping Slashes Etc...)
How can I remove HTML and add slashes to a variable?

I know I can add slashes with addslashes($var); but I need to know how to remove all HTML at the same time. Also - Are there any other characters I should strip from the variable (it will be stored in a database and displayed on a web page).

Use Cookies To Save Info On What The User Enter Last Time In A Input?
I am having some trouble looking for a good tutorial on cookies and how to have them save what you last time entered in the form. So how can I do this so users don't have to renter everything the next time they try to post something on my site?

Problem With Dynamic Text Fields
My goal is this: A user logs into the site and is presented with a directory listing (this is done, check). He then clicks on the directory, each which has their own amount of text files within them, and a page loads up presenting either text areas or text fields depending on the type of text file (some only hold one number, others just hold text). The text will already be entered into the text field, so no re-typing will be necessary, and if editing needs to be done, it can be. There is currently a map made in Macromedia Flash which relies directly on these text files to output certain information. I want to be able to alter the text files, and in turn, alter the Macromedia Flash. I understand that all of this can be done easier with databasing, but that's not the goal.

A word on the directories and text files: There are the same number of directories as there are buildings on the map. Each building has 2 text files, some have 4 if there are two buildings too close together to tell them apart. The first text file is totalBuildingName.txt, and this holds the number of pictures there are of that building, just one number. The second file holds text, and is just BuildingName.txt, and it holds the description of the building. The main directory where ALL of the PHP files are stored is called final. it then goes up to directories, then up to the building name. So if you're in admissions, the directory is: ./directories/admissions/

As for the code: It all works fine. Of course it doesn't work completely fine, or I wouldn't be posting here. It does everything I want it to do, and possibly more, however, I can't seem to open the text files within the directory. No matter how hard I try. The permissions ARE set on the folders and files, so that shouldn't be an issue, and if placed in the same directory as the text file, fopen can be used to file the text file, and then implode it to print it out. This leads me to believe that $TheFile isn't looking in the right place, but to be honest, I can't figure out what is the correct direction. I'll be extremely thankful to anyone who can point me in the remotely correct direction. Thank you so much.

Problem With Quotations In Text Fields
I'm new to PHP & MySql and have run into a problem when retrieving field data from MySql and inputting it into a Text field for editing and updating in the database.

The inputted info has href/jscript popup window code in it. The problem is the quotation marks in the HREF interfere with the quotation marks in the Text Field.

ie <INPUT VALUE="<a href="#" onClick="etc..

The returned code in the Text Field gets cut off after href= because the Value parameter is closed by the " of the HREF.

Sorting Fields From A Text File
Is there a way to sort by field when reading text from a flat-file database? I'm looking at some non-database alternatives to store the data for my website, and was considering using text files.

For example, lets say I have a text file with four fields (first name, last name, zip code, and e-mail address), which are seperated by a pipeline "|". How would I sort by the last name field (either asc or desc)? I assume I would have to read the contents of the file into an array, and then use one of the array sort functions, but I'm not really sure.

Also, is there a way to limit the number of lines shown? I assume this would be pretty easy...maybe by getting the number of lines and then dividing by 10 (or whatever you want the number per page to be).

Options For Clearing Text Fields?
I am new to php and html. I'm modifying a journal article database application.

Text field input (title, authors, journal, etc.) and associated pdf file are uploaded.

Successful completion prints a sentence at the top but the text fields are not
cleared. Headers have already been sent so I can't use header (right?). I
want the text fields empty so the user can enter data for the next pdf to upload. Code:

Uploading Generated Text Fields
I have on a page 4 text fields shown for a user to enter an amount in. If they have more than 4 amounts to enter in i have a button which, when clicked adds another text field although the max amount of text fields avaliable is 15. I need my php script to take the values entered by the user and send them into my MS Access database and order them into one field within the table with each value separated my commas.

I have included  this post my php so far, and the javascript code which generates the text fields which are unique in name. Code:

When To Clean Input Text
I was wondering what people do with text provided by the user in a
form. Some cleaning needs to be done at some stage if you are going to
be putting it in a database or displaying it etc. But when is the time
to do that?

Do you clean it as soon as you get it?
Do you pass around the original text and clean it when you use it?

What about magic slashes? You need to addslashes before using in a db
statement, but you need to strip them when displaying. When do you do
that?

Text Area Input Box With PHP
I have a text area box on one page. PHP sets the information that is inputted into the text area into a variable. When I print this info to the screen via echo, it does't have the line retain the formatting that the user had in the text area. It has no line breaks, it runs everything together.

Input Text Issues
Whenever I receive input from an HTML text field or and HTML text area
with " or ' meaning double or singe quotes into a php variable and
then print or echo it back out to the user in html I get these
characters accompanies by a . Why is this and how can I get rid of it.

$submitform->body=@$_POST['body']; <<<< there are no in the input.

print("body - ".$submitform->body."<br>"); <<<< but here there will
be slashes for all ' or " .

Text Input With Links, Etc..
I hope you can give me a few pointers on this issue.

I'd like visitors to my website to be able to enter text to be viewed on the
site - a bit like a bulletin board or forum. I can do this for regular text
easily by simply populating a 'TEXT' field within my MySQL database and
grabbing it back when rendering the site using PHP. However, I'd also like
visitors to be able to put in URL links or email items that can be clicked.
How would I go about doing this?.I've seen this sort of thing on forums
where words can be selected and a URL applied, but I have no idea how to do
this and how this information (ie. the link and the associated text) would
be stored in the database field(s).
Any ideas?. Are there any PHP examples available for this sort of thing?.

Input SQL Data Through Text Box And Get Nothing?
I want to add SQL command through a textbox in the form using post
method,but when i execute the following file, nothing is added to the
database.
I can add
$sqlol = "update acc_account
set user_name='k'
where accountid=1";
to the database if it was added to the file but when i use $result =
mysql_query($sql); which execute the query, it get nothing. However,
the $sql statement do print out on the screen using print.

<?php
$conn=mysql_connect('localhost', 'shytr8');

if(!$conn)
{print "Error- Could not connect to MYSQL";
exit;}

$er=mysql_select_db("test");

if(!$er){
print "Error- Could not create er";
$query = "CREATE DATABASE test";
mysql_query($query);}

$sql=$_POST[SQLcommand];
$result = mysql_query($sql);
?>

Checking Input Text?
I wondered if this script seemed correct? The user should enter a
userid and password in two text fields, and then pass these values to
the method login_user.

Could I ask, is there any approach to, once the user clicks the submit
button to test the userid and password has been entered, and the text
fields are not empty.

<?php

function login_form(){
?>
<html>
<head>
<title></title>
</head>

<body>

<div align="center">
<form method="post">
<table border="1">
<tr>
<th align="right">E-mail</th>
<td nowrap>
<input name="userid" size="25">
</td>
</tr>
<tr>
<th align="right">Password</th>
<td nowrap>
<input name="password" size="25">
</td>
</tr>
<tr>
<td align="center">
<input type="submit" name="submit" value="Login">
</td>
</tr>
</table>
</form>
<div>
</body>
</html>
<?php
}

login_form();
$user_info = login_user($_POST['userid'], $_POST['password'];
?>

Php/sql Question - How To Build A Dynamic Query Statement Based On User Input
I need to build a query based on what the user checks in the form. For
example, if the user does not check certain fields, I don' tneed to use
those in the query statement.

Backslash Appears In Text Fields With Apostrophes
In <input type="text"> and <textarea> fields, when I enter a string that contains an apostophe, and then re-display the page (e.g. after an insert or update), the text changes to add a backslash in front of the apostrophe.

If I leave the screen, and load the record fresh, the single backslash is not there. So I know it is not being saved in the database.

For example say I type "This isn't my dog" into a field and press save on my screen. When the form is re-displayed, the string has changed to "This isn't my dog". If I save again, I get "This isn't my dog", and once more I get "This isn\'t my dog. It appears that the apostrophe and then each backslash is being "escaped" each time.

I assume this is PHP's way of "escaping" special characters, but they end up getting stored in my database if I save a screen twice or more in succession. I this supposed to happen? Is there a way to eliminate this "escaping" behaviour in PHP?

$_POST Identical Text Fields Into Database
I have a list which is pulled and displayed from my MS Access database. Next to each row, is a text field which appears evertime a new row is displayed and that is called 'code'.

I want any text field filled in by the user to be sent into my database, into one field all separated by commas. I have made an attempt at this in the second example script but it needs tweaking.

I have here my script which pulls the list from my database: Code:

Spaces In <input Text> Boxes.
When I submit a form where a user has typed a space into the input box, then check that value in the action .php file, only the text before the first space is displayed. How can I get all of the text sent?

eg

Code:
<form name="form2" method="post" action="temp.php">
<input type="text" name="name">
<input type="submit" name="Submit" value="Submit">
</form>

Then in temp.php
Code:
echo "Username = $name";

If the user enters "Greg Bennet" into the text field, I get back "Username = Greg".

Double Quotes In Text Input
I accept text, add_slashes, and store it in my MySQL DB. When I display
the text, I normally strip_slashes and also strip_tags. This all works
excepts for a field with double quotes. e.g.

"My Book's Title" is very simple

When I display this field, it is totally blank. What's the solution?


Copyright © 2005-08 www.BigResource.com, All rights reserved