Forum Moderators: coopster

Message Too Old, No Replies

Posting PDF Form data to mySQL

I am having trouble storing my data in mySQL

         

mbair

8:33 pm on Aug 11, 2005 (gmt 0)

10+ Year Member



I am working on a script that will take information submitted from a pdf form and store the field data to a given mySQL table. I just cant figure out what is wrong with my script. I am able to get the data from the pdf form, and set it as a variable so I can work with it in php. It is displaying the proper data when I echo() it, and I get no mySQL errors. It looks like everything should work, but when I check my database, nothing has been updated.

Any suggestions?
Matt

Here is the code I have written:

<?php
// Get Client NAME
$firstname = $_COOKIE['fname'];
$lastname = $_COOKIE['lname'];

// Get info from pdf post
$Participant_Street = $_POST['Participant_Street'];
echo "Participant Street: '$Participant_Street'" ;

// Connect to mySQL
$conn = @mysql_connect("localhost", "user", "password")
or die("Could not connect to MySQL");
$db = @mysql_select_db("my_database", $conn)
or die("Could not select database");

// Insert Data for Client
$sql = "UPDATE clients SET Participant_Street = '$Participant_Street' WHERE fname = '$firstname' and lname = '$lastname'";
$result = @mysql_query( $sql, $conn)
or die("Could not execute query");
if($result) {echo("Information: $Participant_Street saved");}
?>

If I fill out my pdf with some information (say 691 in the "Participant Street" field) I get the following displayed:

Participant Street: '691'Information: 691 saved

Just as I would expect if it worked properly. No errors.

[edited by: ergophobe at 8:35 pm (utc) on Aug. 11, 2005]
[edit reason] Anonymized user and password (hacker alert) [/edit]

ergophobe

8:37 pm on Aug 11, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



echo the $sql var (your query). I suspect you're not getting firstname or lastname.

If you haven't got error_reporting set to E_ALL, do so (it will alert you to undefined variables).

mbair

9:21 pm on Aug 11, 2005 (gmt 0)

10+ Year Member



You were right, I am not getting the information from my cookies. I dont know why though... I checked and made sure my page is making the cookies and they are named lname and fname. Any idea? Also, how do I change my error reporting as you suggested?

When I echoed my sql query I got:

UPDATE clients SET Participant_Street = '691' WHERE fname = '' and lname = ''

Here is my current code:

<?php // Get Client NAME
$firstname = $_COOKIE['fname'];
$lastname = $_COOKIE['lname'];
?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>

<body>
<?php

// Get info from pdf post
$Participant_Street = $_POST['Participant_Street'];
echo ("Participant Street: $Participant_Street") ;

// Connect to mySQL
$conn = @mysql_connect("localhost", "user", "password")
or die("Could not connect to MySQL");
$db = @mysql_select_db("my_database", $conn)
or die("Could not select database");

// Insert Data for Client
$sql = "UPDATE clients SET Participant_Street = '$Participant_Street' WHERE fname = '$firstname' and lname = '$lastname'";
$result = @mysql_query( $sql, $conn)
or die("Could not execute query");
if($result) {echo("Information: $Participant_Street saved $sql");}
?>

</body>
</html>

[edited by: ergophobe at 1:01 am (utc) on Aug. 12, 2005]
[edit reason] Anonymized user and password (hacker alert) [/edit]

coopster

3:43 am on Aug 12, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, mbair.

To turn error_reporting on you can simply add the function to the top of your script during development (don't forget to remove it before putting it into production though).

<?php
error_reporting [php.net](E_ALL);
?>

Have you read through some of the common COOKIE pitfalls [php.net]?