Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: Please can someone help me implement this script into another script?

  1. #1
    Join Date
    Apr 2012
    Posts
    12
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Post Please can someone help me implement this script into another script?

    Hi guys,

    I have a problem which has been sticking with me for 2 weeks now, I haven't found any solution so I decided i will start my own thread.

    The problem:

    I want to implement my calendar.php into my book.php . However everytime i try i get a blank screen on my localhost:8080/start/booking/book.php or it just wont insert the data into the database.

    The files:

    book.php

    Code:
    <?php
    echo "<h1>book</h1>";
    
    $submit = $_POST['submit'];
    //form data
    
    $fullname = strip_tags($_POST['fullname']);
    $service = strip_tags($_POST['service']);
    $address = strip_tags($_POST['address']);
    $veichle = strip_tags($_POST['veichle']);
    $date = date ("Y-m-d");
    
    if ($submit)
    {
       //check for existance
        if ($fullname&&$service&&$address&&$veichle)
        {
    
    
                    //register the user!
    
                   //encrypt password
                  // $password       = md5($password);
                  // $repeatpassword = md5($repeatpassword);
                   
                     //open our database
                     $connect = mysql_connect ("localhost", "root", "");
                     mysql_select_db("autoservice");  //select database
                     $queryreg = mysql_query("
                     INSERT INTO booking VALUES ('','$fullname','$service','$address','$veichle','$date')
                     ");
    
                   die ("You have been registered! <a href='index.php'> Return to login page</a>");
                 }
                }
    
        
    
        else {
        echo "Please fill in <b>all</b> fields!";
    }
    
    ?>
    <html>
    <p>
    <form action='book.php' method='POST'>
          <table>
                 <tr>
                     <td>
                     Your full name:
    
                     </td>
                     <td>
                     <input type='text' name='fullname'>
                     </td>
                 </tr>
                 <tr>
                     <td>
                     Choose a service:
    
                     </td>
                     <td>
                     <input type='text' name='service'>
                     </td>
                 </tr>
                 <tr>
                     <td>
                     Address:
    
                     </td>
                     <td>
                     <input type='text' name='address'>
                     </td>
                 </tr>
                 <tr>
                     <td>
                     Veichle:
    
                     </td>
                     <td>
                     <input type='text' name='veichle'>
                     </td>
                 </tr>
           </table>
           <p>
           <input type='submit' name='submit' value='Register'>
           
    </form>
    
    
    
    
    
    </html>

    Calendar.php
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Bookings</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script type="text/javascript" src="calendarDateInput.js">
    
    /***********************************************
    * Jason's Date Input Calendar- By Jason Moon http://calendar.moonscript.com/dateinput.cfm
    * Script featured on and available at http://www.dynamicdrive.com
    * Keep this notice intact for use.
    ***********************************************/
    
    </script>
    </head>
    <body>
    <?php
    $DBConnect = @mysql_connect("localhost", "root");
    if (!$DBConnect)
      {die("<p>The database server is not available</p>");
      }
      
      $dbselect = @mysql_select_db("autoservice");
      
      if (!$dbselect){
      die("<p>The database is not available</p>");
      }
    
    $inp = $_POST['date']; // Get the textbox that holds the date
    $table_name='booking'; // Set the name of your table 
    $col_name = 'fromdate'; // Set the column that will hold the dates 
    
    if(isset($_POST['submit'])) 
        { 
        $sQuery = "INSERT INTO $table_name($col_name) VALUES ('($inp)')"; // Insert query 
    	//This function encodes will change any type of date and format it to (YYYY-mm-dd) and will store the date into mysql table
    function encodeDate ($inp) {
    $tab = explode ("-", $inp);
    $r = $tab[2]."-".$tab[1]."-".$tab[0];
    return $r;
    }
        mysql_query($sQuery) or die(mysql_error()); // Do the query 
        } 
    	
     
    ?> 
    
    <form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>"> 
    <script>DateInput('date', true, 'YYYY-MM-DD')</script> 
    <input type="submit" name="submit" value="Submit"> 
    </form> 
    
    </body>
    </html>

    More info:

    The files work fine when testing them each seperately.
    I also appreciate any help please dont spam this thread i.e "Do it yourself" as I said i have been looking for 2 weeks.


    Thank you

  2. #2
    Join Date
    Mar 2011
    Posts
    2,002
    Thanks
    59
    Thanked 107 Times in 105 Posts
    Blog Entries
    4

    Default

    Just one quick note about (one of the) scripts you posted.

    This line (from the second)

    Code:
    <form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    is dangerous as it leaves you open to XSS attack.

    Use this instead

    Code:
    <form method="POST" action="<?php echo esc_url( $_SERVER['PHP_SELF'] ); ?>">
    Correct me if I'm wrong
    Keyboard1333

  3. The Following User Says Thank You to keyboard For This Useful Post:

    Autoservice (04-02-2012)

  4. #3
    Join Date
    Apr 2012
    Posts
    12
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Smile

    Quote Originally Posted by keyboard1333 View Post
    Just one quick note about (one of the) scripts you posted.

    This line (from the second)

    Code:
    <form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    is dangerous as it leaves you open to XSS attack.

    Use this instead

    Code:
    <form method="POST" action="<?php echo esc_url( $_SERVER['PHP_SELF'] ); ?>">
    Correct me if I'm wrong
    Keyboard1333
    Thanks for the note.

  5. #4
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    I'm not entirely sure how you want to combine them- do you want to put the "Jason's input date..." thing in the original form?

    Is there are a reason you need the user to input the date? If you are just looking to store the date that the user submits the form, you can use the php date() function.

    Please clarify what it is you want to accomplish here.
    - Mike

  6. The Following User Says Thank You to mburt For This Useful Post:

    Autoservice (04-03-2012)

  7. #5
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    On an unrelated note, your original form has some issues. "book.php" should function in the following order:

    1) Check if any post data is sent
    2) If so, evaluate post data, if not proceed to page

    Like this:

    Code:
    <?php
    if (count($_POST) > 0) {
      // Evaluate form data here
    }
    ?><!DOCTYPE html>
    <html>
    ... rest of page goes here
    </html>
    Also your PHP code is outputting HTML data before your first <html> tag. What you should do instead is this:

    Code:
    if ($fullname && $service && $address && $veichle) {
      // ...Do database stuff
      $message = "You have been registered... etc.";
    }
    And further down your page, somewhere in your body:
    Code:
    <?php
    if (isset($message)) echo "<div>$message</div>";
    ?>
    - Mike

  8. The Following User Says Thank You to mburt For This Useful Post:

    Autoservice (04-03-2012)

  9. #6
    Join Date
    Apr 2012
    Posts
    12
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by mburt View Post
    I'm not entirely sure how you want to combine them- do you want to put the "Jason's input date..." thing in the original form?

    Is there are a reason you need the user to input the date? If you are just looking to store the date that the user submits the form, you can use the php date() function.

    Please clarify what it is you want to accomplish here.
    Hi mburt,

    Thanks for you great answers! Sorry i didn't explain my aim.

    My aim:

    I want to create an appointment page for my client so his customers can book a date for an appointment (that is the purpose of the calendar).

    So i basically need help by putting all this code into 1 file, so it should be like this:

    Full name:
    Service:
    Address:
    Veichle:
    [The calendar]
    Submit button

    The problem is I have the calendar in 1 file and the rest (full name,service e.t.c) in another file. I need them both in 1 file. hope you got that

  10. #7
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Look back at this line in the "book.php":

    Code:
    INSERT INTO booking VALUES ('','$fullname','$service','$address','$veichle','$date')");
    Does $date need to be the inputted date by the user?

    And one more thing... Do you mean "vehicle" every time "veichle" is written there?
    - Mike

  11. The Following User Says Thank You to mburt For This Useful Post:

    Autoservice (04-03-2012)

  12. #8
    Join Date
    Apr 2012
    Posts
    12
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by mburt View Post
    Look back at this line in the "book.php":

    Code:
    INSERT INTO booking VALUES ('','$fullname','$service','$address','$veichle','$date')");
    Does $date need to be the inputted date by the user?

    And one more thing... Do you mean "vehicle" every time "veichle" is written there?
    For the "$date" no it shouldn't be inputted by the user the form automatically sents the date of submission into my database.

    And for the "veichle" yes the person has to type in their veichle company.

    I know this sound stupid but im going to change this later

  13. #9
    Join Date
    Mar 2011
    Posts
    2,002
    Thanks
    59
    Thanked 107 Times in 105 Posts
    Blog Entries
    4

    Default

    IMPORTANT
    One other quick note -
    You should never post your database connection details online


    Code:
    $DBConnect = @mysql_connect("localhost", "*****");
    if (!$DBConnect)
      {die("<p>The database server is not available</p>");
      }
    do that instead

    You'll have to change it back after someone's answered the question, but it will stop other people from accessing your database.

  14. #10
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    So where does the inputted date go? Which column is it in your database?

    This script combines both of those things, however, in the mysql_query the inputted date is NOT included:

    Code:
    <?php
    if (count($_POST) > 0) {
      function s($x) { return strip_tags(stripslashes($_POST[$x])); }
      $fullname = s("fullname"); $service = s("service");
      $address = s("address"); $vehicle = s("vehicle");
      $date = date("Y-m-d");
      $input_date = s("date"); // this is the user inputted appointment date
      if ($fullname && $service && $address && $vehicle && $date) {
        mysql_connect("localhost", "root", "");
        mysql_select_db("autoservice");
        mysql_query("INSERT INTO booking VALUES('', '$fullname', '$service', '$address', '$vehicle', '$date')");
        mysql_close();
        $message = "You have been registered! <a href=\"index.php\"> Return to login page</a>";
      } else $message = "Please fill in <b>all</b> fields";
    }
    ?><!DOCTYPE html>
    <html>
      <head>
        <meta charset="UTF-8">
        <title>Book an Appointment</title>
        <style type="text/css">
    .row { margin-bottom: 5px; }
    .field { float: left; width: 150px; }
    .clear { clear: left; }
    .message { color: red; }
        </style>
        <script type="text/javascript" src="calendarDateInput.js">
    /***********************************************
    * Jason's Date Input Calendar- By Jason Moon http://calendar.moonscript.com/dateinput.cfm
    * Script featured on and available at http://www.dynamicdrive.com
    * Keep this notice intact for use.
    ***********************************************/
        </script>
      </head>
      <body>
        <form action="book.php" method="post">
          <div class="row">
            <div class="field">Your full name:</div>
            <div class="field"><input name="fullname"></div>
            <div class="clear"></div>
          </div>
          <div class="row">
            <div class="field">Choose a service:</div>
            <div class="field"><input name="service"></div>
            <div class="clear"></div>
          </div>
          <div class="row">
            <div class="field">Address:</div>
            <div class="field"><input name="address"></div>
            <div class="clear"></div>
          </div>
          <div class="row">
            <div class="field">Vehicle:</div>
            <div class="field"><input name="vehicle"></div>
            <div class="clear"></div>
          </div>
          <div class="row">
            <div class="field">Date:</div>
            <div class="field"><script type="text/javascript">DateInput('date', true, 'YYYY-MM-DD')</script></div>
            <div class="clear"></div>
          </div>
          <div class="row">
            <div class="field">&nbsp;</div>
            <div class="field"><input type="submit" value="Register!"></div>
            <div class="clear"></div>
          </div>
        </form><?php
    if (isset($message)) echo "\n    <div class=\"message\">$message</div>";
    ?>
      </body>
    </html>
    You need to figure out which field the inputted date (appointment date) goes into, then I can update it appropriately.
    Last edited by mburt; 04-03-2012 at 12:54 AM.
    - Mike

Bookmarks

Posting Permissions

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