wizpeep Posted October 14, 2008 Share Posted October 14, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/128420-php-newbie-probably-very-simple-answer-whats-missing-from-code/ Share on other sites More sharing options...
budimir Posted October 14, 2008 Share Posted October 14, 2008 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?? Quote Link to comment https://forums.phpfreaks.com/topic/128420-php-newbie-probably-very-simple-answer-whats-missing-from-code/#findComment-665425 Share on other sites More sharing options...
CroNiX Posted October 14, 2008 Share Posted October 14, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/128420-php-newbie-probably-very-simple-answer-whats-missing-from-code/#findComment-665428 Share on other sites More sharing options...
DarkWater Posted October 14, 2008 Share Posted October 14, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/128420-php-newbie-probably-very-simple-answer-whats-missing-from-code/#findComment-665429 Share on other sites More sharing options...
budimir Posted October 14, 2008 Share Posted October 14, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/128420-php-newbie-probably-very-simple-answer-whats-missing-from-code/#findComment-665436 Share on other sites More sharing options...
DarkWater Posted October 14, 2008 Share Posted October 14, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/128420-php-newbie-probably-very-simple-answer-whats-missing-from-code/#findComment-665438 Share on other sites More sharing options...
budimir Posted October 14, 2008 Share Posted October 14, 2008 Well, you've got your opinion. And, you are getting OFF TOPIC! We can open a discussion about this somewhere else! Quote Link to comment https://forums.phpfreaks.com/topic/128420-php-newbie-probably-very-simple-answer-whats-missing-from-code/#findComment-665443 Share on other sites More sharing options...
wizpeep Posted October 14, 2008 Author Share Posted October 14, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/128420-php-newbie-probably-very-simple-answer-whats-missing-from-code/#findComment-665444 Share on other sites More sharing options...
DarkWater Posted October 14, 2008 Share Posted October 14, 2008 Well, you've got your opinion. 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? Quote Link to comment https://forums.phpfreaks.com/topic/128420-php-newbie-probably-very-simple-answer-whats-missing-from-code/#findComment-665446 Share on other sites More sharing options...
DarkWater Posted October 14, 2008 Share Posted October 14, 2008 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). Quote Link to comment https://forums.phpfreaks.com/topic/128420-php-newbie-probably-very-simple-answer-whats-missing-from-code/#findComment-665450 Share on other sites More sharing options...
budimir Posted October 14, 2008 Share Posted October 14, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/128420-php-newbie-probably-very-simple-answer-whats-missing-from-code/#findComment-665452 Share on other sites More sharing options...
wizpeep Posted October 14, 2008 Author Share Posted October 14, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/128420-php-newbie-probably-very-simple-answer-whats-missing-from-code/#findComment-665468 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.