Jump to content

[SOLVED] if statement help


darkfreaks

Recommended Posts

ok right now i have

 

<?php

if($age<18) {echo "You can not add this user nice try pedo";}

?>

 

 

but i also want it to search membersprofile.php for the age and if the user that is posting to the underage user is above 18 to not allow them to add them as a friend. but i still want people who are under 17 to be able to add people who are the same age if not less.

Link to comment
Share on other sites

We need some code of somesort to help you. Where is the code that you use to check if they are under 18?

You will need 2 variables, one of the logged in user ($user_age) and one of the user you are trying to message/add/whatever ($target_age) then base your if statement off that

 

Need some code to help. What variables do you have to work with?

Link to comment
Share on other sites

Code:

 

<?php
$strTitle = 'You are now friends';
define('QUADODO_IN_SYSTEM', true);
require_once('includes/header2.php');

$with = $qls->Security->make_safe($_POST['with']);
$username = $qls->Security->make_safe($_POST['username']);

include ('config.php');

$result = $qls->SQL->select('*',
  'friends',
  array('username' =>
    array(
      '=',
      $username
    )
  )
);

$already_friends = false;
while ($row = $qls->SQL->fetch_array($result)) {
  if ($row['with'] == $with) {
  $already_friends = true;
  }
}
if($age<18){echo "You can't add a user under 18 for legal reasons!";}
if ($already_friends === true) {
echo 'You are already friends with ' . $with;
}
else {
// My insert query faster and handles errors
$qls->SQL->insert('friends',
  array(
    'username',
    'with'
  ),
  array(
    $username,
    $with
  )
);

echo "You are now friends with <a href=\"../profile/$with\">$with</a>";
}

include ('includes/footer.php');
?>

Link to comment
Share on other sites

$users_age=strpos('profile.php',$age); if($age<18||$users_age>18)

If profile.php is a script, it's very likely not going to have a user's age embedded within it.

 

Anyways, you're telling PHP to look for whatever is in $age within the string 'profile.php'.

 

In all likelihood you want to pull each person's age from the database and compare them, and that is only if they are not contained within memory already.

Link to comment
Share on other sites

how would i find the difference with just the age variable? ???

 

Say you had a database with all users in it, you'd have username, name, surname, title etc.. you'd also have an age column. Then pull from the database the age from the person doing the adding (user1) and that of the person being added (user2).

 

So something like

if($user1_age>18 && $user2_age<18) {
echo "You can't add a user under 18 for legal reasons!";
}

Something like that.

 

Although, you might want to refine your ages.. at the moment a 19 year old can't add a 17 year old. That's not anything dodgy at all. :P and it limits people.

 

this

 

if($user1_age>25 && $user2_age<16) {
echo "You can't add a user under 16 for legal reasons!";
}

 

would probably be better.

 

Sam

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.