Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › PHP/MySQL questions from a beginner
New Posts  All Forums:Forum Nav:

PHP/MySQL questions from a beginner

post #1 of 10
Thread Starter 

Hey,

 

So I can set up LAMP servers, but don't actually know much about writing PHP and have been trying to learn some basics. I've managed to create MySQL databases, tables, add entries with a form, view entries in a HTML table and such.

 

I can also delete entries but with my newbie-ness it requires modifying the file for each entry I want to delete. I was wondering if anyone has some pointers on how I would go about making a still basic but more user friendly version that perhaps even allows just entering a value into a form that takes that value, substitutes it into the delete file, and performs the delete. The site i've found most useful so far is w3schools so i'm currently just imitating and modifying the guides on there for my needs.

 

I guess the way I should go about it is make a HTML form that defines the action to take once the value has been submitted, then the defined action file (my delete file) should subtitute that value in?

 

Besides the other required stuff, can I just take what it would say after name=?

name=something

(in the HTML file)

 

and do

 

DELETE FROM columnname WHERE fieldname="something"

(in the delete PHP file)

 

to get that value the user inserted into the form, over into my delete file?

 

Thanks for reading!


Edited by Sainesk - 1/10/14 at 9:01pm
Winter Heater
(9 items)
 
 
HTPC
(9 items)
 
CPUMotherboardGraphicsRAM
i7 2600K GIGABYTE GA-H61M-S1 Galaxy GTX 460 768MB Corsair XMS3 DDR3 1333 2x4GB 
Hard DriveHard DriveCoolingPower
64GB ADATA S596 Turbo SSD WD Green 1TB Antec Kuhler H2O 620 IN WIN Commander 650W 
Case
COOLER MASTER RC-690 
CPUMotherboardGraphicsRAM
Phenom II X6 1055T  ASUS M4A87TD EVO XFX Radeon HD 5850 1GB AMD Performance Edition DDR3 1333 2X2GB  
Hard DriveHard DriveCoolingPower
32GB ADATA S596 Turbo SSD WD Blue 500GB Scythe Mugen 2 Rev. B OCZ Fatal1ty 550W  
Case
COOLER MASTER HAF 932 
CPUMotherboardGraphicsRAM
Athlon II x2 240 ASROCK M3A770DE POWERCOLOR HD 4850 1GB G.SKILL F3 DDR3 1600 2x2GB 
Hard DriveHard DriveCoolingPower
32GB Adata S596 Turbo SSD SAMSUNG Spinpoint F3 1TB Scythe Big Shuriken 2 rev. B Cooler Master Elite Power 460W 
Case
COOLER MASTER Elite 360 
  hide details  
Reply
Winter Heater
(9 items)
 
 
HTPC
(9 items)
 
CPUMotherboardGraphicsRAM
i7 2600K GIGABYTE GA-H61M-S1 Galaxy GTX 460 768MB Corsair XMS3 DDR3 1333 2x4GB 
Hard DriveHard DriveCoolingPower
64GB ADATA S596 Turbo SSD WD Green 1TB Antec Kuhler H2O 620 IN WIN Commander 650W 
Case
COOLER MASTER RC-690 
CPUMotherboardGraphicsRAM
Phenom II X6 1055T  ASUS M4A87TD EVO XFX Radeon HD 5850 1GB AMD Performance Edition DDR3 1333 2X2GB  
Hard DriveHard DriveCoolingPower
32GB ADATA S596 Turbo SSD WD Blue 500GB Scythe Mugen 2 Rev. B OCZ Fatal1ty 550W  
Case
COOLER MASTER HAF 932 
CPUMotherboardGraphicsRAM
Athlon II x2 240 ASROCK M3A770DE POWERCOLOR HD 4850 1GB G.SKILL F3 DDR3 1600 2x2GB 
Hard DriveHard DriveCoolingPower
32GB Adata S596 Turbo SSD SAMSUNG Spinpoint F3 1TB Scythe Big Shuriken 2 rev. B Cooler Master Elite Power 460W 
Case
COOLER MASTER Elite 360 
  hide details  
Reply
post #2 of 10
How do you usually manage the database?

The easiest way will probably to use a PHP library for it.

Mysqli:
http://php.net/mysqli

Read up on SQL injection too, never parse user input directly without sanitizing it first, no matter how trivial you think it is smile.gif

