Forum Moderators: coopster
<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."
>
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");
?>
$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.)