Re: Decoding the query string array

From: Randell D. (you.can.email.me.at.randelld_at_yahoo.com)
Date: 10/26/03


Date: Sun, 26 Oct 2003 06:25:15 GMT


"davidv" <eigenstates@yahoo.com> wrote in message
news:WB2dneUW5a9aEwSiXTWc-g@speakeasy.net...
> I am building a very simple form that takes text and inserts data in a
> MySQL db.
>
> I would like my "logic" to simply insert the value in to the field in
> the database that matches the name from the query string.
>
> Here's the question- can I do this if I do not know how many name/value
> pairs are passed to the "logic" ? Can I just step through the $_POST
> array and use a do while $i <= count($_POST) or something?
>
> I have tried this but for some reason I cannot get a number back from
> the $_POST array. I am also confused about how the $_POST array is
> constructed. How do I reference name/value pair $_POST[0,1,2 etc...] get
> their "names" and "values" in to variables so I can accomplish the
> INSERT SQL(e.g. $name = $_POST[0,0]; $value = $_POST[0,1]; [INSERT
> $value INTO $name];- The MySQL fields will match $name)?
>
> Thanks in advance.
>
> David
>

First off - you ought to becareful writing $_POST data to the database
without first ensuring that its clean. Do you have magic_quotes on (its on
by default I think). Secondly, I have all my db values sent through
trim() - This removes excess space either side of your values, including any
null characters (I don't fully understand the latter other than believing
that some hacks can be performed with buffer overruns which (I believe, I
could be wrong) is performed by passing commands beyond null characters
(again, dunno how its done but believe I'm preventing such a hack from
happening by using trim().

Secondly... You need to know how an associated array works...

If you have a text field in HTML like so:

<input type=text name=firstname>

and it is submitted in a form, your $_POST will have a variable
$_POST['firstname']

If you're ever unsure about what has been passed, have your form posted to a
script that calls phpinfo(); and examine the output.

Secondly...

I'm new to MySQL but I have written a script that takes my HTML field/box
names and passes them to an insert in the correct order.... you have to be
careful with this.

I suggest that you first get to know arrays, single and multipe dimensional
and be sound on manipulating them before you think about writing them to the
database... You've not been entirely clear with your request, but I think I
know what you are trying to do... this is possible... but unless you read up
a little more, you could end up writing a script that you rely on, but
unable to support...



Relevant Pages

  • Re: php script to create mySQL database programmatically
    ... "Jerry Stuckle wrote: ... hosting configuration may not allow create database from script, ... You can make a script to create a database. ... Can't connect to local MySQL server through socket ...
    (comp.lang.php)
  • Re: Newbie- Can I create a new MySQL database from within my app?
    ... > database would you normally say to them "No, ... I have no experience with MySQL but SQL Server can export an existing ... script for it once it works. ...
    (alt.comp.lang.borland-delphi)
  • Re: Fwd: Cron run-parts /etc/cron.daily
    ... password yadda yadda, but while I've spent an hour or more reading the ... Can't connect to the database. ... It needs to log in to the mysql database. ... There is a password set for the user 'mysql' in the other default script, ...
    (Fedora)
  • Get IP Address and MAC Address via script
    ... I am currently writing a domain migration script to join workstations ... Two of the columns in the database are for IP Address and ... multiple adapters with an IP Address or a single adapter with multiple ...
    (microsoft.public.scripting.vbscript)
  • DBD::mysql::st execute failed: MySQL server has gone away
    ... I have just recently setup a new FreeBSD 4.9 stable server running MySql ... I have a perl script that connects to the MySql database and then loops ...
    (comp.unix.bsd.freebsd.misc)