Jump to content

Problems with submitting data to mySQL ?


cyber_alchemist

Recommended Posts

I was working on a small script which gets inputs from the user and posts them to the website , the data is stored in the MySQL database but , the script is not working and its not posting any data to the database also it is not giving me any error .. could someone look into this  ??

 

codes :

 

index.php 

<link rel="shortcut icon" type="image/x-icon" href="img/favicon.ico" />
    <link rel="stylesheet" type="text/css" href="css/bjqs.css" />

    <link rel="stylesheet" type="text/css" media="only screen and (max-device-width: 990px)" href="css/mobile.css" />
    <link rel="stylsheet" type="text/css" media="print" href="css/print.css" />
    <link rel="stylesheet" type="text/css" href="css/jquery-ui-1.10.3.custom.css" />
    <link href="style.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" href="css/jquery.wysiwyg.css" type="text/css"/>



    <script type="text/javascript" src="js/jquery-1.9.1.js"></script>
    <script type="text/javascript" src="js/bjqs-1.3.js"></script>
    <script type="text/javascript" src="js/jquery-ui-1.10.3.custom.js"></script>
    <script type="text/javascript" src="js/jquery.validate.js" ></script>
    <script type="text/javascript" src="js/jquery.wysiwyg.js"></script>
    <script type="text/javascript" src="js/wysiwyg.image.js"></script>
    <script type="text/javascript" src="js/wysiwyg.link.js"></script>
    <script type="text/javascript" src="js/wysiwyg.table.js"></script>

    <script type="text/javascript">

      $(function domestic_boxes(){
        $('.domestic-tours').tabs();
        $('#book-now').button();
        $('#call').button();
        $('#submit').button();
      });

      $(function icons(){
            // Hover states on the static widgets
    $( "#dialog-link, #icons li" ).hover(
      function() {
        $( this ).addClass( "ui-state-hover" );
      },
      function() {
        $( this ).removeClass( "ui-state-hover" );
      }
    );
      });

      $(function slideslide() {

        $('#slider-inner').bjqs({
          height      : 400,
          width       : 620,
          responsive  : true
        });

        $('#dest-thumb-nail').bjqs({
          height     : 200,
          width      : 250,
          responsive : true
        });

        $('#dest-thumb-nail-2').bjqs({
          height : 200,
          width : 250,
          responsive : true
        });

      });

      $(function TourInput(){
        $('#tour-package').tabs();
        $('#days').keyup(function pickdays() {
          if (this.value != this.value.replace(/[^0-9\.]/g, '')) {
                this.value = this.value.replace(/[^0-9\.]/g, '');
            }
        });
        $('#nights').keyup(function picknights() {
          if (this.value != this.value.replace(/[^0-9\.]/g, '')) {
                this.value = this.value.replace(/[^0-9\.]/g, '');
            }
        });
        $('#twintriple').keyup(function picknights() {
          if (this.value != this.value.replace(/[^0-9\.]/g, '')) {
                this.value = this.value.replace(/[^0-9\.]/g, '');
            }
        });
        $('#singleocc').keyup(function picknights() {
          if (this.value != this.value.replace(/[^0-9\.]/g, '')) {
                this.value = this.value.replace(/[^0-9\.]/g, '');
            }
        });
        $('#childnobed').keyup(function picknights() {
          if (this.value != this.value.replace(/[^0-9\.]/g, '')) {
                this.value = this.value.replace(/[^0-9\.]/g, '');
            }
        });
        $('#infbelow').keyup(function picknights() {
          if (this.value != this.value.replace(/[^0-9\.]/g, '')) {
                this.value = this.value.replace(/[^0-9\.]/g, '');
            }
        }); 
        $('#transportation').wysiwyg({
          autoGrow: true,
          maxHeight: 600
        });
        $('#payment-norms').wysiwyg({
          autoGrow: true,
          maxHeight: 600
        });
        $('#overview').wysiwyg({
          autoGrow: true,
          maxHeight: 600
        });
        $('#inclusions').wysiwyg({
          autoGrow: true,
          maxHeight: 600
        });
        $('#exclusions').wysiwyg({
          autoGrow: true,
          maxHeight: 600
        });
        $('#itinerary').wysiwyg({
          autoGrow: true,
          maxHeight: 600
        });
        $('#pricingdetails').wysiwyg({
          autoGrow: true,
          maxHeight: 600
        });
      });


    </script>

  </head>

  <body>
    <!--Header End -->
    <div id="header-inner">
      <div class="header-top">
        <div class="head-left"><a href="index.html" ><img src="img/site-logo.png" /></a></div>
        <div class="contact"><div class="head-left"><img height="50" width="55" src="img/telephone.png" /></div><div class="head-right">+919830042523</div></div>
        <div class="contact"><div class="head-left"><img height="50" width="55" src="img/email.png" /></div><div class="head-right">[email protected]</div></div>
      </div>
      <div class="cleaner"></div>
    </div>
    <!--Header End -->
    <!--Container -->
    <div id="container">
      <div class="cleaner"></div>
      <div class="package-part-left" >
      <div class="domestic-tour-lists"> 

         <?php
    
            include_once('_class/tourCMS.php');
            $obj = new tourCMS();

	         /* SETTINGS FOR DATABASE */
            $obj->host = 'mysql.1freehosting.com';
            $obj->username = 'u694861683_sim';
            $obj->password = 'simple';
            $obj->table = 'u694861683_sim';
            $obj->connect();
    
          if ( $_POST )
            $obj->write($_POST);
    
            echo ( $_GET['admin'] == 1 ) ? $obj->display_admin() : $obj->display_public();
    
          ?>
	   </div>

