If Else statement broken

Hi everyone,
So I’m having issues trying to get two of my If, else statements to work.
So they take an input from an html submit form, and if there is an input the code works, but for this there needs to be all the values in the database returned if there is nothing submitted. It’s as if php doesn’t even recognize the if part and only runs the else part.

Any guidance is highly appreciated! Thanks 8)

here’s the code for the 1st:

[php]$lastName = $_POST[‘lastName’];

if ($lastName = “”) {
$query = "SELECT c., s.speaker_year FROM Contact c, Speakers s WHERE s.Contact_con_id = c.con_id ";
} Else {
$query = "SELECT c.
, s.speaker_year FROM Contact c, Speakers s WHERE s.Contact_con_id = c.con_id
AND con_lname = ";
}
$query = $query . “’” . $lastName . “’ ORDER BY con_lname;”;[/php]

here’s the 2nd one:

[php]$rgroups = $_POST[‘rgroups’];

if ($_Post[‘rgroups’] = “”) {
$query6 = "SELECT r.rev_groups_id, c.con_fname, c.con_lname, con_phone, rev_groups_pass, count(p.proposal_id)
FROM Review_Groups r JOIN Proposal p on r.rev_groups_id = p.Review_Groups_rev_groups_id
JOIN Presents px on px.Proposal_proposal_id = p.proposal_id
JOIN Contact c on px.Speakers_Contact_con_id = c.con_id
JOIN Reviewer rw on rw.Review_Groups_rev_groups_id = r.rev_groups_id
WHERE rw.reviewer_type = ‘local’
AND r.rev_groups_id = ";
$query6 = $query6 . “’” . $rgroups . “’ Group BY r.rev_groups_id;”;}
Else {
$query6 = "SELECT r.rev_groups_id, c.con_fname, c.con_lname, con_phone, rev_groups_pass, count(p.proposal_id)
FROM Review_Groups r JOIN Proposal p on r.rev_groups_id = p.Review_Groups_rev_groups_id
JOIN Presents px on px.Proposal_proposal_id = p.proposal_id
JOIN Contact c on px.Speakers_Contact_con_id = c.con_id
JOIN Reviewer rw on rw.Review_Groups_rev_groups_id = r.rev_groups_id
WHERE rw.reviewer_type = ‘local’
AND r.rev_groups_id = ";

$query6 = $query6 . “’” . $rgroups . "’ ";}
[/php]

When making a comparison you need to use two equals signs.

[php]$var1 = $var2 //Sets $var1 to the value of $var2[/php]

[php]$var1 == $var2 //Returns whether or not $var1 has the same value as $var2[/php]

Ah I see, yea i was doing more research and was able to change up my code. Now it’s

[php]$rgroups = isset($_POST[‘rgroups’]) ? $_POST[‘rgroups’] : NULL;
$rgroups = mysql_real_escape_string($rgroups);

$query6 = “SELECT r.rev_groups_id, c.con_fname, c.con_lname, con_phone, rev_groups_pass, count(p.proposal_id)
FROM Review_Groups r JOIN Proposal p on r.rev_groups_id = p.Review_Groups_rev_groups_id
JOIN Presents px on px.Proposal_proposal_id = p.proposal_id
JOIN Contact c on px.Speakers_Contact_con_id = c.con_id
JOIN Reviewer rw on rw.Review_Groups_rev_groups_id = r.rev_groups_id
WHERE rw.reviewer_type = ‘local’
AND r.rev_groups_id = '” . $rgroups . "’ ";

if ($rgroups == NULL) {
$query6 .= " AND r.rev_groups_id = ‘" . $rgroups . "’ Group BY r.rev_groups_id;";
}
[/php]

However I still get nothing back when I submit blank. even if i change the nulls to “” it still doesnt work. But it does work when i submit a value

Ok i got the statement fixed. the final code for this is (for those who may have issues)

[php]
$rgroups = isset($_POST[‘rgroups’]) ? $_POST[‘rgroups’] : “”;
$rgroups = mysql_real_escape_string($rgroups);

$query6 = “SELECT r.rev_groups_id, c.con_fname, c.con_lname, c.con_phone, r.rev_groups_pass, count(p.proposal_id)
FROM Review_Groups r JOIN Proposal p on r.rev_groups_id = p.Review_Groups_rev_groups_id
JOIN Presents px on px.Proposal_proposal_id = p.proposal_id
JOIN Contact c on px.Speakers_Contact_con_id = c.con_id
JOIN Reviewer rw on rw.Review_Groups_rev_groups_id = r.rev_groups_id
WHERE rw.reviewer_type = ‘Local’”;

if ($rgroups == “”) {
$query6 .= " Group BY r.rev_groups_id;";
}
Else {
$query6 .=“AND r.rev_groups_id = '” . $rgroups . “’”;
}[/php]

my next problem is that this if else prints even if i dont click this specific submit button. this is related to my other thread (http://www.phphelp.com/forum/index.php/topic,14578.0.html)

So if anyone has any help for this issue can you reply to that thread?

Thanks

Also, not sure how to resolve posts, but this one is if a mod wants to take care of that for me

;D 8)

try using
[php]
if (!$rgroups) {…
[/php]
i had that problem before when using NULL to check if the query returns false.

Sponsor our Newsletter | Privacy Policy | Terms of Service