Use a form submit rather than a redirect on a button. Here's why.
#well
(19 items)
 
Lenovo L530
(8 items)
 
 
CPUMotherboardGraphicsRAM
Intel Core i7 4770k Gigabyte Z87X-UD4H XFX Radeon HD 6950 Corsair CMX8GX3M2A2000C9 
Hard DriveHard DriveOptical DriveCooling
Samsung EVO 840 Hitachi HDS722020ALA330 Generic DVD±RW Burner Noctua NH-D14 
OSMonitorMonitorKeyboard
Windows 8.1 Dell U2711 LG W2453 Ducky DK9008 Overclock.net Edition, Cherry MX B... 
PowerCaseMouseMouse Pad
Corsair TX850 Antec Three Hundred Corsair Raptor M40 QPAD HeatoN M 
AudioAudioAudio
E-MU Tracker|pre Beyerdynamic DT-770 250 Ohm AntLion ModMIc 
CPUGraphicsRAMRAM
Intel Ivy Bridge 3210M Intel HD 4000 Graphics Soldered Corsair Vengeance  
Hard DriveOptical DriveOSMonitor
500GB DVD-+RW Windows 7 Professional 1600x900 
  hide details  
Reply
#well
(19 items)
 
Lenovo L530
(8 items)
 
 
CPUMotherboardGraphicsRAM
Intel Core i7 4770k Gigabyte Z87X-UD4H XFX Radeon HD 6950 Corsair CMX8GX3M2A2000C9 
Hard DriveHard DriveOptical DriveCooling
Samsung EVO 840 Hitachi HDS722020ALA330 Generic DVD±RW Burner Noctua NH-D14 
OSMonitorMonitorKeyboard
Windows 8.1 Dell U2711 LG W2453 Ducky DK9008 Overclock.net Edition, Cherry MX B... 
PowerCaseMouseMouse Pad
Corsair TX850 Antec Three Hundred Corsair Raptor M40 QPAD HeatoN M 
AudioAudioAudio
E-MU Tracker|pre Beyerdynamic DT-770 250 Ohm AntLion ModMIc 
CPUGraphicsRAMRAM
Intel Ivy Bridge 3210M Intel HD 4000 Graphics Soldered Corsair Vengeance  
Hard DriveOptical DriveOSMonitor
500GB DVD-+RW Windows 7 Professional 1600x900 
  hide details  
Reply
post #3 of 10
Thread Starter 
Quote:
Originally Posted by gonX View Post

How do you usually manage the database?

The easiest way will probably to use a PHP library for it.

Mysqli:
http://php.net/mysqli

Read up on SQL injection too, never parse user input directly without sanitizing it first, no matter how trivial you think it is smile.gif

Use a form submit rather than a redirect on a button. Here's why.

 

I wouldn't say i've really even managed them yet but I've used phpMyAdmin and MariaDB very few times, not yet on my current database though I plan to experiment with it. Also use webmin but don't know if that really counts... :o

 

Thanks for the reply i'll read up on those, and yeah I know about SQL injections and for that reason the VM i'm doing this on is isolated on my LAN, and I wouldn't allow access to it from outside of my LAN with my current knowledge level. My VM contains nothing important, just experimental stuff, so even if someone on my LAN or myself messed it up, it would be a learning experience (+I take snapshots so hopefully I can just restore to a previous point in time).


Edited by Sainesk - 1/11/14 at 7:33am
Winter Heater
(9 items)
 
 
HTPC
(9 items)
 
CPUMotherboardGraphicsRAM
i7 2600K GIGABYTE GA-H61M-S1 Galaxy GTX 460 768MB Corsair XMS3 DDR3 1333 2x4GB 
Hard DriveHard DriveCoolingPower
64GB ADATA S596 Turbo SSD WD Green 1TB Antec Kuhler H2O 620 IN WIN Commander 650W 
Case
COOLER MASTER RC-690 
CPUMotherboardGraphicsRAM
Phenom II X6 1055T  ASUS M4A87TD EVO XFX Radeon HD 5850 1GB AMD Performance Edition DDR3 1333 2X2GB  
Hard DriveHard DriveCoolingPower
32GB ADATA S596 Turbo SSD WD Blue 500GB Scythe Mugen 2 Rev. B OCZ Fatal1ty 550W  
Case
COOLER MASTER HAF 932 
CPUMotherboardGraphicsRAM
Athlon II x2 240 ASROCK M3A770DE POWERCOLOR HD 4850 1GB G.SKILL F3 DDR3 1600 2x2GB 
Hard DriveHard DriveCoolingPower
32GB Adata S596 Turbo SSD SAMSUNG Spinpoint F3 1TB Scythe Big Shuriken 2 rev. B Cooler Master Elite Power 460W 
Case
COOLER MASTER Elite 360 
  hide details  
