Jump to content

beginners php


zeusthegreat

Recommended Posts

do not know what i have done wrong here, i have gone through the lesson 3 times now. lesson 6 video 2- 12mins 17 seconds

 

i keep getting this error when i click on the Query string link to capture email

 

the error Undefined index: name_first in C:\wamp\www\form_response.php on line 18

<br />

<b>Notice</b>: Undefined index: email in C:\wamp\www\form_response.php</b> on line 19

 

First Name: with an email of:

 

 

below is my code firstly for the form

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Untitled Document</title>

<style type="text/css">

body {

background-color: #FFC;

}

</style>

</head>

 

<body>

<br>

<form method="post" action="form_response.php">

 

<div class="form_element_div">

First Name: <br> <input name="name_first" type="text" size="50" maxlength="200">

</div>

<div class="form_element_div">

Email: <br><input name="email" type="text" size="50" maxlength="200"

</div>

<div class="form_element_div">

Favorite colour:

<INPUT type=radio value="red" name="colour">

red

<INPUT type=radio CHECKED value="yellow" name="colour">

yellow

<INPUT type=radio value="blue" name="colour">

blue

 

</div>

<br>

<div class="form_element_div">

Favorite Website:

<select name="favorite webite">

<Option value="" selected>Please Select</Option>

<Option value="www.killerstes.com">killersites.com </Option>

<Option value="www.killerphp.com">killerphp.com </Option>

<Option value="www.google.com">google.com </Option>

 

</select>

</div>

<br>

 

<div class="form_element_div">

Comments: <br>

<textarea name="comments" cols="50" rows="2" id="description" ></textarea>

</div>

<br>

<div class="form_element_div">

<input type="submit" name="submit_button" value="Submit Request >>" class="submit"

</div>

</form>

</div>

 

<div style="margin-top:25px;">

<a href="form_response.php?email=videos&name=stefan">Query String</a>

</div>

</body>

</html>

 

and then the form response php page

 

<div id="topbar"></div>

<div id="navigation" class="container"></div>

<div id="centerDoc" class="container">

<div style="margin-top:25px; margin-bottom:20px; "> </div>

 

 

 

<div>

 

<?php

 

 

 

// FORM PROCESSING CODE - USING 'SUPER GLOBALS' - KILLERPHP.COM

 

$first_name = $_POST['name_first'];

$email = $_POST['email'];

 

print "First Name: {$first_name} with an email of: {$email}";

 

?>

 

</div>

 

 

can anybody please give me some advice

Link to comment
Share on other sites

Two suggestions:-

Never have a space in name="..." like in <select name="favorite webite"> , edit to

<select name="favorite_webite">
or <select name="favorite-webite">

 

Also I think you don't need the curly { } brackets in

print "First Name: {$first_name} with an email of: {$email}";

Try this

print "First Name: $first_name with an email of: $email";

You can add p tags for correctness:-

print "<p>First Name: $first_name with an email of: $email</p>";

 

but I'm not sure if those cure the problem with $email as the variables $first_name and $email look OK.

 

Edit: there are coding errors in the html:-

<div class="form_element_div">
First Name: <br> <input name="name_first" type="text" size="50" maxlength="200" />
</div>
<div class="form_element_div">
Email: <br><input name="email" type="text" size="50" maxlength="200" />
</div>
.........
<input type="submit" name="submit_button" value="Submit Request >>" class="submit" />

I added / inside the > at the end of input tags (should be for all of them when using XHTML doctypes, but not for HTML doctypes) and I added /> at the end of the email and submit input tags where the > was missing.

 

As a last resort if the above fail, try editing the PHP code from

<?php

// FORM PROCESSING CODE - USING 'SUPER GLOBALS' - KILLERPHP.COM

$first_name = $_POST['name_first'];
$email = $_POST['email'];

print "First Name: {$first_name} with an email of: {$email}";

?>

to

<?php
if(isset($_POST['submit_button']))
{
// FORM PROCESSING CODE - USING 'SUPER GLOBALS' - KILLERPHP.COM

$first_name = $_POST['name_first'];
$email = $_POST['email'];

print "First Name: $first_name with an email of: $email";
}
?>

Edited by Wickham
Link to comment
Share on other sites

error message has now changed to

 

 

Notice: Undefined index: email in C:\wamp\www\form_response.php on line 20

 

Notice: Undefined variable: first_name in C:\wamp\www\form_response.php on line 22

First Name: with an email of:

 

 

 

 

 

 

i corrected the code as below

 

 

<div id="topbar"></div>

<div id="navigation" class="container"></div>

<div id="centerDoc" class="container">

<div style="margin-top:25px; margin-bottom:20px; "> </div>

 

 

 

<div>

 

<?php

 

if(isset($_POST['submit_button']))

 

 

// FORM PROCESSING CODE - USING 'SUPER GLOBALS' - KILLERPHP.COM

 

$first_name = $_POST['name_first'];

$email = $_POST['email'];

 

print "First Name: $first_name with an email of: $email"

 

?>

 

</div>

Link to comment
Share on other sites

