New Posts  All Forums:Forum Nav:

PHP if Statments

post #1 of 15
Thread Starter 
Okay, I made up this test script to test out a form's result and I'm having troubles.
Quote:
<?php
$source = $_POST['type'];
if ($source = book)
{
print "awesome";
}
elseif ($source = mbook)
{
print "cute";
}
elseif ($source = rbook)
{
print "nice";
}
elseif ($source = volume)
{
print "splendid";
}
elseif ($source = mag)
{
print "buen";
}
elseif ($source = web)
{
print "party";
}
elseif ($source = song)
{
print "joy";
}
?>
No matter what option I fill out it only gives me the first "if" statement. Running only...
Code:
echo "$source";
I'm able to see that it does change. Therefore, I know it's my if statements that are screwy. Any suggestions?
EDIT: THIS is the form that I'm recieving $_POST['type'] from.
    
CPUMotherboardGraphicsRAM
9950 Phenom 140w @ 3ghz Foxconn A7DA-S ASUS TOP 4850 Mushkin 4gb (2x2gb) DDR2-800 
Hard DriveOptical DriveOSMonitor
500GB WD, 500GB Hit, & 320GB Seagate LG DVD-RW Win7 x64 and Gentoo x64 Hanns-G 22" & Acer 19" 
KeyboardPowerCaseMouse
Logitech G15 Gaming Keyboard Ultra X2 750-Watt Antec 300 Logitech MX518 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
9950 Phenom 140w @ 3ghz Foxconn A7DA-S ASUS TOP 4850 Mushkin 4gb (2x2gb) DDR2-800 
Hard DriveOptical DriveOSMonitor
500GB WD, 500GB Hit, & 320GB Seagate LG DVD-RW Win7 x64 and Gentoo x64 Hanns-G 22" & Acer 19" 
KeyboardPowerCaseMouse
Logitech G15 Gaming Keyboard Ultra X2 750-Watt Antec 300 Logitech MX518 
  hide details  
Reply
post #2 of 15
Thread Starter 
Nevermind, I ended up fixing it by changing several things. For those that may run into a similar problem, here is the new revision...
Quote:
<?php
$source = $_POST['type'];
if ($source == "book")
{
print "awesome";
}
elseif ($source == "mbook")
{
print "cute";
}
elseif ($source == "rbook")
{
print "nice";
}
elseif ($source == "volume")
{
print "splendid";
}
elseif ($source == "mag")
{
print "buen";
}
elseif ($source == "web")
{
print "party";
}
elseif ($source == "song")
{
print "joy";
}
?>
    
CPUMotherboardGraphicsRAM
9950 Phenom 140w @ 3ghz Foxconn A7DA-S ASUS TOP 4850 Mushkin 4gb (2x2gb) DDR2-800 
Hard DriveOptical DriveOSMonitor
500GB WD, 500GB Hit, & 320GB Seagate LG DVD-RW Win7 x64 and Gentoo x64 Hanns-G 22" & Acer 19" 
KeyboardPowerCaseMouse
Logitech G15 Gaming Keyboard Ultra X2 750-Watt Antec 300 Logitech MX518 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
9950 Phenom 140w @ 3ghz Foxconn A7DA-S ASUS TOP 4850 Mushkin 4gb (2x2gb) DDR2-800 
Hard DriveOptical DriveOSMonitor
500GB WD, 500GB Hit, & 320GB Seagate LG DVD-RW Win7 x64 and Gentoo x64 Hanns-G 22" & Acer 19" 
KeyboardPowerCaseMouse
Logitech G15 Gaming Keyboard Ultra X2 750-Watt Antec 300 Logitech MX518 
  hide details  
Reply
post #3 of 15
Yeah. Gotta watch out for those double equal signs.

Don't ask me why you need to do it that way. I never understood why.
 
Server
(3 items)
 
 
CPUGraphicsRAMHard Drive
Intel Core i7-3540M Intel HD Graphics 4000 8GB G.SKILL Ripjaws DDR3 1600 Samsung 840 EVO 250GB SSD 
OSMonitorMouseAudio
Windows 10 Pro x64 14" at 1600x900 Logitech Anywhere Mouse MX FiiO E17 USB DAC amp 
CPUOSCase
i3-540 Debian 8 (Jessie) Cooler Master Elite 341 
  hide details  