Reply
Winter Heater
(9 items)
 
 
HTPC
(9 items)
 
CPUMotherboardGraphicsRAM
i7 2600K GIGABYTE GA-H61M-S1 Galaxy GTX 460 768MB Corsair XMS3 DDR3 1333 2x4GB 
Hard DriveHard DriveCoolingPower
64GB ADATA S596 Turbo SSD WD Green 1TB Antec Kuhler H2O 620 IN WIN Commander 650W 
Case
COOLER MASTER RC-690 
CPUMotherboardGraphicsRAM
Phenom II X6 1055T  ASUS M4A87TD EVO XFX Radeon HD 5850 1GB AMD Performance Edition DDR3 1333 2X2GB  
Hard DriveHard DriveCoolingPower
32GB ADATA S596 Turbo SSD WD Blue 500GB Scythe Mugen 2 Rev. B OCZ Fatal1ty 550W  
Case
COOLER MASTER HAF 932 
CPUMotherboardGraphicsRAM
Athlon II x2 240 ASROCK M3A770DE POWERCOLOR HD 4850 1GB G.SKILL F3 DDR3 1600 2x2GB 
Hard DriveHard DriveCoolingPower
32GB Adata S596 Turbo SSD SAMSUNG Spinpoint F3 1TB Scythe Big Shuriken 2 rev. B Cooler Master Elite Power 460W 
Case
COOLER MASTER Elite 360 
  hide details  
Reply
post #4 of 10
The point is just that you should be aware of it. If anyone who isn't you is going to use it, sanitize the input before adding it to the SQL query or even better, use SQL parameters.
#well
(19 items)
 
Lenovo L530
(8 items)
 
 
CPUMotherboardGraphicsRAM
Intel Core i7 4770k Gigabyte Z87X-UD4H XFX Radeon HD 6950 Corsair CMX8GX3M2A2000C9 
Hard DriveHard DriveOptical DriveCooling
Samsung EVO 840 Hitachi HDS722020ALA330 Generic DVD±RW Burner Noctua NH-D14 
OSMonitorMonitorKeyboard
Windows 8.1 Dell U2711 LG W2453 Ducky DK9008 Overclock.net Edition, Cherry MX B... 
PowerCaseMouseMouse Pad
Corsair TX850 Antec Three Hundred Corsair Raptor M40 QPAD HeatoN M 
AudioAudioAudio
E-MU Tracker|pre Beyerdynamic DT-770 250 Ohm AntLion ModMIc 
CPUGraphicsRAMRAM
Intel Ivy Bridge 3210M Intel HD 4000 Graphics Soldered Corsair Vengeance  
Hard DriveOptical DriveOSMonitor
500GB DVD-+RW Windows 7 Professional 1600x900 
  hide details  
Reply
#well
(19 items)
 
Lenovo L530
(8 items)
 
 
CPUMotherboardGraphicsRAM
Intel Core i7 4770k Gigabyte Z87X-UD4H XFX Radeon HD 6950 Corsair CMX8GX3M2A2000C9 
Hard DriveHard DriveOptical DriveCooling
Samsung EVO 840 Hitachi HDS722020ALA330 Generic DVD±RW Burner Noctua NH-D14 
OSMonitorMonitorKeyboard
Windows 8.1 Dell U2711 LG W2453 Ducky DK9008 Overclock.net Edition, Cherry MX B... 
PowerCaseMouseMouse Pad
Corsair TX850 Antec Three Hundred Corsair Raptor M40 QPAD HeatoN M 
AudioAudioAudio
E-MU Tracker|pre Beyerdynamic DT-770 250 Ohm AntLion ModMIc 
CPUGraphicsRAMRAM
Intel Ivy Bridge 3210M Intel HD 4000 Graphics Soldered Corsair Vengeance  
Hard DriveOptical DriveOSMonitor
500GB DVD-+RW Windows 7 Professional 1600x900 
  hide details  
