Problem with php code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nttssv
Forum Newbie
Posts: 1
Joined: Wed Oct 26, 2005 7:59 am

Problem with php code

Post by nttssv »

Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


Hi all , I just started to learn PHP , I encounter an error when trying this code. Can u enlighten me ?

My code for creat_entry.php is

Code: Select all

<?php 
include("dbconnect.php"); 

if ($_POST['submit'] == "Sign!") 
{ 
$query = "insert into guestbook 
(name,location,email,url,comments) values 
(‘$name’, ‘$location’, ‘$email’, ‘$url’, ‘$comments’)"; 
mysql_query($query) or
	die (mysql_error()); 
?> 

<h2>Thanks!!</h2> 
<h2><a href="view.php">View My Guest Book!!!</a></h2> 

<?php 
} 
else 
{ 
include("sign.php"); 
} 
?>
My code for sign.php

Code: Select all

<h2>Sign my Guest Book!!!</h2> 

<form method=POST action="create_entry.php">

<b>Name:</b> 
<input type=text size=40 name=name> 
<br> 
<b>Location:</b> 
<input type=text size=40 name=location> 
<br> 
<b>Email:</b> 
<input type=text size=40 name=email> 
<br> 
<b>Home Page URL:</b> 
<input type=text size=40 name=url> 
<br> 
<b>Comments:</b>
<textarea name=comments cols=40 rows=4 wrap=virtual></textarea> 
<br> 

<input type=submit name=submit value="Sign!"> 
<input type=reset name=reset value="Start Over"> 

</form>

The result I got when running create_entry.php is

Notice: Undefined index: submit in c:\Inetpub\wwwroot\create_entry.php on line 4


Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Last edited by nttssv on Wed Oct 26, 2005 8:34 am, edited 1 time in total.
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

change submit to name since submit will not exist if you press enter inside a textfield or submit the form by other means...
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

try putting POST in quotes and the rest is speculation, maybe try switching value=Sign! to value="submit" and then change what you check for. I want to say a long time ago there was a bug where I.E. generally got cranky if name and value were different...Who knows? There's my two theories.
Post Reply