Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Other Have a form and an SQL database, but dont know how to get them to link

  • This topic is empty.
Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #250819
    dannodzines
    Participant

    I am trying to link a registration for for an event I am planning to an SQL database to track it all. The more I look onthe internet the more I realize that I am not asking Google the right question to get the help. I already have the form made, but I cannot seem to locate the proper coding to get it to go to the SQL database. What ideas do you all have? Any help is greatly appreciated.

    #250838
    I.m.learning
    Participant

    How familiar are you with databases? Before I write up anything, I’d like to know your experience. I could tell you how to establish a connection and whatnot; but you should already know how to do this, if you don’t then I fear for your safety (SQL injection/XSS/etc.).

    #250879
    Anonymous
    Inactive

    Maybe post the code you already have written. That would be helpful to see both the language you are using as well as getting an idea of what you already know.

    #250880
    dannodzines
    Participant

    That’s the thing. I do not know. Is there a good reference that I could use so I could at least start it off?

    I have tried the W3C and other sites, but it didn’t appear right to me… I will keep looking and update this post as soon as I find something…

    #250882
    Anonymous
    Inactive

    I’m sure we can find you something.

    At a basic level, a form needs to send information to a server, usually via a post request. The server then handles that request. You want the data to end up in a database, but you will need some sort of instruction to get the data from the request into your database.

    You’re going to need to look into server-side languages. I use PHP mostly, but many others exist. You may already have chosen one – if so, tell us and we can help more specifically.

    These languages will have ways of accessing the data in the request. They will also have ways of connecting to your database and submitting SQL queries.

    Things to look up:

    • How to access post variables in your chosen language
    • How to open a database connection in your chosen language
    • How to query a database in your chosen language
    • How to execute statements safely (for example, using prepared statements). If you don’t know what these are, please read into this before you make any web form live.

    Finally, look into other options that don’t require coding. Google forms work pretty well for a lot of cases and unless you’re planning to use this knowledge elsewhere (either just because you’re keen to learn, or maybe you’re planning to use this code a lot), you might be better off using an existing solution and a spreadsheet. Just a thought.

    #250884
    I.m.learning
    Participant

    That’s why I wanted to know your experience. You stated you tried W3C; try W3 Schools; they have hands-on tutorials with examples.

    Just like with most coding; there are various ways to accomplish a task (just as BenWalker stated with some examples).

    My concern was about your security. If you use a live webpage to test and it is not properly protected, someone could use SQL injection and wipe out your entire databases.

    I say start from the very beginning and refer to Ben’s statement:

    “You’re going to need to look into server-side languages. I use PHP mostly, but many others exist. You may already have chosen one – if so, tell us and we can help more specifically.”

    I, like Ben, use PHP and use Wampserver (Windows) to test my pages. There’s also: MAMP, LAMP, and XAMP.

    http://pikandeeweb.com/2014/09/12/difference-wamp-lamp-mamp-xampp/

    #250943
    dannodzines
    Participant

    So, I have been looking into php texts, and I found this
    <form action=”action.php” method=”post”>

    Your name: <input type=”text” name=”name” />

    Your age: <input type=”text” name=”age” />

    <input type=”submit” />

    </form>
    but I do not see a way that this will also email people. If I try
    <form action=”action.php” method post, form action=
    “mailto:[email protected][email protected]&subject=Showdown Pledge Form” method=”post” enctype=”text/plain”>
    Name:<br>
    <input type=”text” name=”Sponsors Name” style=”height: 35px; width: 500px; font-family: ‘times new roman’; font-size: 18px;”required><br>
    Email Address:<br>
    <input type=”text” name=”Sponsors Email” style=”height: 35px; width: 500px; font-family: ‘times new roman’; font-size: 18px;”required><br>
    Phone Number:<br>
    <input type=”text” name=”Sponsors Phone” style=”height: 35px; width: 500px; font-family: ‘times new roman’; font-size: 18px;”required><br>
    Choose your Bowler:<br>
    <input type=”checkbox” name=”Chris”>Chris
    <input type=”checkbox” name=”Dave”>Dave
    <input type=”checkbox” name=”both”>Both<br>
    Which game do you choose to sponsor? (Select game(s))<br>
    <input type=”checkbox” name=”Game 1″>Game 1
    <input type=”checkbox” name=”Total”>Total<br>
    Please tell us what you will be sponsoring: (select ONE)<br>
    <input type=”checkbox” name=”Total Pins”>Pins
    <input type=”checkbox” name=”Strikes”>Strikes
    <input type=”checkbox” name=”Marks”>Strikes/Spares<br>
    Please Tell us how much you plan on donating for above:<br>
    <input type=”text” name=”Amount” style=”height: 35px; width: 35px; font-family: ‘times new roman’; font-size: 18px;”required><input type=”checkbox” name=”cents”>Cents<input type=”checkbox” name=”Dollars”>Dollars<br><br><br>

    <input type=”submit” value=”send” style=”height: 50px; width: 150px; font-size: 18px;”>
    <input type=”reset” value=”reset” style=”height: 50px; width: 150px; font-size: 18px;”>
    </form>

    if I did this and added the php codes at the top of the body section, would that make it possible to email and save the data on the database? There is a lot that I have left to learn, but in a sense I have not really learned anything… Soooooooo much…

    ps the codepen does not like me

    #250952
    I.m.learning
    Participant

    Have a look at these links

    Emails
    http://stackoverflow.com/questions/17384494/sending-an-automated-email

    MySQL
    http://www.tutorialrepublic.com/php-tutorial/php-mysql-insert-query.php

    Without having a server on your own computer, you won’t be able to test PHP on your own system.

    http://php.net/manual/en/tutorial.requirements.php

    If you use Windows, download Wampserver
    http://www.homeandlearn.co.uk/php/php1p3.html

    #250954
    Beverleyh
    Participant

    You might want to take a look into Form Tools http://www.formtools.org it’s FREE

    You host it yourself and can plug it into any HTML form – it will process the data and send out emails as well as storing the data in a database.

    It has a nice backend admin panel where you can further manipulate the database (add more fields at a later date), create data ‘views’ (for admins and clients) and even input data (i.e. It accepts ‘submissions’ via the frontend form AND backend admin) and you can export data to excel spreadsheets for further analysis.

    Might make things easier for you.

    #250960
    dannodzines
    Participant

    When inserting the php codes into the HTML what section do I do this in? Does it go in the head or the body? I appreciate all the help so far and soon I will be able to test this.

    #250961
    Beverleyh
    Participant

    What PHP codes?

    PHP can go anywhere – it depends what it’s doing.

    #250985
    dannodzines
    Participant

    This may be a dumb question, but when I connect in php in a specific section, do I have to close it before moving on to the next set? This is what I have right now and I want to make sure all the work I have done is on the right track. You all have been great so far. The references were spot on and also were very helpful. I only want the information of a form to go to mysql so that is the plan… here are the codes so far.

    <?php
    $link=mysqli_connect (“104.168.177.4”, “rdhczoav_bowlers”, “bowlers”, “rdhczoav_bowlersagainstdepression”);
    if($link===false){
    die(“ERROR: Could not connect.”.mysqli_connect_error());}
    $sql= “CREATE TABLE bowlers (bowler_id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, firstName VARCHAR (30) NOT NULL, lastName VARCHAR (30) NOT NULL, emailAddress VARCHAR (100), PhoneNumber VARCHAR (15) NOT NULL, Bowler VARCHAR (7) NOT NULL, Games VARCHAR (10) NOT NULL, Amount VARCHAR (5) NOT NULL, Per VARCHAR (10) NOT NULL”;
    if (mysqli_queary ($link, $sqli)){
    echo “Table bowlers created successfully”;}
    else{
    echo “Error: Could not able to execute $sqli.” . myysqli_error($link);
    }
    <form action=”insert.php” method=”post”>

    <label for=”firstName”>First Name:</label>
    <input type=”text” name=”firstname” id=”firstName”>

    <label for=”lastName”>Last Name</label>
    <input type=”text” name=”lastname” id=”lastName”>

    <label for=”emailAddress”>Email Address:</label>
    <input type=”text” name=”email” id=”emailAddress”>

    <label for=”phoneNumber”>Phone Number:</label>
    <input type=”text” name=”phone” id=”PhoneNumber”>

    <input type=”text” name=”Sponsors Phone” style=”height: 35px; width: 500px; font-family: ‘times new roman’; font-size: 18px;”

    <label for=”bowler”>Chris or David</label>
    <input type=”text” name=”bowler” id=”Bowler”>

    <label for=”games”>Game 1, 2, 3, or total (select as many as you want)</input>
    <input type=”text” name=”games” id=”Games”>

    <label for=”amount”>Amount in cents</label>
    <input type=”text” name=”amount” id=”Amount”

    <label for=”per”>Strike, mark, or Pins</label>
    <input type=”text” name=”per” id=”Per”

    <input type=”submit” value=”send” style=”height: 50px; width: 150px; font-size: 18px;”>
    <input type=”reset” value=”reset” style=”height: 50px; width: 150px; font-size: 18px;”>
    </form>
    <h3 align=”center”>Website donated by DannoDzines. For more information on DannoDzine please email [email protected] or visit Dannodzines.</h3>
    </main>
    <?php
    $link=mysqli_connect (“104.168.177.4”, “rdhczoav_bowlers”, “bowlers”, “rdhczoav_bowlersagainstdepression”);
    if($link===false){
    die(“ERROR: Could not connect.”.mysqli_connect_error());}
    mysqli_close($link);
    ?>

    #250995
    Beverleyh
    Participant

    You are fine to break in and out of PHP around HTML, but you’re missing a closing PHP tag here, if that’s what you mean;

    }
    /* close the PHP here */ 
    ?>
     <form action="insert.php" method="post">
    

    However, I would expect to see the PHP code for form processing, and insertion into the database, in the “insert.php” file referenced in the action attribute of your form.

Viewing 13 posts - 1 through 13 (of 13 total)
  • The forum ‘Other’ is closed to new topics and replies.