[Phpug] Help Please?????

Kae Verens kae at webworks.ie
Fri Dec 14 07:37:57 GMT 2007


-----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-----


More information about the Phpug mailing list