and tourCMS.php :-

class tourCMS {

  var $host;
  var $username;
  var $password;
  var $table;

  public function display_public() {
    $show = $_GET['show'] + 5;

      $q = "SELECT * FROM tourDB ORDER BY created DESC LIMIT $show";

      $r = mysql_query($q);

    if ( $r !== false && mysql_num_rows($r) > 0 ) {
      while ( $a = mysql_fetch_assoc($r) ) {
        $tour_id = stripslashes($a['tour_id']); 
        $tour_type = stripslashes($a['tour_type']);
        $tour_name = stripslashes($a['tour_name']);
        $day = stripslashes($a['day']);
        $nights = stripslashes($a['nights']);
        $tour_price = stripslashes($a['tour_price']);
        $overview = stripslashes($a['overview']);
        $itinerary = stripslashes($a['itinerary']);
        $terms_conditons = stripslashes($a['terms_conditons']);
        $inclusions = stripslashes($a['inclusions']);
        $exclusions = stripslashes($a['exclusions']);
        $twin_triple_sharing = stripslashes($a['twin_triple_sharing']);
        $single_occcupancy = stripslashes($a['single_occcupancy']);
        $child_with_no_bed = stripslashes($a['child_with_no_bed']);
        $inf_below = stripslashes($a['inf_below']);
        $pricing_details = stripslashes($a['pricing_details']);
      

        $entry_display .= <<<ENTRY_DISPLAY
<div class="domestic-tours">
        <ul>
            <li><a href="#overview_$tour_name">Overview</a></li>
            <li><a href="#itinerary_$tour_name">Itinerary</a></li>
            <li><a href="#inclusions_$tour_name">Inclusions</a></li>
            <li><a href="#terms_$tour_name">Terms And Conditions</a></li>
            <li><a href="#price_$tour_name">Tour Price</a></li>
        </ul>
        <div id="overview_$tour_name">
            <div id="dest-thumb-nail" class="dest-thumb-nail">
              <ul class="bjqs">
                <li><img src="img/bangkok/1.jpg" /></li>
                <li><img src="img/bangkok/2.jpg" /></li>
                <li><img src="img/bangkok/3.jpg" /></li>
                <li><img src="img/bangkok/4.jpg" /></li>
                <li><img src="img/bangkok/5.jpg" /></li>
                <li><img src="img/bangkok/6.jpg" /></li>
                <li><img src="img/bangkok/6.jpg" /></li>
              </ul>
            </div>
            <div class="overview">
              <span class="overview-heading">$tour_name</span><br /><br />
              <span class="overview-duration">$nights Nights , $day Days</span><br /><br />
                $overview 
            </div>
        </div>
        <div id="itinerary_$tour_name">
          <div class="itin-content">
            <span class="overview-heading">$tour_name</span><br /><br />
            <span class="overview-duration">$nights Nights, $day Days</span><br /><br /><br />
            $itinerary 
          </div> 
        </div>
        <div id="inclusions_$tour_name">
          <div class="inclusions-exclusions">
            <span class="inclusions">Inclusions</span><br /><br />
              $inclusions
            <br />
            <br />
            <span class="exclusions">Exclusions</span><br /><br />
              $exclusions
            <br />
            <br />
          </div>
        </div>
        <div id="terms_$tour_name">
          <div class="terms" >
            <span class="terms-and-conditions" >Terms And Conditions </span><br /><br />
            $terms_conditons
          </div>
        </div>
        <div id="price_$tour_name">
          <div class="price-tab" >
            <div class="price-tab-row" >
              <div class="price-tab-element">
              <b>Pax Type</b>
              </div>
              <div class="price-tab-element">
              <b>Tour Price Total in INR</b>
              </div>
            </div>
            <div class="price-tab-row" >
              <div class="price-tab-element" >
                Twin/Triple Sharing
              </div>
              <div class="price-tab-element" >
                <span class="rupee">`</span> $twin_triple_sharing
              </div>
            </div>
            <div class="price-tab-row" >
              <div class="price-tab-element" >
                Single Occupancy 
              </div>
              <div class="price-tab-element" >
                <span class="rupee">`</span> $single_occcupancy 
              </div>
            </div>
            <div class="price-tab-row">
              <div class="price-tab-element" >
                Child With No Bed
              </div>
              <div class="price-tab-element">
                <span class="rupee" >`</span> $child_with_no_bed
              </div>
            </div>
            <div class="price-tab-row">
              <div class="price-tab-element">
                Infant below 2 years
              </div>
              <div class="price=tab-element" >
                FREE
              </div>
            </div>
            <button id="book-now">Book Now !</button>
            <button id="call" >call your travel expert</button>
          </div> 
        </div>
      </div>
      <div class="price-tag-domestic"><span class="pricy-price" >` $tour_price</span></div>

ENTRY_DISPLAY;
      }
    } else {
      $entry_display = <<<ENTRY_DISPLAY

<div class="domestic-tours">
<ul>
  <li><a href="#notice">Notice</a></li>
</ul>
  <div id="notice" > 
    <h2> This Page Is Under Construction </h2>
    <p>
      No entries have been made on this page. 
      Please check back soon, or click the
      link below to add an entry!
    </p>
  </div>
</div>

ENTRY_DISPLAY;
    }
    $entry_display .= <<<ADMIN_OPTION

</div>
<div class="pager-items" >
  <div class="pager-display-element">
    <ul id="icons" class="ui-widget ui-helper-clearfix">
      <li class="ui-state-default ui-corner-all">View more Excite Trips</li>
      <li class="ui-state-default ui-corner-all"><a href="{$_SERVER['PHP_SELF']}?show=0">5</a></li>
      <li class="ui-state-default ui-corner-all"><a href="{$_SERVER['PHP_SELF']}?show=5">10</a></li>
      <li class="ui-state-default ui-corner-all"><a href="{$_SERVER['PHP_SELF']}?show=15">20</a></li>
      <li class="ui-state-default ui-corner-all"><a href="{$_SERVER['PHP_SELF']}?show=45">50</a></li>
    </ul>
  </div>
</div>
<!--
    <p class="admin_link">
      <a href="{$_SERVER['PHP_SELF']}?admin=1">Add a New Entry</a>
      <a href="{$_SERVER['PHP_SELF']}?show=0">Show 5</a>
      <a href="{$_SERVER['PHP_SELF']}?show=5">Show 10</a>
      <a href="{$_SERVER['PHP_SELF']}?show=15">Show 20</a>
      <a href="{$_SERVER['PHP_SELF']}?show=35">Show 40</a>
      <a href="{$_SERVER['PHP_SELF']}?show=45">Show 50</a>
      <a href="{$_SERVER['PHP_SELF']}?next_end=2">Next</a>
    </p>
    -->

ADMIN_OPTION;

    return $entry_display;
  }

