Jump to content

Creating a HTML select bar with another HTML select bar in a php document.


Entiranz

Recommended Posts

Hi everyone, im trying to create a php and javascript based search engine for use with mySQL. Its main purpose is to be able to access the database without having to type any SQL code manually, and i would appreciate any help you could give me.

 

At this stage, i have a library file that is functional and a php file that will display a table with the search results. The problem im facing right now is the main search engine, where im trying to implement javascript to create a select bar enabling you to pick the search parameters (the WHERE bit of the sql, like WHERE ID < 7 or something like that).

 

This is my current code:

<html>
      <head>
            <title>Chefens Tabell Formulär</title>
            <script type="text/javascript">

                    var formInputs = document.forms["searchengine"].elements;
                    function selectCreate()
                    {

                         var textCreate = "Tabell " + formInputs["tableselect"].value + ".";
                         if(formInputs["tableselect"].value == "anställda")
                         {
                             var barCreate = "<select name=\"columnselect\"><option>ID</option><option>Förnamn</option><option>Efternamn</option><option>Lön</option><option>PI ID</option><option>Kontakt ID</option><option>Avdelning ID</option></select>";
                         }
                         else if(formInputs["tableselect"].value == "avdelning")
                         {
                             var barCreate = "<select name=\"columnselect\"><option>ID</option><option>Avdelning</option><option>Syfte</option><option>Antal Medlemmar</option><option>Effektivitet</option></select>";
                         }
                         else if(formInputs["tableselect"].value == "kontakt information")
                         {
                             var barCreate = "<select name=\"columnselect\"><option>ID</option><option>Telefon Nr</option><option>Email Adress</option><option>Mobil Nr</option><option>Post Nr</option><option>IP Adress</option></select>";
                         }
                         else if(formInputs["tableselect"].value == "privat information")
                         {
                             var barCreate = "<select name=\"columnselect\"><option>ID</option><option>Adress</option><option>Moder</option><option>Fader</option><option>Antal Syskon</option><option>Vaknings Tid</option><option>Morgon Rutin</option><option>Anländer till Jobbet</option><option>Hemligheter</option></select>";
                         }
                         else
                         {
                             var barCreate = "Error, no table has been selected."
                         }
                         document.getByIdElement("javatextout").innerHTML = textCreate;
                         document.getByElementId("javabarout").innerHTML = barCreate;
                    }
            </script>
      </head>
<body>
      <form name="searchengine" action="Chefens Svar Formular.php" method="post">
            <p>Vad vill du söka efter i tabellen?</p>
            <br />
            <select name="val">
                    <option>1</option>
                    <option>2</option>
                    <option>3</option>
                    <option>4</option>
                    <option>5</option>
                    <option>6</option>
                    <option>7</option>
                    <option>8</option>
                    <option>9</option>
                    <option>10</option>
                    <option>11</option>
                    <option>12</option>
                    <option>13</option>
                    <option>14</option>
                    <option>15</option>
                    <option>16</option>
                    <option>17</option>
                    <option>17</option>
                    <option>18</option>
                    <option>19</option>
                    <option>20</option>
            </select>
            <br />
                    <input type="checkbox" name="thing1" value="Förnamn">Förnamn
                    <input type="checkbox" name="thing2" value="Efternamn">Efternamn
                    <input type="checkbox" name="thing3" value="Lön">Lön
                    <input type="checkbox" name="thing4" value="Adress">Adress
                    <input type="checkbox" name="thing5" value="Moder">Moder
            <br />
                    <input type="checkbox" name="thing6" value="Fader">Fader
                    <input type="checkbox" name="thing7" value="Antal Syskon">Antal Syskon
                    <input type="checkbox" name="thing8" value="Vaknings Tid">Vaknings Tid
                    <input type="checkbox" name="thing9" value="Morgon rutin">Morgon Rutin
                    <input type="checkbox" name="thing10" value="Anländer till jobbet">Anländer Till Jobbet
            <br />
                    <input type="checkbox" name="thing11" value="Hemligheter">Hemligheter
                    <input type="checkbox" name="thing12" value="Telefon Nr">Telefon Nummer
                    <input type="checkbox" name="thing13" value="Email Adress">Email Adress
                    <input type="checkbox" name="thing14" value="Mobil Nr">Mobil Nummer
                    <input type="checkbox" name="thing15" value="Post Nr">Post Nummer
            <br />
                    <input type="checkbox" name="thing16" value="Ip Adress">Ip Adress
                    <input type="checkbox" name="thing17" value="Avdelning">Avdelning
                    <input type="checkbox" name="thing18" value="Syfte">Syfte
                    <input type="checkbox" name="thing19" value="Antal Medlemmar">Antal Medlemmar
                    <input type="checkbox" name="thing20" value="Effektivitet">Effektivitet
            <br />
            <h4>Vad är sök parametrarna?</h4>
                    <br />
                         <p>Vilken tabell vill du börja i?</p>
                                <select name="tableselect">
                                <option>anställda</option>
                                <option>kontakt information</option>
                                <option>privat information</option>
                                <option>avdelning</option>
                                </select>
                                <br />
                                <input type="button" value="Välj" onclick="selectCreate()">
                         <div id="javatextout"></div>
                         <br />
                         <div id="javabarout"></div>
                         <p>Vilken operator vill du använda? (=, <, >)</p>
                         <br />
                                     <input type="radio" name="oper" value="=">=
                                     <input type="radio" name="oper" value="<"><
                                     <input type="radio" name="oper" value=">">>
                         <br />
                         <br />
                                <input type="reset" value="Reset">
                         <br />
                         <br />
                                <input type="submit" value="Search">
      </form>
</body>
</html>

 

Let me know if you need the other files, but i dont think you do since they get information from this one and not the other way around.

 

Entiranz.

Link to comment
Share on other sites

Ok after looking over the code a few times more i noticed some syntax errors (i had written getByElementId and not getElementById and some other nonsense) but even after fixing thosethe button still doesnt do anything.. Hope you guys can help.

 

Entiranz.

Link to comment
Share on other sites

Okay, now i know that. I did manage to make it work but this is only for a school assignment, i have no intention of using it inside an actual website. But before i mark this as solved is there any other way to make it work like i intend to, without problems like this? It would be nice to be able to create a search engine like this, but id rather do it without any security risks.

 

Entiranz.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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