[Phpug] Help Please?????
Tony Freegrove
tonyf at southeastpromotions.com
Fri Dec 14 08:02:39 GMT 2007
Kae,
Thanks for that, Someone else who is up at strange hours! I assigned the
variables as definite values in the line following the "if($value!="")"
statement. I've tried it with [] after them too but it just posts the
string "array" to the DB. The initial 4 variables are not part of the array,
the only 2 that are are $assign and $defect, as they're the only ones that
will change. Does using a mix of definite values and arrays really mess
with the script.
The $key++ is there because I've tried while, for and do / while loops and
I've obviously forgotten to take it out on the last change.
I also note your point about the inefficiency of the last section within the
loop, I'll take it out.
As I said, I'm new to PHP and really struggling with this one.
Tony
-----Original Message-----
From: phpug-bounces at lists.iephpug.org
[mailto:phpug-bounces at lists.iephpug.org] On Behalf Of Kae Verens
Sent: 14 December 2007 07:38
To: Irish PHP User Group
Subject: Re: [Phpug] Help Please?????
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Tony Freegrove wrote:
> The specific code I'm having the problem with is below. Have I left
> something glaringly obvious out????
>
> Thanks in advance for any help on this.
>
> <?
> foreach($defects as $key => $value){
> $key++;
why is the $key++ there?
> if ($value!=""){
>
> print "<tr><td colspan='2'><input name='defect' type='hidden'
> value='$value'>$value</td><td colspan='2'><select name='assign'
> id='assign'><option value='estates'>Estates</option><option
> value='fieldops'>Field Ops</option><option
> value='contractor'>Contractor</option><option
> value='misc'>Miscellaneous</option><option value='nfa'>No Further
> Action</option><option value='close'>Close</option></select><br
> /></td></tr>";
>
> if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
> $insertSQL = sprintf("INSERT INTO estates (siteref, sitename,
> `date`, engineer, defect, assigned) VALUES (%s, %s, %s, %s, %s, %s)",
> GetSQLValueString($_POST['siteref'], "text"),
> GetSQLValueString($_POST['sitename'], "text"),
> GetSQLValueString($_POST['date'], "date"),
> GetSQLValueString($_POST['engineer'], "text"),
> GetSQLValueString($_POST['defect'], "text"),
>
> GetSQLValueString($_POST['assign'], "text"))
ok - there's your problem - $_POST['assign'] for example is not an array
- - it is an exact value.
look at this URL:
http://test.com/blah.php?assign=1&assign=2
when you echo $assign in that page, you will be shown "2".
look at this one:
http://test.com/blah.php?assign[]=1&assign[]=2
now, when you echo it, it will fail because $assign is an array -
var_dump($_GET['assign']) will show you this.
so the main problem is that you've been naming your POST variables
incorrectly. You did not include the code for them, but I assume that you do
not have '[]' at the end of the names for the fields.
> mysql_select_db($database_connaiep, $connaiep);
inefficient - put this line outside the loop.
> $Result1 = mysql_query($insertSQL, $connaiep) or die(mysql_error());
> } } }
- --
Kae Verens
http://webworks.ie/ lead programmer
http://verens.com/ my blog
http://kfm.verens.com/ current project
- --
this is Kae's signature's signature.
yes, he really is that important.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFHYjLVA9z/zIBK4hURAucnAJ9GZgTrQYd/F6nYpEx4kZXbWP1nYwCfdeQR
yLJAnDfhm1Sw3RXPhBrh3M0=
=IgK7
-----END PGP SIGNATURE-----
_______________________________________________
Phpug mailing list
Phpug at lists.iephpug.org
http://lists.iephpug.org/mailman/listinfo/phpug
Member Map http://www.frappr.com/irishphpusersgroup/
Membership Planner Calendar: http://tinyurl.com/opjd5
More information about the Phpug
mailing list