News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

PHP newbie - IF statement

Started by TonyJ, February 26, 2020, 12:12:32 PM

Previous topic - Next topic

TonyJ

Hi,

I'm using a PHP snippet from the SMF forums, which allows me to import 300 users into our private forum.

During the import process, I need to determine who doesn't have an email address (Column is blank in the Member CSV that i'm importing from)

If the field is blank, I need to substitute a fake email address, which will be the Member Number i.e. [email protected]

The Import PHP file uses an array to grab the data from the CSV, then parses it to SUB-MEMBERS.PHP to load the SQL database i.e

'email-address' => $key[0],
'member-number' => $key[1],

So, I need something like this to work in my Import PHP file: (Sorry, it's in BASIC)

IF $key[0] = "" THEN
    // No email address, so make one up, using Member Number
    'email-address' => $key[1] & "no-email.com"
ELSE
    // Email address exists, so use it
    'email-address' => $key[0]
END IF

Thanks again.



I want to die in my sleep like my Grandfather. Not kicking and screaming like his passengers!

Shambles

Something like

<?php
// assuming $key is an array()

$email_address = empty($key[0]) ? $key[1] . '@no-email.com' $key[0];

TonyJ

Thanks for your help, Shambles.

I had to change a few things to make it work, but all good.

'email' => empty($key[3]) ? $key[0] . "@no-email.com" : $key[3],

Thanks very much.
I want to die in my sleep like my Grandfather. Not kicking and screaming like his passengers!

Advertisement: