Jump to content

PHP Newbie - Probably very simple answer - whats missing from code???


Recommended Posts

Hi All

Attempting to learn PHP (as far as page 29)

 

Trying to return form variables to a script. However the values are not displayed.

I have attached the code for both pages below. Whats wrong with it????

 

<HTML>

<HEAD>

<TITLE> HTML Forms </TITLE>

</HEAD>

<BODY>

<FORM ACTION="formhandler.php" METHOD="post">

Name: <INPUT TYPE=TEXT NAME="name" SIZE-20><BR>

Email: <INPUT TYPE=TEXT NAME="email" SIZE-20><BR>

Company: <INPUT TYPE=TEXT NAME="company" SIZE-20><BR>

Phone Number: <INPUT TYPE=TEXT NAME="number" SIZE-20><BR>

<INPUT TYPE=SUBMIT NAME="SUBMIT" VALUE="Submit !">

</FORM>

</BODY>

</HTML>

 

<HTML>

<HEAD>

<TITLE> HTML Forms </TITLE>

</HEAD>

<BODY>

<?PHP

print "Name - $name.<BR>\n";

print "Email - $email.<BR>\n";

print "Company - $company.<BR>\n";

print "Phone Number - $number.<BR>\n";

?>

</BODY>

</HTML>

 

The form returns:

 

Name - .

Email - .

Company - .

Phone Number - .

 

No Variable Values are added All help and advice gratefully received.

 

Many Thanks

Wizpeep

 

You are not trying to get the values from form.

 

$1 = $_POST["name"];
$2 = $_POST["email"];
$3 = $_POST["company"];
$4 = $_POST["number"];

 

and then query to insert into DB

 

$sql = "INSERT INTO table_name (name_of_fields) VALUES ($variables)";
$result = mysql_query($sql) or die (mysql_error());

 

That's basiclly all the code you need to insert data in DB. just adjust it according to your needs and to match your DB fields.

 

P.S.

You know that you need a connection to DB??

I assume the page that your form is on is 'formhandler.php'?

 

if so, put this at the top for each variable you use in your form:

 

<?php
$name = isset($_POST['name']) ? $_POST['name'] : "";  //this tells it that if the form was submitted, get the value of 'name' from the post array and assign it to the variable $name, if it wasn't set, set it to "" (nothing).
?>
<HTML> ....

 

@budimer - Where did he ask anything about a database?

You are not trying to get the values from form.

 

$1 = $_POST["name"]
$2 = $_POST["email"]
$3 = $_POST["company"]
$4 = $_POST["number"]

 

and then query to insert into DB

 

$sql = "INSERT INTO table_name (name_of_fields) VALUES ($variables)";
$result = mysql_query($sql) or die (mysql_error());

 

That's basiclly all the code you need to insert data in DB. just adjust it according to your needs and to match your DB fields.

 

P.S.

You know that you need a connection to DB??

 

What?!  He's not even using a database, he's just learning PHP.  o_O

 

Anyway, how old is this book you're learning from?  It's using fricken' capitalized HTML tags (which don't work in XHTML) and it's depending on register_globals().  It must be over 8 years old.

Well, now he will have much clearer picture of how to store data in a DB. I don't see any point in just displaying the values on the form.

 

If he is learning then I showed him much bigger picture and made the situation more understandable for him.

 

And, I'm sorry guys, but if he is learning PHP, then it's much better that he learns how to create a database and establish a link to it, first. Then he can start learning PHP.

 

It's like a building a house from the roof.

Well, now he will have much clearer picture of how to store data in a DB. I don't see any point in just displaying the values on the form.

 

If he is learning then I showed him much bigger picture and made the situation more understandable for him.

 

And, I'm sorry guys, but if he is learning PHP, then it's much better that he learns how to create a database and establish a link to it, first. Then he can start learning PHP.

 

It's like a building a house from the roof.

 

You'd have to be retarded to build a house from the roof considering that the roof collapses with nothing underneath it and kills all the workers.

 

I'm pretty sure pilots don't fly a couple times and then learn controls, nor do composers write a sonata and then learn to compose.

 

Please make sense next time you decide to turn new PHP programmers down the completely wrong path.

Thanks everyone

The version of PHP covered is 3&4 (VisualQuickstart PHP)

I am at a very early stage on my learning curve. I would like to create database driven dynamic pages.

Would it be a better way to become conversant with MYSQL first???

 

The only thing I desperately need to do is return inputs from a enquiry form to an email address. at the moment.

 

As i said I am at a very very early stage in my PHP/MYSQL learning.

Well, you've got your opinion.  ;D

 

And, you are getting OFF TOPIC!

 

I'm not off-topic at all, you were completely off topic.  He's learning PHP and just wants to understand form processing, and you go off talking about how to use databases.  If you asked your friend for help on your algebra homework and he starts telling you about calculus and says it's because 'since you are learning, I showed you much bigger picture and made the situation more understandable for you.', what would you say?

Thanks everyone

The version of PHP covered is 3&4 (VisualQuickstart PHP)

I am at a very early stage on my learning curve. I would like to create database driven dynamic pages.

Would it be a better way to become conversant with MYSQL first???

 

The only thing I desperately need to do is return inputs from a enquiry form to an email address. at the moment.

 

As i said I am at a very very early stage in my PHP/MYSQL learning.

 

PHP3 no longer even exists.  PHP4 is horribly deprecated.  PHP6 is almost out, that's how far behind that book is.  Go buy a NEW book.  That book will get you NOWHERE, and is probably teaching you the WORST possible practices (register_globals, not even proper XHTML, etc).

OK, that is quite simple.

 

You can use PHP mail() function to send emails.

 

$to = "email@example.com"; //Here goes $_POST["email"];
$subject = "Test mail"; //Here goes some subject like "This is enqur. from web page"
$message = "Hello! This is a simple email message."; //Here goes like phone number etc.
$from = "someonelse@example.com";
$headers = "From: $from"; //Here goes you're email adress
mail($to,$subject,$message,$headers);
echo "Mail Sent.";

 

Also, DarkWater is right, go get new book. This is just causing problems for you.

I have a form and want enquiries back to my email address

The code is:

<form name="form1" method="post" action="">

              <div align="left"><span class="style24">name:</span> <br>

                <input name="name" type="text" class="formfield" id="name2" size="30" maxlength="30">

                <span class="style24">company: </span><br>

                <input name="company" type="text" class="formfield" id="name" size="30" maxlength="30">

                <br>

                <span class="style24">phone number </span><br>

                  <input name="phonenumber" type="text" class="formfield" id="company" size="30" maxlength="30">

                  <br>

                <span class="style24">email address:</span><br>

                <input name="email" type="text" class="formfield" id="name" size="30" maxlength="40">

                <br>

                  <span class="style24">add your message here </span><br>

                <textarea name="textarea" cols="35" rows="6" class="formfield"></textarea>

                  <input name="brochure" type="checkbox" id="brochure" value="brochure">

                <span class="style24">              request brochure</span><br>

                <br>

                <input name="Submit" type="submit" class="submitbutton" value="submit">

                  <br>

              </div>

            </form>

 

I want this returned to my email info@recruitment4less.co.uk

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.