logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Coding & Scripting Corner View previous topic :: View next topic
Reply to topic   Topic: PHP - Passing Variables
Author
Modern Merlin



Joined: 30 Oct 2007
Posts: 10
Location: Roseville

PostPosted: Tue 30 Oct '07 9:54    Post subject: PHP - Passing Variables Reply with quote

Ok so I admit Im new at this... PHP that is...
Trying to take an html form and write to a database.

When I hit the submit button it goes to the next page but it comes up completely blank... Crying or Very sad

Originally I had the form in a huge table, but after doing some reading decided to try it even without the table and I still cant pass the variables...

Here is my config.php

Code:
<?php
$server = "localhost";
$db_user = "taken_out_for_posting_purposes";
$db_pass = "taken_out_for_posting_purposes";
$database = "taken_out_for_posting_purposes";
$table = "Order_Form";
?>


Here is the Form (yes I know there are better ways of making it pretty LOL rather than the spaces. Im just testing right now...)

Code:
<form method="post" action="save_order.php">
    Date of Contact:&nbsp;
    <input name="date_contact" type="text" id="date_contact" maxlength="10">
    <br>
    Name:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <input name="name" type="text" id="name" maxlength="25">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    Phone:
    <input name="phone" type="text" id="phone" maxlength="10">
    <br>
    Company:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <input name="company" type="text" id="company" maxlength="30">
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Fax: 
    <input name="fax" type="text" id="fax" maxlength="10">
    <br>
    Address:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <textarea name="address" cols="20" rows="2" id="address"></textarea>
    <br>
    City
    <input name="city" type="text" id="city" maxlength="25">
    Website:
    <input name="website" type="text" id="website" maxlength="20">
    <br>
    State:
    <select name="state" size="1" id="state">
        <option value="Alabama">AL - Alabama</option>
        <option value="Alaska">AK - Alaska</option>
        <option value="Arizona">AZ - Arizona</option>
        <option value="Arkansas">AR - Arkansas</option>
        <option value="California">CA - California</option>
        <option value="Colorado">CO - Colorado</option>
        <option value="Connecticut">CT - Connecticut</option>
        <option value="Delaware">DE - Delaware</option>
        <option value="District of Columbia">DC - District of Columbia</option>
        <option value="Florida">FL - Florida</option>
        <option value="Georgia">GA - Georgia</option>
        <option value="Hawaii">HI - Hawaii</option>
        <option value="Idaho">ID - Idaho</option>
        <option value="Illinois">IL - Illinois</option>
        <option value="Indiana">IN - Indiana</option>
        <option value="Iowa">IA - Iowa</option>
        <option value="Kansas">KS - Kansas</option>
        <option value="Kentucky">KY - Kentucky</option>
        <option value="Louisiana">LA - Louisiana</option>
        <option value="Maine">ME - Maine</option>
        <option value="Maryland">MD - Maryland</option>
        <option value="Massachusetts">MA - Massachusetts</option>
        <option value="Michigan">MI - Michigan</option>
        <option value="Minnesota">MN - Minnesota</option>
        <option value="Mississippi">MS - Mississippi</option>
        <option value="Missouri">MO - Missouri</option>
        <option value="Montana">MT - Montana</option>
        <option value="Nebraska">NE - Nebraska</option>
        <option value="Nevada">NV - Nevada</option>
        <option value="New Hampshire">NH - New Hampshire</option>
        <option value="New Jersey">NJ - New Jersey</option>
        <option value="New Mexico">NM - New Mexico</option>
        <option value="New York">NY - New York</option>
        <option value="North Carolina">NC - North Carolina</option>
        <option value="North Dakota">ND - North Dakota</option>
        <option value="Ohio">OH - Ohio</option>
        <option value="Oklahoma">OK - Oklahoma</option>
        <option value="Oregon">OR - Oregon</option>
        <option value="Pennsylvania">PA - Pennsylvania</option>
        <option value="Rhode Island">RI - Rhode Island</option>
        <option value="South Carolina">SC - South Carolina</option>
        <option value="South Dakota">SD - South Dakota</option>
        <option value="Tennessee">TN - Tennessee</option>
        <option value="Texas">TX - Texas</option>
        <option value="Utah">UT - Utah</option>
        <option value="Vermont">VT - Vermont</option>
        <option value="Virginia">VA - Virginia</option>
        <option value="Washington">WA - Washington</option>
        <option value="West Virginia">WV - West Virginia</option>
        <option value="Wisconsin">WI - Wisconsin</option>
        <option value="Wyoming">WY - Wyoming</option>
    </select>
    Email:
    <input name="email" type="text" id="email" maxlength="20">
    <br>
    Zip:
    <input name="zip" type="text" id="zip" maxlength="5">
<input type="submit" name="Submit" value="Submit">
</form> 


Here is the insert page