Reply
post #5 of 10
Thread Starter 

Now i'm trying something that i'm finding complicated - I want to create a dropdown that has the options coming from the data in a column from a table, and lets me submit it into another table. The whole thing works fine when I define each options value, but when I try to do this dynamic options thing where it fetches the options from a table it's just not working out, I don't see any options showing up.

 

Here's the form part:

 

Quote:
<form action="insertintotable.php" method="post">
Fieldone: <input type="text" name="fieldone"><br>
Fieldtwo: <input type="text" name="fieldtwo"><br>
Dropdown:
<SELECT NAME=dropdown>
<OPTION VALUE=0>Select an option
<?php
 $con=mysqli_connect('localhost','root','pass','database');
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query("SELECT columnone FROM tabletwo",$con);
      while($row = mysqli_fetch_array($result))
      {
      $selectoptions=$row["columnone"];
      echo "<OPTION VALUE=\"".$selectoptions".\"></option>';
      }
 ?>
</SELECT>
<input type="submit">
</form>

 

can someone give me pointers on where i'm messing up?

Winter Heater
(9 items)
 
 
HTPC
(9 items)
 
CPUMotherboardGraphicsRAM
i7 2600K GIGABYTE GA-H61M-S1 Galaxy GTX 460 768MB Corsair XMS3 DDR3 1333 2x4GB 
Hard DriveHard DriveCoolingPower
64GB ADATA S596 Turbo SSD WD Green 1TB Antec Kuhler H2O 620 IN WIN Commander 650W 
Case
COOLER MASTER RC-690 
CPUMotherboardGraphicsRAM
Phenom II X6 1055T  ASUS M4A87TD EVO XFX Radeon HD 5850 1GB AMD Performance Edition DDR3 1333 2X2GB  
Hard DriveHard DriveCoolingPower
32GB ADATA S596 Turbo SSD WD Blue 500GB Scythe Mugen 2 Rev. B OCZ Fatal1ty 550W  
Case
COOLER MASTER HAF 932 
CPUMotherboardGraphicsRAM
Athlon II x2 240 ASROCK M3A770DE POWERCOLOR HD 4850 1GB G.SKILL F3 DDR3 1600 2x2GB 
Hard DriveHard DriveCoolingPower
32GB Adata S596 Turbo SSD SAMSUNG Spinpoint F3 1TB Scythe Big Shuriken 2 rev. B Cooler Master Elite Power 460W 
Case
COOLER MASTER Elite 360 
  hide details  
Reply
Winter Heater
(9 items)
 
 
HTPC
(9 items)
 
CPUMotherboardGraphicsRAM
i7 2600K GIGABYTE GA-H61M-S1 Galaxy GTX 460 768MB Corsair XMS3 DDR3 1333 2x4GB 
Hard DriveHard DriveCoolingPower
64GB ADATA S596 Turbo SSD WD Green 1TB Antec Kuhler H2O 620 IN WIN Commander 650W 
Case
COOLER MASTER RC-690 
CPUMotherboardGraphicsRAM
Phenom II X6 1055T  ASUS M4A87TD EVO XFX Radeon HD 5850 1GB AMD Performance Edition DDR3 1333 2X2GB  
Hard DriveHard DriveCoolingPower
32GB ADATA S596 Turbo SSD WD Blue 500GB Scythe Mugen 2 Rev. B OCZ Fatal1ty 550W  
Case
COOLER MASTER HAF 932 
CPUMotherboardGraphicsRAM
Athlon II x2 240 ASROCK M3A770DE POWERCOLOR HD 4850 1GB G.SKILL F3 DDR3 1600 2x2GB 
Hard DriveHard DriveCoolingPower
32GB Adata S596 Turbo SSD SAMSUNG Spinpoint F3 1TB Scythe Big Shuriken 2 rev. B Cooler Master Elite Power 460W 
Case
COOLER MASTER Elite 360 
  hide details  
Reply
post #6 of 10
My php is very rusty so i could be wrong, but isn't this line wrong?
Code:
echo "<OPTION VALUE=\"".$selectoptions".\"></option>';

You start with a " and end with a ' , and one of the . is inside the quotes.
I'm guessing it should be
Code:
echo "<OPTION VALUE=\"".$selectoptions."\"></option>";

Just a guess, as i said i haven't touched much php in the last years.

edit: actually i think the " after the backslash shouldn't be there too (last one in $selectoptions."\"), i'd recommend to check the page source to see where it's wrong but i'm pretty sure there is something wrong there.
Edited by Delphiwizard - 1/19/14 at 12:22pm
Extremepc
(18 items)
 
The Duke
(18 items)
 
 
CPUMotherboardGraphicsRAM
Core I7 2600 Asus P8P67 deluxe Asus GTX 570 Kingston DDR3 16 gb (4x4) 
Hard DriveHard DriveHard DriveHard Drive
Revodrive x2 240 ST31500341 ST32000641AS HD103UJ 
Optical DriveCoolingOSMonitor
BH10LS30 Scythe mugen 2 Windows 7 Ultimate Yamakasi Q270 SE 
MonitorKeyboardPowerCase
Samsung 2443 BW Logitech K800 Coolermaster 850 watt  Coolermaster Haf-x 
MouseOther
Logitech performance mx 2 x hauppauge HVR 2200 tuner card 
  hide details  
Reply
Extremepc
(18 items)
 
The Duke
(18 items)
 
 
CPUMotherboardGraphicsRAM
Core I7 2600 Asus P8P67 deluxe Asus GTX 570 Kingston DDR3 16 gb (4x4) 
Hard DriveHard DriveHard DriveHard Drive
Revodrive x2 240 ST31500341 ST32000641AS HD103UJ 
Optical DriveCoolingOSMonitor
BH10LS30 Scythe mugen 2 Windows 7 Ultimate Yamakasi Q270 SE 
MonitorKeyboardPowerCase
Samsung 2443 BW Logitech K800 Coolermaster 850 watt  Coolermaster Haf-x 
MouseOther
Logitech performance mx 2 x hauppauge HVR 2200 tuner card 
  hide details  
Reply
post #7 of 10
Quote:
Originally Posted by Delphiwizard View Post

My php is very rusty so i could be wrong, but isn't this line wrong?
Code:
echo "<OPTION VALUE=\"".$selectoptions".\"></option>';

You start with a " and end with a ' , and one of the . is inside the quotes.
I'm guessing it should be
Code:
echo "<OPTION VALUE=\"".$selectoptions."\"></option>";

Just a guess, as i said i haven't touched much php in the last years.

edit: actually i think the " after the backslash shouldn't be there too (last one in $selectoptions."\"), i'd recommend to check the page source to see where it's wrong but i'm pretty sure there is something wrong there.

Correct.

\" = escapes a quote
. = concatenate a string in PHP

Your "guess" is correct smile.gif
#well
(19 items)
 
Lenovo L530
(8 items)
 
 
CPUMotherboardGraphicsRAM
Intel Core i7 4770k Gigabyte Z87X-UD4H XFX Radeon HD 6950 Corsair CMX8GX3M2A2000C9 
Hard DriveHard DriveOptical DriveCooling
Samsung EVO 840 Hitachi HDS722020ALA330 Generic DVD±RW Burner Noctua NH-D14 
OSMonitorMonitorKeyboard
Windows 8.1 Dell U2711 LG W2453 Ducky DK9008 Overclock.net Edition, Cherry MX B... 
PowerCaseMouseMouse Pad
Corsair TX850 Antec Three Hundred Corsair Raptor M40 QPAD HeatoN M 
AudioAudioAudio
E-MU Tracker|pre Beyerdynamic DT-770 250 Ohm AntLion ModMIc 
CPUGraphicsRAMRAM
Intel Ivy Bridge 3210M Intel HD 4000 Graphics Soldered Corsair Vengeance  
Hard DriveOptical DriveOSMonitor
500GB DVD-+RW Windows 7 Professional 1600x900 
  hide details  
Reply
#well
(19 items)
 