Reply
 
Server
(3 items)
 
 
CPUGraphicsRAMHard Drive
Intel Core i7-3540M Intel HD Graphics 4000 8GB G.SKILL Ripjaws DDR3 1600 Samsung 840 EVO 250GB SSD 
OSMonitorMouseAudio
Windows 10 Pro x64 14" at 1600x900 Logitech Anywhere Mouse MX FiiO E17 USB DAC amp 
CPUOSCase
i3-540 Debian 8 (Jessie) Cooler Master Elite 341 
  hide details  
Reply
post #4 of 15
Because a single = is an assignment operator, not a comparison operator, parsers can't generally decide ambiguity (should this = be an assignment or a compare?) easily
Monster v2
(13 items)
 
  
CPUMotherboardGraphicsRAM
Q6600 G0 GA-P35-DS3L HD 4850 6GB Crucial Ballistix 
Hard DriveOSMonitorKeyboard
WD 320GB Windows 7 Ultimate (64bit) 2x Acer 22" WS Logitech g15 
PowerCaseMouse
OCZ 700W Gigabyte 3D aurora Logitech Mx510 
  hide details  
Reply
Monster v2
(13 items)
 
  
CPUMotherboardGraphicsRAM
Q6600 G0 GA-P35-DS3L HD 4850 6GB Crucial Ballistix 
Hard DriveOSMonitorKeyboard
WD 320GB Windows 7 Ultimate (64bit) 2x Acer 22" WS Logitech g15 
PowerCaseMouse
OCZ 700W Gigabyte 3D aurora Logitech Mx510 
  hide details  
Reply
post #5 of 15
Code:

<?php
switch($_POST['type'])
{
    case 'book':
        echo 'awesome';
        break;
    case 'mbook':
        echo 'cute';
        break;
    case 'rbook':
        echo 'nice'
        break;
    case 'volume':
        echo 'splendid';
        break;
    case 'mag':
        echo 'buen';
        break;
    case 'web':
        echo 'party';
        break;
    case 'song':
        echo 'joy';
        break;
    default:
        echo 'invalid';
        break;
}
?>
Powered By Xeon
(15 items)
 
Dragon
(13 items)
 
