www.webdeveloper.com
Results 1 to 3 of 3

Thread: Form > Database?

  1. #1
    Join Date
    Mar 2013
    Posts
    23

    Form > Database?

    Hi,
    I have extracted an old database and imported it on a new server, I need a new form on my website and I need it linked to the database.. I have never done this before and my knowledge of PHP is minimal...

    It is actually an MOT reminder form, here are the following file names and what they contain:

    1) content.html - this is where the form is located
    2) database.php - this file contains the hostname, username, password, database etc.. are located
    3) reminder.php - this file contains the reminder functions


    The code I have for content.html is:

    Code:
    <table border="1" cellpadding="10">
    
    <td>
    <h1> MOT Reminder Form </h1>
    <form action="reminder.php" method = "post"> 
    
    Name: <br /> <input type="text" name="customer" /><br />
    <br />
    
    Email: <br /> <input type="text" name="email" /> <br />
    
    <br />
    
    Phone Number: <br /> <input type="number" name="phone" /> <br />
    
    <br />
    
    Vehicle Make/model: <br /> <input type="text" name="car" /> <br />
    
    <br />
    
    Registration: <br /> <input type="text" name="registration" /> <br />
    
    <br />
    
    Date <br /> <input type="date" name="date" /> <br />
    
    <br />
    <input type="submit" />
    </form>
    
    </form>
    
    </td>
    </table>
    I have had a guess above but it doesnt work, can anyone help me to get this working please?

    thanks,
    Daniel

  2. #2
    Join Date
    Mar 2013
    Posts
    23
    Also,
    I cannot copy the previous form as it isnt compatible with what I am doing.

  3. #3
    Join Date
    May 2008
    Posts
    14
    I'm new too but this is how I am doing it. You may have to replace the field name with the names in your database. Hope this helps.



    Add this above your form.

    Code:
    <?php
    
    include('database.php');
    
    
    if ($_POST['submitted']) 
    	{
    	$customer = $_POST['customer'];
    	$email = $_POST['email'];
    	$phone = $_POST['phone'];
    	$car = $_POST['car'];
    	$registration = $_POST['registration'];
    	$date = $_POST['date'];
    
    	
    		
    	
    	$sql = "INSERT INTO nameofyourtable (customer, email, phone, car, registration, date) VALUES ('$customer','$email' ,'$phone' ,'$car' ,'$registration' ,'$date')";
    	
    	
    if (!mysql_query($sql)) {
    	die('Error: ' . mysql_error());
    	
    
    	}
    		
    	}
    	
    	
    ?>

    Replace
    Code:
    <form action="reminder.php" method = "post">
    With
    Code:
    <form action="content.html" method="post" />
    <input type="hidden" name="submitted" value="true" />

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles