Forum Moderators: coopster

Message Too Old, No Replies

form not passing values

         

dave1236

6:58 pm on Nov 10, 2009 (gmt 0)

10+ Year Member



I have a form that a user completes that is designed to provide users the ability to add promotions to the site.

For some reason, when I submit my form, an entry is created in the database, but no data is actually transmitted.

When I tested by printing my form data, I get blanks as well.

Thoughts?

rocknbil

7:59 pm on Nov 10, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Whenever I encounter this it usually leads to an HTML error in the originating form that borks up the submitted data. A missing quote, something improperly nested, like that. Validate the form via the W3C validator, try again, if it doesn't work post relevant portions of the form and code.

dave1236

8:41 pm on Nov 10, 2009 (gmt 0)

10+ Year Member



thanks, i will do so. i did make some changes.

TheMadScientist

12:01 am on Nov 11, 2009 (gmt 0)

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



It might have to do with attempting to pass an array() if that's what you're doing...

<input
type="hidden"

name="ShouldBeAnArrayAccordingToPHP[]"

value="Unfortunately, it doesn't work in some newer version(s), so you have to give your fields unique names and loop through them to get the info... A PHP upgrade actually seems to have broken a form I was asked to fix."
>

dave1236

3:32 pm on Nov 11, 2009 (gmt 0)

10+ Year Member



OK...I have placed my code below. Here is what happens...

If I submit the form below by entering a value for "name", I get an entry in the DB, but the value is blank. If, in my script to submit, I change "$name" to 'name' the value 'name' is entered in the database.

I had permission issues a while ago. Could this be the issue? Should I potentially just delete my Databases, and start over?

Here is my test code...
the simple Form...

<form action="testadd.php" method="POST">
<table border="0" width="100%">
<tr><td align="right"><b>Name</b></td>
<td width="282"><input type="text" name="name" value="" size="15" maxlength="20"></td></tr>
<tr><td colspan="2">
<input type="submit"
value="Submit"></td>
</tr>
</table>
</form>

testadd.php...
<?php
session_start();
include("incfiles/dogs.inc");
$connection = mysql_connect($host,$user,$password)
or die ("Couldn't connect to server.");
$db = mysql_select_db($database, $connection)
or die ("Couldn't select database.");
$today = date("Y-m-d");
$sql = "INSERT INTO test VALUES
('$name')";
mysql_query($sql);
header("Location: index.php");
?>

MatthewHSE

3:44 pm on Nov 11, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't see the $name variable assigned a value anywhere in testadd.php. That's why you're getting the blank row in your database when using $name in your query, and why you get a row with 'name' in it when you use 'name' instead of the $name variable. You need something like this:

$name = $_POST['name'];

Don't use it just like that though - you need to first sanitize all user-submitted data before you try to do anything with it in relation to your database. (Read about MySQL Injection Attacks [bing.com] for more info.)

dave1236

3:56 pm on Nov 11, 2009 (gmt 0)

10+ Year Member



Interesting....that works.

Is this a new change for form data? I ask because I have other scripts that continue to work, or at least I did not have a POST statement for each value I was passing.

Thanks,

David

dave1236

4:24 pm on Nov 11, 2009 (gmt 0)

10+ Year Member



nevermind the above...i did find something...