Lenovo L530
(8 items)
 
 
CPUMotherboardGraphicsRAM
Intel Core i7 4770k Gigabyte Z87X-UD4H XFX Radeon HD 6950 Corsair CMX8GX3M2A2000C9 
Hard DriveHard DriveOptical DriveCooling
Samsung EVO 840 Hitachi HDS722020ALA330 Generic DVD±RW Burner Noctua NH-D14 
OSMonitorMonitorKeyboard
Windows 8.1 Dell U2711 LG W2453 Ducky DK9008 Overclock.net Edition, Cherry MX B... 
PowerCaseMouseMouse Pad
Corsair TX850 Antec Three Hundred Corsair Raptor M40 QPAD HeatoN M 
AudioAudioAudio
E-MU Tracker|pre Beyerdynamic DT-770 250 Ohm AntLion ModMIc 
CPUGraphicsRAMRAM
Intel Ivy Bridge 3210M Intel HD 4000 Graphics Soldered Corsair Vengeance  
Hard DriveOptical DriveOSMonitor
500GB DVD-+RW Windows 7 Professional 1600x900 
  hide details  
Reply
post #8 of 10
Thread Starter 

Thanks for the help, it's still not working because of some mistake(s) I must've made somewhere... I feel like i've tried everything and dropdown still not showing any options (besides the "select an option").

 

I'm just going to throw my structure I have here if it helps and anyone wants to play Sherlock/laugh at me :o:

 

Structure explanation (Click to show)
Database: database1
Tables: endpoints, locations
Column I want to fetch values from for dropdown: LocationID from the table locations. This column already exists in both tables, in locations it is primary/unique and auto-incrementing. Since they're both named the same in both tables could I be referring accidentally to the wrong one?

 

I believe the error has to be in the form file I have since it is not fetching the existing values in the column into the dropdown.

Form part of html (Click to show)
<form action="insertintotable.php" method="post">
Fieldone: <input type="text" name="fieldone"><br>
Fieldtwo: <input type="text" name="fieldtwo"><br>
LocationID:
<SELECT NAME=LocationID>
<OPTION VALUE=0>Select an option
<?php
 $con=mysqli_connect('localhost','root','mypass','database1');
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query("SELECT LocationID FROM locations",$con);
      while($row = mysqli_fetch_array($result))
      {
      $selectoptions=$row["LocationID"];
      echo "<OPTION VALUE=\"".$selectoptions."\"></option>";
      }
 ?>
</SELECT>
<input type="submit">
</form>

 

tried with and without that " after the \.


Edited by Sainesk - 1/20/14 at 5:35pm
Winter Heater
(9 items)
 
 
HTPC
(9 items)
 
CPUMotherboardGraphicsRAM
i7 2600K GIGABYTE GA-H61M-S1 Galaxy GTX 460 768MB Corsair XMS3 DDR3 1333 2x4GB 
Hard DriveHard DriveCoolingPower
64GB ADATA S596 Turbo SSD WD Green 1TB Antec Kuhler H2O 620 IN WIN Commander 650W 
Case
COOLER MASTER RC-690 
CPUMotherboardGraphicsRAM
Phenom II X6 1055T  ASUS M4A87TD EVO XFX Radeon HD 5850 1GB AMD Performance Edition DDR3 1333 2X2GB  
Hard DriveHard DriveCoolingPower
32GB ADATA S596 Turbo SSD WD Blue 500GB Scythe Mugen 2 Rev. B OCZ Fatal1ty 550W  
Case
COOLER MASTER HAF 932 
CPUMotherboardGraphicsRAM
Athlon II x2 240 ASROCK M3A770DE POWERCOLOR HD 4850 1GB G.SKILL F3 DDR3 1600 2x2GB 
Hard DriveHard DriveCoolingPower
32GB Adata S596 Turbo SSD SAMSUNG Spinpoint F3 1TB Scythe Big Shuriken 2 rev. B Cooler Master Elite Power 460W 
Case
COOLER MASTER Elite 360 
  hide details  
Reply
Winter Heater
(9 items)
 
 
HTPC
(9 items)
 
CPUMotherboardGraphicsRAM
i7 2600K GIGABYTE GA-H61M-S1 Galaxy GTX 460 768MB Corsair XMS3 DDR3 1333 2x4GB 
Hard DriveHard DriveCoolingPower
64GB ADATA S596 Turbo SSD WD Green 1TB Antec Kuhler H2O 620 IN WIN Commander 650W 
Case
COOLER MASTER RC-690 
CPUMotherboardGraphicsRAM
Phenom II X6 1055T  ASUS M4A87TD EVO XFX Radeon HD 5850 1GB AMD Performance Edition DDR3 1333 2X2GB  
Hard DriveHard DriveCoolingPower
32GB ADATA S596 Turbo SSD WD Blue 500GB Scythe Mugen 2 Rev. B OCZ Fatal1ty 550W  
Case
COOLER MASTER HAF 932 
CPUMotherboardGraphicsRAM
Athlon II x2 240 ASROCK M3A770DE POWERCOLOR HD 4850 1GB G.SKILL F3 DDR3 1600 2x2GB 
Hard DriveHard DriveCoolingPower
32GB Adata S596 Turbo SSD SAMSUNG Spinpoint F3 1TB Scythe Big Shuriken 2 rev. B Cooler Master Elite Power 460W 
Case
COOLER MASTER Elite 360 
  hide details  
