HTML form data to MySQL using PHP... url length problems...

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
Sinemacula
Forum Contributor
Posts: 110
Joined: Sat Feb 08, 2003 2:36 am
Location: San Jose, CA

HTML form data to MySQL using PHP... url length problems...

Post by Sinemacula »

Hi,

First, I apologize if I'm posting this question under the wrong category... I wasn't sure whether to go with PHP-Normal, ClientSide or Databases.

So, here's the problem:

I've created an html form with about 30 questions... some of which provide space for lengthy answers. I'm using a php script to process the data, inserting the data into a MySQL database, and sending me a confirmation email with the data also as a backup.

However, the data being input by the users is carried from the html form to the php script in the URL... and when users input long answers, I'm getting an error:

Code: Select all

Request-URI Too Large
 The requested URL's length exceeds the capacity limit for this server.

 request failed: URI too long
Here's the script I'm using:

Code: Select all

<?PHP
	$db = mysql_pconnect("localhost", "--------", "--------");
	if (!$db) &#123; 
echo( "<p>Unable to connect to the " . 
"database server at this time.</p>" ); 
exit(); 
&#125;
	mysql_select_db("survey2", $db);
	$sql = ("INSERT INTO ---survey (Code,length,area,Q3,Q4,Q5,Q6,Q7,Q8,Q9,Q10,Q11,Q12,Q13,Q14,Q15,Q16,Q17,Q18A,Q18B,Q18C,Q18D,Q18E,Q18F,Q18G,Q18H,Q18I,Q18J,Q19,Q20,Additional) VALUES ("$Code","$length","$area","$Q3","$Q4","$Q5","$Q6","$Q7","$Q8","$Q9","$Q10","$Q11","$Q12","$Q13","$Q14","$Q15","$Q16","$Q17","$Q18A","$Q18B","$Q18C","$Q18D","$Q18E","$Q18F","$Q18G","$Q18H","$Q18I","$Q18J","$Q19","$Q20","$Additional");"); 
	$result = mysql_query($sql, $db);

$subject = "--- Survey"; 
$toaddress = "scott@-------.com";
$from_name = "---";
$from_email = "scott@--------.com";
$headers = "From: $from_name<$from_email>\n"; 
$headers .= "Reply-To: <$from_email>\n"; 
$headers .= "MIME-Version: 1.0\n"; 
$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n"; 
$headers .= "X-Sender: $from_name<$from_email>\n"; 

$headers .= "X-Mailer: PHP4\n"; //mailer 
$headers .= "X-Priority: 2\n"; //1 UrgentMessage, 3 Normal 
$headers .= "Return-Path: <$from_email>\n"; 
$date  = date("l, F d, Y");
$message  = "				--- SURVEY

Name: $Code				
Date: $date

1. $length
2.  $area
3. $Q3
4.$Q4
5. $Q5
6. $Q6
7. $Q7
8. $Q8
9. $Q9
10. $Q10
11. $Q11
12. $Q12
13. $Q13
14. $Q14
15. $Q15
16. $Q16
17. $Q17
18. 
a.  $Q18A
b.  $Q18B
c.  $Q18C
d.  $Q18D
e.  $Q18E
f.   $Q18F
g.  $Q18G
h.  $Q18H
i.  $Q18I
j.  $Q18J
19. $Q19
20. $Q20
$Additional"\n";

$message .= "\n";
// this ends the message part 
// send the message :-) 
mail($toaddress, $subject, $message, $headers);
?>
(There's also html at the end, to create a thank you page)

What do I need to change to make it so that the data is passed some other way? Can the php somehow be added to the html form itself? Would that solve the problem?

This newbie appreciates any direction you can give!!

Thanks,
Scott
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

...

Post by kettle_drum »

Are you using GET rather than POST in your form?
Sinemacula
Forum Contributor
Posts: 110
Joined: Sat Feb 08, 2003 2:36 am
Location: San Jose, CA

Post by Sinemacula »

You're right... I just double-checked the form, and it's GET... is that what will be causing the problem? If I change it to POST will it be solved? (Man, I must really sound like a newbie, huh?)

Thanks,
Scott
Sinemacula
Forum Contributor
Posts: 110
Joined: Sat Feb 08, 2003 2:36 am
Location: San Jose, CA

Thank you!

Post by Sinemacula »

Okay, I suppose I could have just tested it before I posted that follow-up... anyway, I changed it to POST and now it works fine.

Thank you!

Scott
Post Reply