Advertisement:

Author Topic: PHP newbie - IF statement  (Read 212 times)

Offline TonyJ

  • Semi-Newbie
  • *
  • Posts: 20
  • Gender: Male
PHP newbie - IF statement
« on: February 26, 2020, 12:12:32 PM »
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. 32564@no-email.com

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!

Offline Shambles

  • SMF Hero
  • ******
  • Posts: 5,418
  • Gender: Male
    • i30 Owners Club
Re: PHP newbie - IF statement
« Reply #1 on: February 26, 2020, 01:39:10 PM »
Something like

Code: [Select]
<?php
// assuming $key is an array()

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

Offline TonyJ

  • Semi-Newbie
  • *
  • Posts: 20
  • Gender: Male
Re: PHP newbie - IF statement
« Reply #2 on: February 26, 2020, 07:31:49 PM »
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!