I've downloaded your code and I think you are doing two things (I was only thinking about the submit button, not the Query String).

I've tested these codes, I used the main file with the form and then one PHP file to operate the submit button and another to operate the query string. I'm not sure if they can be combined.

 

Try this http://www.wickham43.com/forumposts/talos110209.php

filling in the input boxes and using the submit button for one result or using the query string link for the preset result with stefan and email for the other:-

 

talos110209.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
body {
background-color: #FFC;
}
</style>
</head>

<body>
<br>
<form method="post" action="talosresponse110209.php">

<div class="form_element_div">
First Name: <br> <input name="name_first" type="text" size="50" 
maxlength="200"/>
</div>
<div class="form_element_div">
Email: <br><input name="email" type="text" size="50" 
maxlength="200" />
</div>
<div class="form_element_div">
Favorite colour:
<INPUT type=radio value="red" name="colour"/>
red
<INPUT type=radio CHECKED value="yellow" name="colour"/>
yellow
<INPUT type=radio value="blue" name="colour"/>
blue

</div>
<br>
<div class="form_element_div">
Favorite Website:
<select name="favorite-website">
<Option value="" selected>Please Select</Option>
<Option value="www.killerstes.com">killersites.com </Option>
<Option value="www.killerphp.com">killerphp.com </Option>
<Option value="www.google.com">google.com </Option>

</select>
</div>
<br>

<div class="form_element_div">
Comments: <br>
<textarea name="comments" cols="50" rows="2" id="description" 
></textarea>
</div>
<br>
<div class="form_element_div">
<input type="submit" name="submit_button" value="Submit Request 
>>" class="submit" />
</div>
</form>
</div>

<div style="margin-top:25px;">
<a href="talosform_response110209.php?email=videos&name_first=stefan"
>Query String</a>
</div>
</body>
</html>

 

The talosresponse110209.php for the submit button

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
body {
background-color: #FFC;
}
</style>
</head>

<body>
<div id="topbar"></div>
<div id="navigation" class="container"></div>
<div id="centerDoc" class="container">
<div style="margin-top:25px; margin-bottom:20px; "> </div>
<div>

<?php
if(isset($_POST['submit_button']))
{
// FORM PROCESSING CODE - USING 'SUPER GLOBALS' - 

KILLERPHP.COM

$first_name = $_POST['name_first'];
$email = $_POST['email'];
$colour = $_POST['colour'];
$website = $_POST['favorite-website'];
$comments = $_POST['comments'];

print "<p>First Name: $first_name with an email of: $email and Favorite 
Colour: $colour and Favorite Website: $website and Comments: 
$comments</p>";
}
?>

</div>

</body>
</html>

and talosform_response110209.php for the Query String link

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
body {
background-color: #FFC;
}
</style>
</head>

<body>
<div id="topbar"></div>
<div id="navigation" class="container"></div>
<div id="centerDoc" class="container">
<div style="margin-top:25px; margin-bottom:20px; "> </div>

<div>
<?php

$first_name = $_GET['name_first'];
$email = $_GET['email'];

print "<p>First Name: $first_name with an email of: $email</p>";

?>

</div>

</body>
</html>

 

Both the submit button (fill in the boxes with whatever you want) and the Query string (with preset entries)work. The two processing files are nearly the same except one uses POST and the other uses GET (if you switch them in either file you get errors).

Edited by Wickham
Link to comment
Share on other sites

The php processing page that works from the submit button in the form action="..." is talosresponse110209.php and the one working from the Query link is talosform_response110209.php

 

so look for the corresponding places where the codes are in the page with the form talos110209.php

Edited by Wickham
Link to comment
Share on other sites

how come i have have tryed to customise these pages names and for some reason the button page does not work

 

Parse error: syntax error, unexpected T_VARIABLE in C:\wamp\www\form_response.php on line 28

 

 

the rest works

 

i called the first page talos_form.php and it works fine

 

 

the second page i called form_response.php and i get the above error when the button is pressed but it works ok on your link

 

the third page i called form_query.php and the query link on the form works fine

 

sorry to bother but the more mistakes i make the more i learn......

 

 

thankyou

Link to comment
Share on other sites

I have done this both ways downloaded code and applied your names to the particular pages and applied my names to the pages and i get the same error!

 

I am wondering if there is something in the php settings panel that i need to change as i am not thick by any means and usually when i follow a training lesson i plough through it no worries...

 

 

Please can somebody help as this lesson has held me up all week now!!!

 

 

thankyou...

Link to comment
Share on other sites

Copy/paste my three files, don't try to edit your files because you will make a mistake, then change only the filenames and that should make them work.

 

In my first file talos110209.php edit the action=".." to action="form_response.php" and edit the query link near the bottom to

<a href="form_query.php?email=videos&name_first=stefan">Query String</a>

and rename the whole file talos_form.php

 

The second and third of my files only need renaming form_response.php and form_query.php

 