Code:
<?php
$Name=$_POST['name'];
$Company=$_POST['company'];
$Address=$_POST['address'];
$City=$_POST['city'];
$State=$_POST['code'];
$Zip=$_POST['zip'];
$Phone=$_POST['phone'];
$Fax=$_POST['fax'];
$Website=$_POST['website'];
$Email=$_POST['email'];

include "config.php";

//Testing the form and seeing if its actually sending the variables
print $Zip;

//connect to the mysql server
$link = mysql_connect($server, $db_user, $db_pass)
or die(("Could not connect to mysql because " mysql_error());

//select the database
mysql_select_db($database)
or die ("Could not select database because " mysql_error());

//Insert into the database
$insert = mysql_query ("INSERT INTO $table (Name, Company, Address, City, State, Zip, Phone, Fax, Website, Email)  VALUES ('$Name',''$Company','$Address','$City','$State','$Zip','$Phone','$Fax','$Website','$Email')", $link)
or die("Could not insert data because " mysql_error());
mysql_close();
echo 'Thank you $Name, for your time.  Please make sure to print out this page for your records.';
?>


I have been doing a lot of reading and at this point my brain is fried LOL. Im just trying to learn how to do this... Thanks for any help anyone can be Very Happy

Modern Merlin
Back to top
Modern Merlin



Joined: 30 Oct 2007
Posts: 10
Location: Roseville

PostPosted: Tue 30 Oct '07 13:42    Post subject: Reply with quote

Ok now after taking a look at the error log in SSH Im a little further.

Now my issue is that when I dont choose a checkbox that is assigned a variable for example:

I added a check box which I assigned the name producer
When I go to the next page it is then assigned:
$Producer=$_POST['producer'];
But if I dont check the box it wont write to the DB.

The field producer is set to not_null but has a default value of 0
If I dont check it does that mean it has to be assigned the value of 0?
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7371
Location: Germany, Next to Hamburg

PostPosted: Tue 30 Oct '07 17:07    Post subject: Reply with quote

you should turn on the error reporting. It makes programing easier

Code:

error_reporting(E_ALL);
Back to top
Modern Merlin



Joined: 30 Oct 2007
Posts: 10
Location: Roseville

PostPosted: Tue 30 Oct '07 17:18    Post subject: Reply with quote

So I just put that in the top where all my other variables are defined?

Thanks so much for your help. I havent touched any coding like this in almost 4+ years. So yeah I might as well say Im a n00b LOL

Modern Merlin
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7371
Location: Germany, Next to Hamburg

PostPosted: Tue 30 Oct '07 18:16    Post subject: Reply with quote

Put that at the very top of your page.
Or turn it on in php.ini if you can.
Back to top
Modern Merlin



Joined: 30 Oct 2007
Posts: 10
Location: Roseville

PostPosted: Tue 30 Oct '07 20:41    Post subject: Reply with quote

Tried to put it at the top of the page and the page comes up blank. Now the error I am getting is:

PHP Parse error: parse error, unexpected T_ENDIF in rest_of_the_path/forms/save_order.php on line 307, referer: rest_of_the_path/forms/orderform2.php

Here is the code from that file:

Code:
//if no name entered and no email entered print an error
if (empty($Name) && empty($Email)){
echo "<center>No email address and no name was entered. <br>Please include an email and a name</center>";
}
//if no name entered send an error
elseif (empty($Name)){
echo "<center>No name was entered.<br>Please include a name.</center><br>";
}
//if no email entered send print an error
elseif (empty($Email)){
echo "<center>No email address was entered.<br>Please include your email.</center> <br>";
}
//if the form has both an email and a message
else {

echo "<center>Thank you $Name, for your time.<BR>Please make sure to print out this page for your records.</center>";
}
endif;


With ofcourse the endif; being on line 307

Any advice? Or did I end it incorrectly? LOL

Modern Merlin
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7371
Location: Germany, Next to Hamburg

PostPosted: Wed 31 Oct '07 10:48    Post subject: Reply with quote

There is no endif if you are using { and }

remove the endif; and it will work.
Back to top
Modern Merlin



Joined: 30 Oct 2007
Posts: 10
Location: Roseville

PostPosted: Wed 31 Oct '07 14:40    Post subject: Reply with quote

OMG Im so sorry if you feel I have wasted your time! I figured out what my problem was...

I took out the endif and then I took a very hard look at the coding...

In one spot the variables I was trying to enter had an extra ' around it. Then I looked at my INSTERT INTO statement and low and behold (Taught me yet again not to code on absolutley no sleep for 2 days Very Happy ) that I was trying to insert the variables in my database and not the actual table! Rolling Eyes

So thank you so much for your time and efforts!

Modern Merlin
Back to top


Reply to topic   Topic: PHP - Passing Variables View previous topic :: View next topic
Post new topic   Forum Index -> Coding & Scripting Corner