  public function display_admin() {
    return <<<ADMIN_FORM

<form action="{$_SERVER['PHP_SELF']}" method="post" >
            <div id="tour-package" >
              <ul>
                <li><a href="#genral">General Information</a></li>
                <li><a href="#picture">Picture And Meta Info</a></li>
                <li><a href="#tour-inclusions">Tour Inclusions</a></li>
                <li><a href="#tour-feature">Itinerary</a></li>
                <!--<li><a href="#availibility">Availability and Others</a></li>-->
                <li><a href="#billing">Billing And Prices</a></li>
              </ul>
              <div id="genral">
                <div class="package-element">
                  <p><span class="left" >Tour Name: <input type="text" name="tour_name" id="tour_name" /></span></p>
                </div>
                <div class="package-element">
                  <p>Tour Type:
                    <select id="tour_type" name="tour_type" >
                      <option value="null-category" checked="checked" >Select Tour Type</option>
                      <option value="international" >International Tours</option>
                      <option value="domestic" > Domestic Tours </option>
                      <option value="insta_deals" >Insta Deals</option>
                    </select>
                  </p>
                </div>
                <div class="package-element">
                  <p>No. of Days: 
                    <input type="text" size="2" id="day" name="day" />
                  </p>
                </div>
                <div class="package-element">
                  <p> No. of Nights:
                    <input type="text" name="nights" id="nights" size="2" />
                  </p>
                </div>
                <div class="package-element" >
                  <p> Sub categories 
                    <input type="text" name="tour_type" id="tour_type" size="5" />
                  </p>
                </div>
                <div class="package-element">
                  <div class="package-element-head">
                    <p>Overview of the package :</p>
                  </div>  <br />
                  <div class="package-element">
                    <textarea rows="10" cols="70" id="overview" name="overview" ></textarea>
                  </div>
                </div>
                <div class="cleaner"></div><br />
              </div>
              <div id="picture" >
                <div class="chavi" >
                  <div class="package-element-head" >
                    <p>Pictures To upload (.jpg, .png) :</p>
                  </div>
                  <div class="cleaner"></div>
                  <div class="chavi-element" >
                    <span class="left">1st Image</span><span class="right"><input type="file" accept ="image/gif, image/jpeg" name="pic1" id="pic1" /></span>
                  </div>
                  <div class="chavi-element" >
                    <span class="left">2nd Image</span><span class="right"><input type="file" accept ="image/gif, image/jpeg" name="pic2" id="pic2" /></span>
                  </div>
                  <div class="chavi-element">
                    <span class="left" > 3rd Image</span><span class="right"><input type="file" accept ="image/gif, image/jpeg" name="pic3" id="pic3" /></span>
                  </div>
                  <div class="chavi-element" >
                    <span class="left" >4th Image</span><span class="right"><input type="file" accept ="image/gif, image/jpeg" name="pic4" id="pic4" /></span>
                  </div>
                  <div class="chavi-element" >
                    <span class="left" >5th Image</span><span class="right"><input type="file" accept ="image/gif, image/jpeg" name="pic5" id="pic5" /></span>
                  </div>
                </div>
                <div class="meta-info">
                  <div class="package-element-head" >
                    <p>Title:</p>
                  </div>
                  <div class="package-element" >
                    <input type="text" size="30" id="title" name="title" />
                  </div>
                  <div class="package-element-head-2" >
                  Keywords:
                  </div>
                  <div class="package-element" >
                    <textarea rows="5" cols="28" id="keywords" name="keywords" ></textarea>
                  </div>
                </div>
                <div class="meta-info" >
                  <div class="package-element-head" >
                    Description:
                  </div>
                  <div class="package-element" >
                    <textarea rows="5" cols="30" name="description" id="description"></textarea>
                  </div>
                  <div class="package-element-head-2" >
                    URL of the page:
                  </div>
                  <div class="package-element" >
                    <input type="text" size="30" name="url" id="url" onblur="this.value=removeSpaces(this.value);" />
                  </div>
                </div>
                <div class="cleaner"></div>
              </div>
              <div id="tour-inclusions">
                <div class="inclusions-exclusions">
                  <div class="package-element-head" >
                  Inclusions:
                  </div>
                  <div class="package-element" >
                    <textarea rows="10" cols="70" name="inclusions" id="inclusions"></textarea>
                  </div>
                </div>
                <div class="inclusions-exclusions">
                  <div class="package-element-head" >
                  Exlcusions:
                  </div>
                  <div class="package-element">
                    <textarea rows="10" cols=70" name="exclusions" id="exclusions"></textarea>
                  </div>
                </div>
                <div class="cleaner"></div>
              </div>
              <div id="tour-feature">
                <div class="package-element-head">
                  Itinerary:
                </div>
                <div class="package-element" >
                  <textarea rows="30" cols="75" name="itinerary" id="itinerary"></textarea>
                </div> 
                <div class="cleaner"></div>
              </div>
              <!--<div id="availability">availibility</div>-->
              <div id="billing">
                <div class="price-tab" >
                        <div class="price-tab-row" >
                            <div class="price-tab-element">
                              <b>Pax Type</b>
                            </div>
                            <div class="price-tab-element">
                              <b>Tour Price Total in INR</b>
                            </div>
                        </div>
                        <div class="price-tab-row" >
                            <div class="price-tab-element" >
                              Twin/Triple Sharing
                            </div>
                            <div class="price-tab-element" >
                              <span class="rupee">`</span> <input typ="text" size="7" name="twin_triple_sharing" id="twin_triple_sharing" />
                            </div>
                        </div>
                        <div class="price-tab-row" >
                            <div class="price-tab-element" >
                              Single Occupancy 
                            </div>
                            <div class="price-tab-element" >
                              <span class="rupee">`</span> <input type="text" size="7" name="single_occcupancy" id="single_occcupancy" />
                            </div>
                        </div>
                        <div class="price-tab-row">
                            <div class="price-tab-element" >
                              Child With No Bed
                            </div>
                            <div class="price-tab-element">
                              <span class="rupee" >`</span> <input type="text" size="7" name="child_with_no_bed" id="child_with_no_bed" />
                            </div>
                        </div>
                        <div class="price-tab-row">
                            <div class="price-tab-element">
                              Infant below 2 years
                            </div>
                            <div class="price-tab-element" >
                              <span class="rupee" >`</span> <input type="text" size="7" name="inf_below" id="inf_below" />
                            </div>
                        </div>
                        <div class="package-element-head-2">Pricing Details:</div>
                        <div class="cleaner"></div>
                        <div class="package-element" >
                          <textarea rows="10" cols="70" id="pricing_details" name="pricing_details" ></textarea>
                        </div>
                        <input type="submit" id="submit" value="Create This Entry!" />
                        <div class="cleaner" ></div>
                      </div> 
              </div>
            </div>
          </form>
<!--
    <form action="{$_SERVER['PHP_SELF']}" method="post">
    
      <label for="title">Title:</label><br />
      <input name="title" id="title" type="text" maxlength="150" />
      <div class="clear"></div>
     
      <label for="bodytext">Body Text:</label><br />
      <textarea name="bodytext" id="bodytext"></textarea>
      <div class="clear"></div>
-->  
    </form>
    <br />
    </div>

ADMIN_FORM;
  }

  public function write($p) {
    if ( $_POST['tour_name'] )
      $tour_name = mysql_real_escape_string($_POST['tour_name']);
    if ( $_POST['day'])
      $day = mysql_real_escape_string($_POST['day']);
    if ( $_POST['nights'] )
      $nights = mysql_real_escape_string($_POST['nights']);
    if ( $_POST['tour_price'] )
      $tour_price = mysql_real_escape_string($_POST['tour_price']);
    if ( $_POST['overview'] )
      $overview = mysql_real_escape_string($_POST['overview']);
    if ( $_POST['terms_conditons'] )
       $terms_conditons = mysql_real_escape_string($_POST['terms_conditons']);
    if ( $_POST['inclusions'] )
      $inclusions = mysql_real_escape_string($_POST['inclusions']);
    if ( $_POST['exclusions'] )
      $exclusions = mysql_real_escape_string($_POST['exclusions']);
    if ( $_POST['twin_triple_sharing'] )
      $twin_triple_sharing = mysql_real_escape_string($_POST['twin_triple_sharing']);
    if ( $_POST['single_occcupancy'])
      $single_occcupancy = mysql_real_escape_string($_POST['single_occcupancy']);
    if ( $_POST['child_with_no_bed'] )
      $child_with_no_bed = mysql_real_escape_string('child_with_no_bed');
    if ( $_POST['pricing_details'] )
      $pricing_details = mysql_real_escape_string('pricing_details');
    if ( $tour_name && $day && $nights && $tour_price && $overview && $terms_conditons && $inclusions && $exclusions && $twin_triple_sharing && $single_occcupancy && $child_with_no_bed && $pricing_details) {
     // $created = time();
      $sql = "INSERT INTO tourDB 
        (tour_name, day, nights, tour_price, overview, itinerary, terms_conditons, inclusions, exclusions, twin_triple_sharing, single_occcupancy, child_with_no_bed, inf_below, pricing_details)
      VALUES('$tour_name','$day', '$nights', '$tour_price', '$overview', '$itinerary', '$terms_conditons', '$inclusions', '$exclusions', '$twin_triple_sharing', '$single_occcupancy', '$child_with_no_bed', '$inf_below', '$pricing_details')";
        return mysql_query($sql) or die(mysql_error());
    } else {
      return false;
    }
  }