Reborn
(13 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon X3320 (45nm Quad) ASUS Maximus "Rampage" Formula SE HIS HD 4850 IceQ 4 Turbo Crucial Ballistix Tracer DDR2 
Hard DriveOptical DriveCoolingOS
WD Raptor + WD Caviar SE16 (x2) ASUS 2014L1T 20x DVD-RW Thermalright Ultima-90 Windows 8 Pro 
MonitorKeyboardPowerCase
Samsung 226BW Logitech diNovo Keyboard Corsair HX-620 Cooler Master RC-690 
MouseAudio
Microsoft Touch Mouse Logitech G51 (5.1 Surround) 
CPUMotherboardGraphicsRAM
Intel Pentium Dual-Core E2160 Gigabyte G41MT-ES2L Intel GMA X4500 G.Skill NQ DDR3 
Hard DriveOptical DriveOSPower
Western Digital + Seagate Barracuda Green (x2) Lite-On DVD-RW FreeBSD 9.0 SHAW 680W 
CPUMotherboardGraphicsRAM
Intel Pentium 4 w/HT (Northwood) Gigabyte 8S655FX-L ATI Radeon 9800 Pro OCZ Gold DDR 
Hard DriveOptical DriveOSMonitor
Toshiba IDE Pioneer DVD-RW DVR-109 Linux Mint 12 Viewsonic 15" VA520 
KeyboardPowerMouse
Microsoft Wireless Desktop Elite Generic 450W Microsoft Wireless IntelliMouse Explorer 2.0 
  hide details  
Reply
Powered By Xeon
(15 items)
 
Dragon
(13 items)
 
Reborn
(13 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon X3320 (45nm Quad) ASUS Maximus "Rampage" Formula SE HIS HD 4850 IceQ 4 Turbo Crucial Ballistix Tracer DDR2 
Hard DriveOptical DriveCoolingOS
WD Raptor + WD Caviar SE16 (x2) ASUS 2014L1T 20x DVD-RW Thermalright Ultima-90 Windows 8 Pro 
MonitorKeyboardPowerCase
Samsung 226BW Logitech diNovo Keyboard Corsair HX-620 Cooler Master RC-690 
MouseAudio
Microsoft Touch Mouse Logitech G51 (5.1 Surround) 
CPUMotherboardGraphicsRAM
Intel Pentium Dual-Core E2160 Gigabyte G41MT-ES2L Intel GMA X4500 G.Skill NQ DDR3 
Hard DriveOptical DriveOSPower
Western Digital + Seagate Barracuda Green (x2) Lite-On DVD-RW FreeBSD 9.0 SHAW 680W 
CPUMotherboardGraphicsRAM
Intel Pentium 4 w/HT (Northwood) Gigabyte 8S655FX-L ATI Radeon 9800 Pro OCZ Gold DDR 
Hard DriveOptical DriveOSMonitor
Toshiba IDE Pioneer DVD-RW DVR-109 Linux Mint 12 Viewsonic 15" VA520 
KeyboardPowerMouse
Microsoft Wireless Desktop Elite Generic 450W Microsoft Wireless IntelliMouse Explorer 2.0 
  hide details  
Reply
post #6 of 15
You could just add <?= not <?php its much easier.
post #7 of 15
Quote:
Originally Posted by onlycodered View Post
Yeah. Gotta watch out for those double equal signs.

Don't ask me why you need to do it that way. I never understood why.
Because that's the way god intended it! Visual Basic was made by the devil.
RAWR
(13 items)
 
Home Server
(11 items)
 
 
CPUMotherboardGraphicsRAM
i7-4790k msi z97 gaming 7 gtx 760 4gb 32GB GSkill  
Hard DriveHard DriveCoolingOS
Kingston HyperX 3K 120GB SSD Hitachi 2TB Cooler Master Hyper 212+ Windows 8.1 Pro 
MonitorKeyboardPowerCase
Vizio M492-b2 Logitech Wireless  Corsair HX620 NZXT Phantom White 
Mouse
Logitech Wireless 
  hide details  
Reply
RAWR
(13 items)
 
Home Server
(11 items)
 
 
CPUMotherboardGraphicsRAM
i7-4790k msi z97 gaming 7 gtx 760 4gb 32GB GSkill  
Hard DriveHard DriveCoolingOS
Kingston HyperX 3K 120GB SSD Hitachi 2TB Cooler Master Hyper 212+ Windows 8.1 Pro 
MonitorKeyboardPowerCase
Vizio M492-b2 Logitech Wireless  Corsair HX620 NZXT Phantom White 
Mouse
Logitech Wireless 
  hide details  
Reply
post #8 of 15
Quote:
Originally Posted by hometoast View Post
Because that's the way god intended it! Visual Basic was made by the devil.
When did we start talking about Visual Basic?
 
Server
(3 items)
 
 
CPUGraphicsRAMHard Drive
Intel Core i7-3540M Intel HD Graphics 4000 8GB G.SKILL Ripjaws DDR3 1600 Samsung 840 EVO 250GB SSD 
OSMonitorMouseAudio
Windows 10 Pro x64 14" at 1600x900 Logitech Anywhere Mouse MX FiiO E17 USB DAC amp 
CPUOSCase
i3-540 Debian 8 (Jessie) Cooler Master Elite 341 
  hide details  
Reply
 
Server
(3 items)
 
 
CPUGraphicsRAMHard Drive
Intel Core i7-3540M Intel HD Graphics 4000 8GB G.SKILL Ripjaws DDR3 1600 Samsung 840 EVO 250GB SSD 
OSMonitorMouseAudio
Windows 10 Pro x64 14" at 1600x900 Logitech Anywhere Mouse MX FiiO E17 USB DAC amp 
CPUOSCase
i3-540 Debian 8 (Jessie) Cooler Master Elite 341 
  hide details  
Reply
post #9 of 15
Quote:
Originally Posted by wolf_08 View Post
You could just add <?= not <?php its much easier.
I, personally, prefer to use the full notation. It just seems more specific. If you prefer typing less, you can always make an editor auto-complete it. Maybe it is just me.
Shinobu
(16 items)
 
Nodoka
(16 items)
 
Index
(4 items)
 
CPUMotherboardGraphicsRAM
Intel Core i5-3570K Asus P8Z77-I Deluxe HD6450 Flex Crucial 16GB (2x 8GB) Ballistix Elite 
Hard DriveHard DriveOSMonitor
Samsung SSD 840 EVO 250GB TOSHIBA DT01ACA300 Arch Linux Dell UltraSharp U2713HM 
MonitorMonitorKeyboardPower
Dell U2410 Dell 2407WFP Cherry - Cherry Blue Switches (Unlabeled keys) Seasonic X-650 
CaseMouseAudioAudio
BitFenix Prodigy Black Logitech M570 Trackball Sennheiser HD595 Creative GigaWorks T20 
CPUMotherboardGraphicsRAM
Intel Core i5 3570K Zotac Z77-ITX WiFi EVGA 680 GTX Samsung 
Hard DriveHard DriveOSMonitor
Samsung 256GB 830 Samsung SpinPoint HD501LJ Windows 7 Dell U2410 
MonitorMonitorKeyboardCase
Dell 2407WFP Dell E248WFP Cherry Black (MX Blue Switches, Blank Keys) Silverstone Sugi SG08B 
MouseAudioAudio
Logitech Trackman Logitech Z-5500 Sennheiser HD595s 
CPUMotherboardRAMHard Drive
AMD Athlon II X2 240e Asus M5A78L-M/USB3 Crucial 8GB (2x4GB) DDR3 1600Mhz Ballistix Sport 1.5TB Hard Drives 
  hide details  
Reply
Shinobu
(16 items)
 
Nodoka
(16 items)
 
Index
(4 items)
 
CPUMotherboardGraphicsRAM
Intel Core i5-3570K Asus P8Z77-I Deluxe HD6450 Flex Crucial 16GB (2x 8GB) Ballistix Elite 
Hard DriveHard DriveOSMonitor
Samsung SSD 840 EVO 250GB TOSHIBA DT01ACA300 Arch Linux Dell UltraSharp U2713HM 
MonitorMonitorKeyboardPower
Dell U2410 Dell 2407WFP Cherry - Cherry Blue Switches (Unlabeled keys) Seasonic X-650 
CaseMouseAudioAudio
BitFenix Prodigy Black Logitech M570 Trackball Sennheiser HD595 Creative GigaWorks T20 
CPUMotherboardGraphicsRAM
Intel Core i5 3570K Zotac Z77-ITX WiFi EVGA 680 GTX Samsung 
Hard DriveHard DriveOSMonitor
Samsung 256GB 830 Samsung SpinPoint HD501LJ Windows 7 Dell U2410 
MonitorMonitorKeyboardCase
Dell 2407WFP Dell E248WFP Cherry Black (MX Blue Switches, Blank Keys) Silverstone Sugi SG08B 
MouseAudioAudio
Logitech Trackman Logitech Z-5500 Sennheiser HD595s 
CPUMotherboardRAMHard Drive
AMD Athlon II X2 240e Asus M5A78L-M/USB3 Crucial 8GB (2x4GB) DDR3 1600Mhz Ballistix Sport 1.5TB Hard Drives 
  hide details  
Reply
post #10 of 15
Quote:
Originally Posted by lattyware View Post
I, personally, prefer to use the full notation. It just seems more specific. If you prefer typing less, you can always make an editor auto-complete it. Maybe it is just me.
Yeah, I've always tried to avoid shorthand as well. Sometimes it can screw things up.
 
Server
(3 items)
 
 
CPUGraphicsRAMHard Drive
Intel Core i7-3540M Intel HD Graphics 4000 8GB G.SKILL Ripjaws DDR3 1600 Samsung 840 EVO 250GB SSD 
OSMonitorMouseAudio
Windows 10 Pro x64 14" at 1600x900 Logitech Anywhere Mouse MX FiiO E17 USB DAC amp 
CPUOSCase
i3-540 Debian 8 (Jessie) Cooler Master Elite 341 
  hide details  
Reply
 
Server
(3 items)
 
 
CPUGraphicsRAMHard Drive
Intel Core i7-3540M Intel HD Graphics 4000 8GB G.SKILL Ripjaws DDR3 1600 Samsung 840 EVO 250GB SSD 
OSMonitorMouseAudio
Windows 10 Pro x64 14" at 1600x900 Logitech Anywhere Mouse MX FiiO E17 USB DAC amp 
CPUOSCase
i3-540 Debian 8 (Jessie) Cooler Master Elite 341 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Web Coding