I remember that you typed name="favorite webite" as a form name and I edited that to name="favorite-website" and that also occurs as $website = $_POST['favorite-website']; in my talosresponse110209.php which is the processing page for the submit button, so is that what's causing the trouble if you still have favorite webite in one file? Line 28 in your form_response.php (my talosresponse110209.php) probably is the website name so it needs to agree with the form name="..." in the main page talos_form.php

 

You shouldn't need to edit any php settings.

Edited by Wickham
Link to comment
Share on other sites

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'>http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'>http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">'>http://www.w3.org/1999/xhtml">'>http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Untitled Document</title>

<style type="text/css">

body {

background-color: #FFC;

}

</style>

</head>

 

<body>

<br>

<form method="post" action="form_response.php">

 

<div class="form_element_div">

First Name: <br> <input name="name_first" type="text" size="50"

maxlength="200"/>

</div>

<div class="form_element_div">

Email: <br><input name="email" type="text" size="50"

maxlength="200" />

</div>

<div class="form_element_div">

Favorite colour:

<INPUT type=radio value="red" name="colour"/>

red

<INPUT type=radio CHECKED value="yellow" name="colour"/>

yellow

<INPUT type=radio value="blue" name="colour"/>

blue

 

</div>

<br>

<div class="form_element_div">

Favorite Website:

<select name="favorite-website">

<Option value="" selected>Please Select</Option>

<Option value="www.killerstes.com">killersites.com </Option>

<Option value="www.killerphp.com">killerphp.com </Option>

<Option value="www.google.com">google.com </Option>

 

</select>

</div>

<br>

 

<div class="form_element_div">

Comments: <br>

<textarea name="comments" cols="50" rows="2" id="description"

></textarea>

</div>

<br>

<div class="form_element_div">

<input type="submit" name="submit_button" value="Submit Request

>>" class="submit" />

</div>

</form>

</div>

 

<div style="margin-top:25px;">

<a href="form_query.php?email=videos&name_first=stefan"

>Query String</a>

</div>

</body>

</html>

 

 

 

 

copied this pasted it like you said

 

 

named the file afterwards talos_form.php

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Untitled Document</title>

<style type="text/css">

body {

background-color: #FFC;

}

</style>

</head>

 

<body>

<div id="topbar"></div>

<div id="navigation" class="container"></div>

<div id="centerDoc" class="container">

<div style="margin-top:25px; margin-bottom:20px; "> </div>

<div>

 

<?php

if(isset($_POST['submit_button']))

{

// FORM PROCESSING CODE - USING 'SUPER GLOBALS' -

 

KILLERPHP.COM

 

$first_name = $_POST['name_first'];

$email = $_POST['email'];

$colour = $_POST['colour'];

$website = $_POST['favorite-website'];

$comments = $_POST['comments'];

 

print "<p>First Name: $first_name with an email of: $email and Favorite

Colour: $colour and Favorite Website: $website and Comments:

$comments</p>";

}

?>

 

</div>

 

</body>

</html>

 

 

 

then copied this and renamed the file

 

form_response .php

 

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Untitled Document</title>

<style type="text/css">

body {

background-color: #FFC;

}

</style>

</head>

 

<body>

<div id="topbar"></div>

<div id="navigation" class="container"></div>

<div id="centerDoc" class="container">

<div style="margin-top:25px; margin-bottom:20px; "> </div>

 

<div>

<?php

 

$first_name = $_GET['name_first'];

$email = $_GET['email'];

 

print "<p>First Name: $first_name with an email of: $email</p>";

 

?>

 

</div>

 

</body>

</html>

 

the copied this and named it form_query.php

 

and as has happened all the way through the talos_form page loads

 

the submit button comes up with

 

Parse error: syntax error, unexpected T_VARIABLE in C:\wamp\www\form_response.php on line 28

 

and the third page when clicked on the query link works fine

 

 

I have been using your code ever sinc e you posted it and still no joy!!!!

 

 

I am using wamp by the way if that has any significance

Link to comment
Share on other sites

In this section of your code:

 

<?php
if(isset($_POST['submit_button']))
{
// FORM PROCESSING CODE - USING 'SUPER GLOBALS' -

KILLERPHP.COM 

You can't have a multi-line comment line comment like that. Either you need to do:

 

<?php
if(isset($_POST['submit_button']))
{
/* FORM PROCESSING CODE - USING 'SUPER GLOBALS' -

KILLERPHP.COM */

or

 

<?php
if(isset($_POST['submit_button']))
{
// FORM PROCESSING CODE - USING 'SUPER GLOBALS' -

//KILLERPHP.COM 

 

It's possible that when Wickham entered in the code, either a line break was added accidentally, or the forum formatting itself messed things up somehow.

Link to comment
Share on other sites

Yes, my file has the lines closed up! It should be

 

// FORM PROCESSING CODE - USING 'SUPER GLOBALS' - KILLERPHP.COM

 

which is on two lines in my file but continuous, just breaking at the right side of a small window.

 

The above is copied from my Notepad file but usually when I copy into a forum post code tags (not just normal text like above) from Notepad it often splits lines with a line space and I try to close them up but missed that one (and possibly others) so not my fault - blame the forum or Notepad!

 

Sorry

Edited by Wickham
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...