  public function connect() {
    mysql_connect($this->host,$this->username,$this->password) or die("Could not connect. " . mysql_error());
    mysql_select_db($this->table) or die("Could not select database. " . mysql_error());

    return $this->buildDB();
  }

  private function buildDB() {
    $sql = <<<MySQL_QUERY
CREATE TABLE IF NOT EXISTS tourDB (
  tour_id                       INTEGER                        NOT NULL    AUTO_INCREMENT,
  tour_type                     INTEGER                        NOT NULL,
  tour_name                     VARCHAR(255)                   NOT NULL,
  day                           INTEGER                        NOT NULL,
  nights                        INTEGER                        NOT NULL,
  tour_price                    VARCHAR(25)                    NOT NULL,
  overview                      TEXT                           NOT NULL,
  itinerary                     TEXT                           NOT NULL,
  terms_conditons               TEXT                           NOT NULL,
  inclusions                    TEXT                           NOT NULL,
  exclusions                    TEXT                           NOT NULL,
  twin_triple_sharing           INTEGER                        NOT NULL,
  single_occcupancy             INTEGER                        NOT NULL,
  child_with_no_bed             INTEGER                        NOT NULL,
  inf_below                     INTEGER                        NOT NULL,
  pricing_details               TEXT,
  keywords                      VARCHAR(155)                   NOT NULL,
  title                         VARCHAR(25)                    NOT NULL,
  description                   VARCHAR(136)                   NOT NULL,

  PRIMARY KEY (tour_id)
  )
  ENGINE="MyISLAM"
MySQL_QUERY;

    return mysql_query($sql) or die(mysql_error());
  }

}

?>

thanks in advance :)

Link to comment
https://forums.phpfreaks.com/topic/282630-problems-with-submitting-data-to-mysql/
Share on other sites

if ( $_POST )

will always return true. To see if post data has been sent you'll want to check the $_SERVER['REQUEST_METHOD']

 

You'll also want to check that $obj->write($_POST); returned false. This method returns false when no data has been added to the database

 

So change

if ( $_POST )
    $obj->write($_POST);

to

if ( $_SERVER['REQUEST_METHOD'] == 'POST') {
    if($obj->write($_POST) === false) {
        echo 'Sorry, no data added to database';
    } else {
        echo 'data has been added to database';
    }
}

thank you  :happy-04:  the post data was shown and there was some problem with in the $obj->write() method, just to test it , i just rewrote it for just one column .  It works and pushes the data into the database. , still though it not retrieving the data. i will get back to that once i wrote the full $obj->write() method. 

Archived

This topic is now archived and is closed to further replies.

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