★ wanayoo — archive 1999 http://www.devshed.com/Talk/Forums/Forum5/HTML/002012.htmlNouvelle recherche | Portail wanayoo
DevShed Menu
* DevShed Home
* Developer News
* DevShed Brain Dump




UBBFriend: Email This Page to Someone!
  DevShed Discussion Forums
  PHP
  comparing array contents

Post New Topic  Post A Reply
profile | register | preferences | faq | search

next newest topic | next oldest topic
Author Topic:   comparing array contents
zcrar70
Member
posted July 19, 2000 11:20 AM     Click Here to See the Profile for zcrar70   Click Here to Email zcrar70     Edit/Delete Message Reply w/Quote
hi,

i'm having a small problem with getting information into a database. Basically, i've got a form with some elements in it, such as:
name
phone
address

for example. I pass these values to a function which finds out whether the action is associateds with the form is to insert, update or delete info from/to the database (using an HTML "hidden" field.)

The field names in my database are the same as in my form. (name, phone etc...). Using mysql_fetch-field, I have an array with the field names in it. I read the values passed from the form into an array called $values with the form fields as keys ? I would like to set the entry as 'NULL' for each field in which there is no data to enter. I thought the best way to do this was by comparing the contents of both arrays, and where there was a key in $values corresponding to the fieldname, somehow assign the contents of $values to that fieldname in the query....

sorry this is quite specific and' i'm sure it's been answered before, except i can't find where.....does anyone have any ideas ?

cheers,
nick

Chris Pickett
Member
posted July 19, 2000 12:07 PM     Click Here to See the Profile for Chris Pickett   Click Here to Email Chris Pickett     Edit/Delete Message Reply w/Quote
Ok, if I am understanding correctly you want to take Name, Phone, etc., from an HTML form, and if it is empty put NULL in the database, otherwise, put what they enter?

Try something like this.

<?
if($name == " ")
{
$name = "NULL";
}
elseif($email == " ")
{
$email = "NULL";
}
etc.

then just insert, update like normal.

If I misunderstood just yell at me
Chris

ledjon
Member
posted July 19, 2000 12:56 PM     Click Here to See the Profile for ledjon   Click Here to Email ledjon     Edit/Delete Message Reply w/Quote
You should be able to setup the database so that it automatically puts NULL in if nothing is entered.

Chris Pickett
Member
posted July 19, 2000 01:05 PM     Click Here to See the Profile for Chris Pickett   Click Here to Email Chris Pickett     Edit/Delete Message Reply w/Quote
I think a text field automatically returns something, I had trouble when I was making a databse program, and trying to search, it would always come back with everything, because the empty text field would return a " ", but you can try that, if it works, it would be the easier solution.

Chris

ledjon
Member
posted July 19, 2000 01:34 PM     Click Here to See the Profile for ledjon   Click Here to Email ledjon     Edit/Delete Message Reply w/Quote
Oh, I see.. this is calling info from the DB then? (I didn't pay much attention). Then what chris suggested is the best thing to do.

zcrar70
Member
posted July 20, 2000 05:27 AM     Click Here to See the Profile for zcrar70   Click Here to Email zcrar70     Edit/Delete Message Reply w/Quote
hi,

thanks a lot for your answers - unfortunately that's not quite what i'm trying to do. I'm actualy trying to build a function / class to dynamically enter info from a form into a database, independent of the form or the database used or of the action (insert, update etc.,..).

As such I though that if I entered the info from the form into an array and compared the keys to the 'name' key in the array returned by mysql_fetch_fields, I could enter the info from the form in the corresponding field in the db insert 'null' to the rest. (I actually need to send NULL in the query, so that auto_increment or timestamp fields automatically set.)

Any ideas ?

Cheers,

nick

All times are MST (US)

next newest topic | next oldest topic

Administrative Options: Close Topic | Archive/Move | Delete Topic
Post New Topic  Post A Reply
Hop to:

Contact Us | DevShed.com

Copyright © 1997-2000 ngenuity. All rights reserved.

Powered by: Ultimate Bulletin Board, Version 5.41a
© Infopop Corporation (formerly Madrona Park, Inc.), 1998 - 1999.