Jump to content

Not working right


topflight

Recommended Posts

This code I have is suppose to check the member list in the hub field and assign the new member a login id depending on what their hub is +1 well it works for all the other hubs but when the user selects the KSEA then it assigns it a KPDX hub id please help. This is my code:

 

<?php
$plist = mysql_query("SELECT * FROM `members` WHERE hub='$_POST[hub]' ORDER BY login DESC LIMIT 1") or die(mysql_error());
$plrows = mysql_num_rows($plist);
if ($plrows=="0"){ 
if ($_POST[hub]=="KSEA"){ $login = "1000"; }
if ($_POST[hub]=="KLAX"){ $login = "2000"; }
if ($_POST[hub]=="KPDX"){ $login = "3000"; }
if ($_POST[hub]=="PANC"){ $login = "4000"; }} else {

while($plr = mysql_fetch_array($plist)){ $login = $plr[login]; } $login = $login + 1; }
?>

 

Also this is the part of the form that contains the hub part.

 

     

      <select name="hub">
              <option>- SELECT A HUB -</option>
              <option value="KPDX">Portland</option>
              <option value="KSEA">Seattle</option>
              <option value="KLAX">Los Angeles</option>
              <option value="PANC">Anchorage</option>
            </select>

 

thanks in advanced!

Link to comment
https://forums.phpfreaks.com/topic/152931-not-working-right/
Share on other sites

try this...

<?php
$plist = mysql_query("SELECT * FROM `members` WHERE hub='".$_POST['hub']."' ORDER BY login DESC LIMIT 1") or die(mysql_error());
$plrows = mysql_num_rows($plist);
if ($plrows=="0") { 
if ($_POST['hub']=="KSEA"){ $login = "1000"; }
elseif ($_POST['hub']=="KLAX"){ $login = "2000"; }
elseif ($_POST['hub']=="KPDX"){ $login = "3000"; }
elseif ($_POST['hub']=="PANC"){ $login = "4000"; }
} else {
while($plr = mysql_fetch_array($plist))
{ 
$login = $plr['login']; 
} 
$login = $login + 1; 
}
?>

 

Regards, ACE

Link to comment
https://forums.phpfreaks.com/topic/152931-not-working-right/#findComment-803187
Share on other sites

Have a play with this and see how it goes. I've added 3 lines showing some debug info so you can see exactly what data is being returned and where.

<?php
$plist = mysql_query("SELECT * FROM `members` WHERE hub='".$_POST['hub']."' ORDER BY login DESC LIMIT 1") or die(mysql_error());
$plrows = mysql_num_rows($plist);
//DEBUG DATA TO SEE WHAT WE'RE PLAYING WITH
echo 'rows='.$plrows.'<br>';
echo 'POST='.$_POST['hub'].'<br>';
if ($plrows=="0") {
  switch ($_POST['hub']) {
    case 'KSEA':$login='1000';break;
    case 'KLAX':$login='2000';break;
    case 'KPDX':$login='3000';break;
    case 'PANC':$login='4000';break;
    default:
      while ($plr=mysql_fetch_array($plist)) {
        $login=$plr['login']; 
      }
      $login++;
  }
}
echo 'login='.$login.'<br>';
?>

Link to comment
https://forums.phpfreaks.com/topic/152931-not-working-right/#findComment-803216
Share on other sites

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.