Reply
post #9 of 10
Maybe it's because you're assigning a value to each field, but not populating it with content? The final content probably looks something like this:
Code:
<SELECT NAME=LocationID>
<OPTION VALUE=0>Select an option
<OPTION VALUE="Amazing"></OPTION>
<OPTION VALUE="PHP"></OPTION>
<OPTION VALUE="Skills"></OPTION>
</SELECT>
<!-- etc -->

You're missing a closing OPTION tag on the first one, and you're not assigning a display value (aka content) to each field.
For good measure I suggest that you HTML encode the $selectoptions variable before inserting it into the OPTION tag to avoid issues with characters that could be interpreted as part of the HTML rather than as part of the value/content.
Edited by gonX - 1/21/14 at 5:15am
#well
(19 items)
 
Lenovo L530
(8 items)
 
 
CPUMotherboardGraphicsRAM
Intel Core i7 4770k Gigabyte Z87X-UD4H XFX Radeon HD 6950 Corsair CMX8GX3M2A2000C9 
Hard DriveHard DriveOptical DriveCooling
Samsung EVO 840 Hitachi HDS722020ALA330 Generic DVD±RW Burner Noctua NH-D14 
OSMonitorMonitorKeyboard
Windows 8.1 Dell U2711 LG W2453 Ducky DK9008 Overclock.net Edition, Cherry MX B... 
PowerCaseMouseMouse Pad
Corsair TX850 Antec Three Hundred Corsair Raptor M40 QPAD HeatoN M 
AudioAudioAudio
E-MU Tracker|pre Beyerdynamic DT-770 250 Ohm AntLion ModMIc 
CPUGraphicsRAMRAM
Intel Ivy Bridge 3210M Intel HD 4000 Graphics Soldered Corsair Vengeance  
Hard DriveOptical DriveOSMonitor
500GB DVD-+RW Windows 7 Professional 1600x900 
  hide details  
Reply
#well
(19 items)
 
Lenovo L530
(8 items)
 
 
CPUMotherboardGraphicsRAM
Intel Core i7 4770k Gigabyte Z87X-UD4H XFX Radeon HD 6950 Corsair CMX8GX3M2A2000C9 
Hard DriveHard DriveOptical DriveCooling
Samsung EVO 840 Hitachi HDS722020ALA330 Generic DVD±RW Burner Noctua NH-D14 
OSMonitorMonitorKeyboard
Windows 8.1 Dell U2711 LG W2453 Ducky DK9008 Overclock.net Edition, Cherry MX B... 
PowerCaseMouseMouse Pad
Corsair TX850 Antec Three Hundred Corsair Raptor M40 QPAD HeatoN M 
AudioAudioAudio
E-MU Tracker|pre Beyerdynamic DT-770 250 Ohm AntLion ModMIc 
CPUGraphicsRAMRAM
Intel Ivy Bridge 3210M Intel HD 4000 Graphics Soldered Corsair Vengeance  
Hard DriveOptical DriveOSMonitor
500GB DVD-+RW Windows 7 Professional 1600x900 
  hide details  
Reply
post #10 of 10
I would really recommend asking questions on Stackoverflow - Really good if you need answers.

Anyway..

1) You need to write statements in a better way e.g. Use PDO (So much easier to work with)
2) The way I'd usually do something like this.. is to grab the results into an array and then work with them from there.
3) If you are doing this dynamically you'll want to use something like AJAX.

But if you think about the structure:

You want something like this.. select Column A - Fetch the results of all attributes where the parent is Column A - Value and place in Column B. If you want to do it truly dynamically you need to grab the post using something like Ajax.

http://www.sourcecodester.com/tutorials/php/5568/creating-dependent-dropdown-list-php-jquery-and-ajax.html something like this might help.
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › PHP/MySQL questions from a beginner