Current location: Hot Scripts Forums » Programming Languages » PHP » From form to php...


From form to php...

Reply
  #1 (permalink)  
Old 04-16-04, 05:34 AM
MasQ's Avatar
MasQ MasQ is offline
Newbie Coder
 
Join Date: Feb 2004
Location: Norway/Oslo
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts
From form to php...

Hey people

In expanding my knowledge I am working on setting up a http server, but for now, its only local and not connected to the internet.
It is an Apache 2.0 installation with PHP v. 4.3.5 installed on it, and it seems to work fine. Exept:
As usual I have a form, that points to a .php page upon submitting, but for some reason the form-variables aren't working in the php page on my local server instalation.
I have tryed the exact same files on a webhotel I am renting, and it works fine there... So im guessing it hase something todo with config, but if it is the Apache config, or the php.ini file there is a problem with, im not sure...
If you need to see the print of the phpinfo() command, I have printed it to a pdf file that you can find on: http://www.nepelan.org/diverse/masq/phpinfo.pdf (its on the webhotel, not on the local server!)

Form:
Code:
<form name="smgform" method="post" action="smg.php">
  <p>Stocks and price:<br>
    <input name="stocks" id="stocks" type="text" size="8">
    <select name="action">
      <option value="add" selected>buy</option>
      <option value="sub">sell</option>
    </select>
    &euro; 
    <input type="text" name="price" id="price" size="8">
    <br>
    <br>
      <input type="submit" class="button" value="Submit">
and the smg.php file:
PHP Code:

<?php

if($stocks == ""){ echo "Du har ikke valgt hvor mange aksjer!"; exit(); }
if(
$price == ""){ echo "Du har ikke skrevet hvor mye du har kjøpt/solgt aksjer for!"; exit(); }
$oldtotal file_get_contents("total.txt");
$total="$stocks"$price";
if(
$action == "add"){ $newtotal="$oldtotal"$total;}
if(
$action == "sub"){ $newtotal="$oldtotal"$total;}

//test
echo "Stocks: $stocks <br>" ;
echo 
"Price: $price <br>" ;
echo 
"Old content of total.txt file: $oldtotal <br>" ;
echo 
"The total of the multiplication of stocks and price: $total <br>" ;
echo 
"The amount of € you have made/lost: $newtotal <br>" ;

?>
The part below //test is only temporary... I used it to se where things werent working, some other commands are going to replace them when this thing works...

Thanks for any help I might get
Reply With Quote
  #2 (permalink)  
Old 04-16-04, 05:45 AM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
it's about globals ,I think, just use $_POST['stock'] instead of $stocks !! replace this $_POST[] for all other fields and it should work ...

just don't depend on globals !
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Reply With Quote
  #3 (permalink)  
Old 04-16-04, 05:48 AM
perleo perleo is offline
Coding Addict
 
Join Date: Jul 2003
Location: Ireland
Posts: 269
Thanks: 0
Thanked 0 Times in 0 Posts
Iam not sure what your looking for, but to pull the form information with PHP you need to do this......

PHP Code:

// We get what the user put in the form and put them into variables

$stocks $_POST['stocks'];
$action $_POST['action'];
$price $_POST['price'];

//Now we check to see if they filled everything in
if(!$stocks)
{
 echo 
"Du har ikke valgt hvor mange aksjer!";
 exit(
0);
}
if(!
$price)
{
 echo 
"Du har ikke skrevet hvor mye du har kjøpt/solgt aksjer for!";
 exit(
0);
}

//Now do the math
$oldtotal file_get_contents("total.txt"); 
$total="$stocks"$price"
if(
$action == "add"){ $newtotal="$oldtotal"$total;} 
if(
$action == "sub"){ $newtotal="$oldtotal"$total;} 

//Now print out the form details
echo "Stocks: $stocks <br>" 
echo 
"Price: $price <br>" 
echo 
"Old content of total.txt file: $oldtotal <br>" 
echo 
"The total of the multiplication of stocks and price: $total <br>" 
echo 
"The amount of € you have made/lost: $newtotal <br>" 
Hope this will do it for you. The $_POST[''] get the input. You place the name of the input in ['NAMEHERE']
Reply With Quote
  #4 (permalink)  
Old 04-16-04, 06:17 AM
MasQ's Avatar
MasQ MasQ is offline
Newbie Coder
 
Join Date: Feb 2004
Location: Norway/Oslo
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks for the grate answear both of you!! It works perfectly now!
I found it to be easyer to just use the:
PHP Code:

$stocks $_POST['stocks']; 

$action $_POST['action']; 
$price $_POST['price']; 
at the top of the sctipt, this way I don't have to change the whole script!
Once again I owe the communety of this page my gratitude!
May you live long and prosper!

(Not really a StarTrek fan, but its a cool line )
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
php form to html file arnec PHP 1 01-21-04 10:14 AM
PHP Upload Form Help tsb PHP 19 12-15-03 07:09 PM
PHP script that uploads and emails the form. ./n00b3 PHP 5 11-24-03 03:16 PM
PHP Triad/Upload form eddyvlad PHP 6 10-06-03 11:17 PM
PHP help ! Submit the form kevin PHP 1 06-24-03 08:09 AM


All times are GMT -5. The time now is 10:26 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.