Creating Empty Variables For Input Data
I am creating a script that will be taking data from a POST and submitting
the data to variables which are placed within a hash for string to data
association. Then, using HTML::Table and Mail::Sendmail, the data is parsed
into an html table and then an email is created and send to a recipient.
So, my question is this; How do I take the input from a post form and have
the variables pick up the data and process it into a hash?
my $name = ;
my $instock = ;
my describe = ;
# Hash to hold inventory data
my %table_data = (
model ='$modelnumber',
item ='$name',
available ='$instock',
description ='$describe',
);
This is all the code I have written thus far, any pointers or suggestions
for this project?
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Creating Hyperlinks From Data Input To Be Display In Table
Ive used search functions and have found relevent thread but the coding does not match. I have a php page the displays records from a form. id name, address, phone, website etc I would like to make the website data to turn into a hyperlink once submitted. Here is my following php code that displays the table Code:
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 ?
PHP Variables Are Always Empty
I'm trying to write a PHP script which allows to enter an username and a password and to click two buttons. If I start my PHP scripts 'mytest.php' I see the two input fields and the two buttons. However if I enter something to the input fields and press a button the echo commands show nothing. ====== PHP script 'mytest.php' ----------------------- <?php session_start(); if (!isset($_SESSION['auth_ok'])) { $_SESSION['auth_ok'] = false; } echo "$user <br>"; echo "$pass <br>"; echo "$button1 <br>"; echo "$button2 <br>"; echo "$auth_ok <br>"; if (isset($button1)){ echo "Button 1 has been pressed<br>"; $auth_ok = true;
Empty Variables In 4.2.1+
I have a site where I check to see if a variable isset to see which file I include on a page - the URL would be something like: http://www.domain.com/?s Then in the PHP file I check to see: PHP Code:
Testing For Empty Variables
I am retreiving the results from a randomized multiple choice quiz sent from a another php page using: foreach($_POST AS $field=>$value){ How do I check to see which questions were not checked?
Empty Variables And 4.21 (POST/GET)
With global variables set to on, I always had the following in my script to make sure variables had a default value: if (empty($var)) { $var = 1;} Now with 4.21, I changed it to: if (empty($_GET['var'])) { $var = 1;} The problem is sometimes I use GET and sometimes I use POST. With global variables on it didn't matter. Now it does. Is there a way to do this? When I try if (empty($_GET['var']) || empty($_POST['var'])), it doesn't work because one or the other will always be empty at any one time.
Empty Variables In Forms
I have some functions that check to see if certain form variables are empty. If they are empty then the function returns a 0. All of that is working just fine. BUT, I cant get the script to see the 0. PHP Code:
Checking For Empty Variables
Can I use empty() to check to see if variables actually have data? Basically I want the script or something to check to see if there is data in the variables. If there is no data, give the user some instructions on writing some data (link to a form or admin panel). If there is data, then continue with writing to the database.
If(empty) Statements/session Variables
1. I have a 2 page form. When the user fills out the info on page form he is directed to the 2nd page of the form. A session variable has been created in the 2nd form to hold all the data from the 1st page. When the 2nd page is submitted all the data (stored from page 1 and new from page 2) are sent to the database. 2. Here is the problem. On page 1, I have several form fields (like combo boxes) that need to work together. For example: I have a text field (name=phylum) in which investigators add new phylum names which are eventually sent to database field "phylum" of the same name. Next to that is a select box (name=newphylum) that has all the names that the investigors have previously entered and that are dynamically retrieved from the database field "phylum". So when a researcher fills out page 1 of the form he/she can either add a new name or select an already existing name from the select box. But just one of these values can be sent to the database, not both. QUESTION 1: How can I say and where would I put something that basically says the following: if the phylum text field is left EMPTY (i.e. they don´t add a new name) and they select instead from the select box, that it is the value from the select box and not the text box that gets sent to the database. QUESTION 2: How do I pass the statement from question 1 into the session variable on page 2 of my form?
Firefox Causing Empty PHP Form Variables??
This is really weird, and I would never believe it possible if it weren't actually happening to me. I've a customer database in mySQL, using PHP to create the forms, yadda yadda. All of a sudden, every time I edit a customer, when I submit the form using Firefox 1.0.2 on Linux (Fedora Core 3) it sends empty form fields to the database. BUT, if I use Firefox on Windows, or Opera on Fedora Core 3, it works perfectly fine. Any ideas what in the world could cause this? Firefox on Linux worked fine to up until...the last few days I think. The only think I can think of, is I may have installed a couple of extensions during that time.
Inserting Empty Data Into Mysql
I am creating an interface for my wife to keep track of what cross stitch threads she has. I have created a text area so she can enter a bunch at a time. I am trying to get the script to skip over blank lines. Code:
Separating Variables From One Input
Information is entered randomly in just one text box (name, social security number, lenght,weight). The problem is how to recognize that what actually was the name, and what was lenght etc. So how can i separate the inputs in their own variables?
Storing Input Values As Variables?
I wondered if anyone could advise? I am trying to write a basic script, which allows user's to enter there username, password in text fields. Then we take these values and pass them to the method login_user($userid, $password); I was unsure how to take the text fields values, and store them in variables, when the submit button is clicked? Is this code correct? <?php function login_form(){ global $PHP_SELF, $userid, $password; ?> <html> <head> <title></title> </head> <body> <div align="center"> <form method="post" enctype="multipart/form-data" action="<?php echo $PHP_SELF ?>"> <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($userid, $password); ?>
Input Data Truncated
I have a form with <input type="text" size="whatever"> and when I enter data with a space in it the information after the space is not displayed. If, from a form the data is inserted into the MySql db, the data is complete (spaces and all), but when pulling the info out and trying to display it again, the info after the space is not there. However, if I "View Source" on the displayed form that has the <input value=<?echo $row["city"]?>> in it, it comes out as <input value=San Diego> but the Diego does not display in the browser.
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); ?>
Creating Variables
Is it possible to have a variable that changes its name?? What I mean is if I have a Loop that goes nine times, is it possible for a variable to change its name on every loop. What I would like would be; PHP Code:
Validating Form Input Data
I am tying to come up with an elegant way to process some input data that come from a form. When the user hits the 'Submit' button, i want the form to appear again with the already entered valid data filled in and prompt the user to re-enter the non-valid data. If all data is valid, i will forward to an other .php page which enters the data into a database. I tried to do this in the following way: the form always hits back on itself, but when all data is valid i use the PHP:header() to redirect to the data.php that performs the database insertion. The problem is that the data is not available to data.php in the $_POST variable. How can i overcome this problem? Any other subtle way to handle the whole thing?
Creating New Variables Out Of A Variable
ok this is what I got..for example I got a variable with the followin as it content: 23,34,50,230,490,1090,2390 now I want each of those numbers to be extracted into their own variable so you'd get something like this: $var[1] (= 23) $var[2] (=34) $var[3] (=50) etc.. I know this can be done as I saw the function somewhere before but dunno what its called..
Creating Global Variables
Is it possible to create a global variable from within a function? My function loads parameters from the command line, and assigns them to php variables. I want to be able to pass these back to the main php code to be used in other functions. The names of the parameters (i.e. 'mode') are unknown until the program is run, so cannot be declared globally at the start of the script. There's a snippet in one of my books showing a function returning by reference - is this what I'm looking for?
Creating Session Variables In 4.2.1
I am on a shared host environment, and the ISP has both track_vars and register_globals enabled. I was changing over my login script from using session_register() to simply $_SESSION, but I'm having problems assigning values to the $_SESSION array. I know that the session is started correctly (I can check my cookies in Mozilla to see the $PHPSESSID value set) but when I try to assign variables it doesn't work unless I use PHP Code:
Creating Dynamic Variables
I'm trying to pass 100 variables (named gain1, gain2...gain100) from a swf to a php file then write these variables to a text file. Sending the data works fine. I just need help creating the variables in the php file. Since all the files have partly the same name, I was hoping to create the variables dynamically. I was hoping to do something like this: $myFileName = "myfile.txt"; $myFileHandle = fopen($myFileName, 'a') or die("can't open file"); for (i=1; i<100; i++) { $gaintext + i= $_POST['gaintxt1' + i]; fwrite($myFileHandle, $gain + i);} However, this isn't working obviously.
Does Anyone Declare A Different Data Type On Every Input In A Form?
I'm trying to read up on the rfc's that govern form inputs. Much of what I'm reading is stuff I didn't know before and some of it is alarming. This one left with me questions: Is this (below) addressed to me as a web designer, or is this addressed to the makers of web browsers? Identifying the type of file being uploaded seems way outside of my scope as a PHP coder. Am I suppose to make clear the expected type of content when I design a form? Off hand, I can only think of two things that every go into an HTML form: strings and binary data. Should I actually label every INPUT with the expected type (does anyone do this?), or can I assume the makers of web browsers have already done that for me? My PHP form code is fairly concise, so I could add in mime/text rather easily, but is it necessary? Surely the browser knows that everything save binary files is a string? They wrote: 3.3 use of multipart/form-data The definition of multipart/form-data is included in section 7. A boundary is selected that does not occur in any of the data. (This selection is sometimes done probabilisticly.) Each field of the form is sent, in the order in which it occurs in the form, as a part of the multipart stream. Each part identifies the INPUT name within the original HTML form. Each part should be labelled with an appropriate content-type if the media type is known (e.g., inferred from the file extension or operating system typing information) or as application/octet-stream. They give the example below. Am I right to say that I don't need to think about any of this, that the web browser does all this automatically? The browser figures out that file2.gif is a gif image that needs to be sent with a the header Content-type: image/gif, yes? If the user also indicated an image file "file2.gif" for the answer to 'What files are you sending?', the client might client might send back the following data: Content-type: multipart/form-data, boundary=AaB03x --AaB03x content-disposition: form-data; name="field1" Joe Blow --AaB03x content-disposition: form-data; name="pics" Content-type: multipart/mixed, boundary=BbC04y --BbC04y Content-disposition: attachment; filename="file1.txt" Content-Type: text/plain ... contents of file1.txt ... --BbC04y Content-disposition: attachment; filename="file2.gif" Content-type: image/gif Content-Transfer-Encoding: binary ...contents of file2.gif... --BbC04y-- --AaB03x-- If I wanted to send multiple files as part of a form input, how would I use the multipart/mixed header, or the "content-transfer-encoding" header? Can anyone point me to an example, so I might have a better chance of understanding this? As with all multipart MIME types, each part has an optional "Content-Type", which defaults to text/plain. If the contents of a file are returned via filling out a form, then the file input is identified as the appropriate media type, if known, or "application/octet-stream". If multiple files are to be returned as the result of a single form entry, they should be represented as a "multipart/mixed" part embedded within the "multipart/form-data". Each part may be encoded and the "content-transfer-encoding" header supplied if the value of that part does not conform to the default encoding.
Check An Input String For Data Types
What's the best way to check to see if an input string is made of completely letters or completely numbers? I wrote this, but it doesn't seem to work. I'll follow it with an example. Code:
Return Data Breaking Input Field
My return data is: (I have nothing to do with how the og person choose to input this) <font color="#800080">CASE</font> and I am setting the value of a input text form field equal to that return $input = "<input type="text" name="queOpt". $i ."" value="". $this->_queArr[$i] ."" />"; im lost on how to fix this. addslashes doesnt make sense - maybe it is the double quote thing
Automatically Creating Class Variables
I am working on an online CV creation program. There are several tables, e.g. Personal details, educational details. Each of these tables contains many fields. I want to write a class that will automatically extract the variables from the tables and give each variable a name that corresponds to the name of the column which it was extracted from. e.g. if a value of 'Conor' was extracted from the column memberName then a new variable $memberName would have the value of 'Conor'. I use the extract of this purpose. The problem is that I have no way of referring to the variables obtained by the extract() function outside of the class. I don't want to have to declare each variable (There are about 5 tables and many variables for each table). Is there any way of automatically making the variables obtained by the extract() function class variables? BTW, this is my first time using OO in PHP! If you don't know what I am talking about I have included a snippet of what I have so far: Code:
Technique For Creating Variables Within A Loop
I'm reasonably proficient in PHP but have been asked how to do something which has got me stumped. Hence, my posting: I want to create a small number of variables, $pos1, $pos2 ... $pos5 within a loop and assign them values from an array, but creating the variable names with incrementing numbers, well I've no idea how the PHP syntax for it works. ========== START CODE ========== <?php $x=5; $myarray = array('a','b','c','d','e'); for($a=0;$a<$x;$a++){ $pos.$a = $myarray[$a]; //Create $pos0 here on first loop, // $pos1 next loop and so forth.. } //Test assigned variable echo $pos3; // $pos3 should equal 'd' exit; ?> ========== END CODE ==========
Creating Info File With Variables
I'm trying to create a file with XML in it which contains user login info. In my script, a line is inserted that will be one type of user information, for example, <loginname>$username</loginname>. When the script runs, it actually inserts the characters $username. How do I make it so it enters in what $username equals, which is $_POST['username'] ? $userinfobody = '<?xml version="1.0"?> <loginname>"$username"</loginname> <loginpass>"$password"</loginpass> <contactemail>"$email"</contactemail> <regdate>"$todaysdate"</regdate>'; I am also getting a syntax error now at 1.0.
Passing Variable Through Hidden Input Drops Data
I have a form that is filled out that is passed to a preview page so the user can validate the changes they're making. On the preview page, they review their changes and hit the "Submit" button to have the data changed in the database. The preview page submits the data to the page that does the work using hidden inputs like: PHP Code:
Double Input Of Form Data When Browser Is Refreshed
I have a form page. When submitted it posts to page2. On page 2, it inserts variable into the database. The queries the database and displays the information. But.... If the viewer refreshes their browser, it now submits the information into the database again. Not sure how to handle problem. I think that if a session variable passed to page 2 in an if else statemen, it will keep this from happening when refreshed since the session variable is not passed in the refresh.
Make Data Safe To Input To Mysql Database
I'm just wondering what kind of things I should do to make sure that inputs from a form are safe to put into a mysql table? I'm currently using ereg() on an input to make sure that only numbers are entered, but on other forms I've got thiongs such as names and other details. How do I make sure that they're not going to break my table?
#2: Creating 'output' With Form-collected Variables
Some dumb questions may follow... I am learning PHP for a simple specialized calculator/curve-fitter that collects input from a user then fits the data to their range of conditions in the form of a table (actually just two columns of output). I bought a copy of Dmitri Koterov's book with a title something like "Create your Web Page with PHP'. What I like about it is it explains the how and why significantly instead of just examples. I may eventually find an answer in there, but I'd like to supplement reading with questions... It APPEARS to me that my task will be even easier with PHP than previous efforts with JavaScript. It looks like I can simply ECHO the processed data embedded in tags, like a <LIlist or even a <TABLE. With JS I got lost trying to figure out other examples people referred me to with get inner html & item ID etc...got too abstract for me. It doesn't need to be fancy...thus far, I think the echo method may be adequate. So, at last, the question...I previously had trouble with JS figuring out how to make variables accessible to more than one script (make them 'global'?). I think PHP is more flexible with variables...whether or not it is a good practice, they apparently do not need to be explicitly defined by type (they are interpreted by content?), but are they automatically assumed to be global? What do I need to do to them to make them be 'global' or "remembered" for use by more than one script? What then would be their 'lifetime'...cleared when the script is exit-ed, or until refreshed by a new form Submit? (Maybe what I'm hinting at is whether or not there is the concept of a 'session' that gets reset somehow. Lastly, can Submits of form data for the purpose of recalculation be 'processed' by other means than pressing a Submit button, like a MouseOver or MouseOff kind of thing?
Passing Variables To An Image Creating Php File
I have been working with the gd functions in PHP to render an image. I was able to solve the (apparently) usual header problems and such like via searching through this page and help documentation, such that I am now able to produce an image by doing the following : Code:
White Space Creating In Session Variables
i use session variables to store values submitted by the form for later retrieval.. but once i try to retrieve the values they get truncated where ever the white space is encoutered... e.g. if i submit the value as "blood sample".. n store it in session variabl.. once i try to retrieve the value it shows "blood" only. anything after the white space is ingnored or truncated. Code:
Help In Creating Data Entry Forms With MySQL
I was wondering if any of you experts has some example of MySQL data entry form either using PHP or any public domain software for my photo album. I'd like to enter some description with it.
Ftp_nlist Returns False For Empty Directory Instead Of Empty Array
In an application installed with PHP5 it looks like ftp_nlist() returns false if the directory is empty, instead of an empty array as it should according to the manual. On the original server with PHP4 it works as expected. Is this a bug, or an undocumented change in PHP5, or a setting that could be changed somewhere?
How Does PHP5 Process POST Data In Creating $_POST Array?
I need to save a wav file that is HTTP POSTed to a php page. What does PHP5 do automatically to a POSTed variable when it puts it in the $_POST[] superglobal array? I haven't been able to find any info on this.... I have a script that does what I want in PERL, but I need to do it in PHP. I think the PERL does something magic when it does this: #### PERL CODE #### read ( STDIN, $buffer, $ENV { 'CONTENT_LENGTH' } ); @pairs = split ( /&/, $buffer ); foreach $pair ( @pairs ) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $FORM { $name } = $value; } #### END PERL CODE ####
Losing $_POST Data With Input Type="image"
I am having problems with a php script that I am developing. I have a file called "login.php". It contains an HTML form with a username and password field, and is submitted with an image. Here is a simplified version of my form: <form name="form1" action="<?php echo $_SERVER['PHP_SELF']?>" method="post"> <input type="text" size="20" maxlength="50" class="text" name="uname"> <input type="password" size="20" maxlength="12" class="text" name="passwd"> <input type="image" src="images/b-login.jpg" border="0" name="submit"> </form> As you can see, the script calls itself. However, when I try to access $_POST['uname'] and $_POST['password'], they do not exist. If I replace the line <input type="image" src="images/b-login.jpg" border="0" name="submit"> with <input type="submit" name="submit" value="Login"> everything works fine. I need to use this image to submit my form, not the standard "Submit" button. Any ideas on what the problem is?
$_POST Behavior From Input=submit Vs Input-type=button
I have been trying to solve an annoying behavior with PHP (I think). Maybe some of you have encountered the same and have some ideas. I have an html form and I use an <input type="button"> element with the onClick event that calls a javascript funtion. Once the script's content has been processed, I execute the form.submit() directive. I would like to combine the html form and the PHP script into one, and use action="<?php echo($PHP_SELF) ?>". When the html form has <input type="button" name="theButton" value="thisisthetrigger" onclick="doThis(this.form)">but PHP cannot 'read' the value of $_POST["theButton"] after form.submit(). If I substitute the <input type="button"> for <input type="submit"> then PHP reads the value just fine. Some may argue to just use the latter option, but that will cost me a trip back to the server to basically do a lot of validation that can be very easily accomplished on the client side.
Insert Data Into Variables,,,
How can i insert the data into variables from the tables,,, $query = "SELECT * FROM users WHERE name = '$username'"; $result = mysql_query($query, $connection) or die('error making query'); while ($row = mysql_fetch_array($result, MYSQL_BOTH)) { $organization = $row["organization"]; $contactperson = $row["contactperson"];}
Creating Dir, Copy Files And Pass Variables To 2 Files
I need to create a folder on the server weekly named by the user. To this folder copy the contents of an /Original folder. Inside the new folder edit one of the files to insert a data with a XML path generated in another application, copied (via memory) and pasted within the very first form and passed to the file in question. <param name="FlashVars" value="xmlfile= $lanofile" /> the $lanofile is the value that I need to pass from the form to be read by this file. I have created an form (n.php) that POST the name of the folder to a second file (creatdir.php) everything is cool until I have to edit the third file. How can I pass the value of one of the formfileds to a second file and them read this value as a variable to be consumed as mentioned above? Or actually right whatever is on the third field to this position (not using variables).
Save Data Not Variables In A File
I am try to save the "values" of variables from a file (template.php) to another file (tmp.txt). $value = "12345"; template.php <?php The answer is $value. //When viewing the file, I see 12345. ?> tmp.txt The answer is 12345. This is what I am trying to do. The answer is $value. This is the results of the following script. When I write the data to tmp.txt, the variable is copied, not the value of the variable. How do I write (save) the results of the template.php in tmp.txt? <?php $url_read = $_SESSION['folder_dir']."template.php"; $url_write = $_SESSION['folder_dir'].'tmp.txt' $f_r = file($url_read); $read_file = fopen($url_read, "r"); $f_w = file($url_write); $write_file = fopen($url_write, "wb"); foreach($f_r as $line) { fwrite($f_w,$line); } fclose($read_file); fclose($write_file);
Offline Function, Variables With No Data In Them
I've been trying to figure this out for a while, the function returns a result but its not the result l want. I've tried to debug the function and it seems that $groupid and $status aren't being set as when l echo'ed them out they both had no data in them. If l set the variables data inside the function the code executes perfectly, so l cant understand why it isnt working. What l need the code to do is check to see if the member logging in is an admin (group id or a root admin (group id 9) and if the game is offline (status 1) to only only admin and root admin. However is the game is offline but status is set to 2, then only root admin can login. If the game is offline, normal members are not allowed to login. Clearance is there so l can check to see whether or not to allow them pass or stop them from logging in. Code:
Getting Data From Database And Turning Into Variables?
how i can get something from a database and turn it into a variable. Not anything like a table or anything, something like a persons ID.. if there is a table for members and then there is a field called ID asweell as things like username, email ect... how do i get the ID and use it. I do not want a certain ID, i want the ID of a person logged in at that time, so say they left a message on a guestbook, i could display there ID next to them by simply putting a variable like $member_id.
Problem Reading Data Out Of MySQL Db, PHP Variables
Below is part of a code I have for a database. While the database table is created correctly (if it doesn't exist), and data is input correctly into the database when executed, I have a problem when reading out the data into the PHP variables / array. It should be displaying the information out in the following way, using the PHP array: n_date, n_headline, n_summarytext, n_fulltext But what actually gets displayed is the data for: n_date, n_headline, n_summarytext So the "n_fulltext" is not displayed, but the echo'ed text preceeding it "Full text:" is displayed, but it is not reading the information out of the variable. I have checked that there is information input in this field in the db, and it is there.....
Splitting Data Divided By Space Into Array Or Variables
I'm very new to PHP3 and just started learning three days ago. I have seen on a PHP3 tutorial that with a special command data divided by space could be splitted into an array or several variables (for picking out the words of a sentence). I just couldn't find it so far.
Random Variables + Storing Pokémon Data + Adding To Intergers
-How do you set a variable to a random number between two numbers? Such as, setting the variable $var to a random number between 1 and 5. -Yup. Pokémon. Sounds stupid, however, we have interests. So, like, how should I store Pokémon Data? (Pokémon are like creatures or monsters. The closest things possible to it are Monster Rancher, Digimon, and Demikids). It's more than likely going to be stored in a table... yet, I don't see how it could be really possible. -Okay, I have a field called "Money". How would I add or subtract numbers from that field?
|