Jump to content

I'm really stuck and dont understand :(


Accurax

Recommended Posts

I'm really struggleing to get my head around this, and im getting annoyed at myself for not being able to figure it out.

 

Here is my complete script, it should take 4 values from a form sex, location minimum age and maximum age.

 

It should then access my database and display all my members who satisfy all critera and are between minimum and maximum age's supplied.

 

here is my complete code as it stands .... at the mometn it just loads a blank page, no error codes or output of any kind, and its got me stumped.

 

<?php
//connect to database here

$sex = $_POST['search_sex'];
$loc = $_POST['search_location'];
$min_age = $_POST['search_age2'];
$max_age = $_POST['search_age1'];

$user_query = "SELECT * FROM members m INNER JOIN pictures p ON p.user_name = m.user_name WHERE sex='$sex' AND location='$loc' ORDER BY last_updated DESC";
$result = mysql_query($user_query)
or die ("no can do");

$today = date('d-m-Y');

$a_today = explode('-', $today);

$day_today = $a_today[0];
$month_today = $a_today[1];
$year_today = $a_today[2];


while ( $row = mysql_fetch_array($result))
{
//calculates the age
$day = $row['day'];
$month = $row['month'];
$year = $row['year'];

$birthday = $day."-".$month."-".$year;

$a_birthday = explode('-', $birthday);

$day_birthday = $a_birthday[0];
$month_birthday = $a_birthday[1];
$year_birthday = $a_birthday[2];

$age = $year_today - $year_birthday;

if (($month_today < $month_birthday) || ($month_today == $month_birthday && $day_today < $day_birthday))
{
$age--;
}

   if (($age >=$min_age) && ($age <= $max_age)) {
      $members [] = $row;


   foreach ($members as $key => $value) 

       print $value['user_name'];


}
}

?>

 

Ive been reading through tutorials on handleing arrays, but nothing seems to make sense with respect to this, so every bit of help is really honestly appreciated here.

Link to comment
https://forums.phpfreaks.com/topic/42504-im-really-stuck-and-dont-understand/
Share on other sites

Still no error message's being thrown out at all code updateed below;

 

<?php
error_reporting(255);

//connect to database here

$sex = $_POST['search_sex'];
$loc = $_POST['search_location'];
$min_age = $_POST['search_age2'];
$max_age = $_POST['search_age1'];

$user_query = "SELECT * FROM members m INNER JOIN pictures p ON p.user_name = m.user_name WHERE sex='$sex' AND location='$loc' ORDER BY last_updated DESC";
$result = mysql_query($user_query)
or die ("no can do");

$today = date('d-m-Y');

$a_today = explode('-', $today);

$day_today = $a_today[0];
$month_today = $a_today[1];
$year_today = $a_today[2];


while ( $row = mysql_fetch_array($result))
{
//calculates the age
$day = $row['day'];
$month = $row['month'];
$year = $row['year'];

$birthday = $day."-".$month."-".$year;

$a_birthday = explode('-', $birthday);

$day_birthday = $a_birthday[0];
$month_birthday = $a_birthday[1];
$year_birthday = $a_birthday[2];

$age = $year_today - $year_birthday;

if (($month_today < $month_birthday) || ($month_today == $month_birthday && $day_today < $day_birthday))
{
$age--;
}

   if (($age >=$min_age) && ($age <= $max_age)) {
      $members [] = $row;


   foreach ($members as $key => $value) 

       print $value['user_name'];


}
}

?>

try escaping the string like:

<?php
        $user_query = "SELECT * FROM members m 
                             INNER JOIN pictures p 
                             ON p.user_name = m.user_name 
                             WHERE sex = '". $sex ."' AND location = '". $loc ."'
                             ORDER BY last_updated DESC";
?>

 

I would suggest you echo the 'today' dates and the 'birthday' dates and see why they aren't matching up. Sometimes odd things can happen when you treat a text string (such as '01') as a number. One thing for certain, theres nothing wrong with PHP, only with the way you are using it (thats what I always tell myself when I have a problem) so you need to pin down the problem by getting as much information as you can - and that means echo, echo, echo. Don't despair - the answer is waiting for you to find it!

i just escaped the string to make sure the value of the variables was being printed. i only put it on separate lines to help diagnose the query if it returned a mysql_error().

 

it could be that your table columns are int values and your $_POST variables are strings, and somethings not picking up in between. can you show a short diagram of your two tables?

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.