Jump to content

Help with MEDIUMBLOB update php script ?


Go to solution Solved by Ch0cu3r,

Recommended Posts

is my function of updating medium blobs is correct ???

public function transact_pic_1( $u ) {
		if ( isset( $_POST[ 'edit' ] ) && $_FILES[ 'pic1' ][ 'size' ] > 0 ) {
			$pic_1_name      = $_FILES[ 'pic1' ][ 'name' ];
			$pic_1_tmp_name  = $_FILES[ 'pic1' ][ 'tmp_name' ];
			$pic_1_file_size = $_FILES[ 'pic1' ][ 'size' ];
			$pic_1_file_type = $_FILES[ 'pic1' ][ 'type' ];
			$image_date_1    = @date( 'Y-m-d' );
			$pic_1_fp        = fopen( $pic_1_tmp_name, 'r' );
			$pic_1_content   = fread( $pic_1_fp, filesize( $pic_1_tmp_name ) );
			$pic_1_content   = addslashes( $pic_1_content );
			fclose( $pic_1_fp );
			if ( !get_magic_quotes_gpc() ) {
				$pic_1_name = addslashes( $pic_1_name );
			} //!get_magic_quotes_gpc()
			if ( $_FILES[ 'pic1' ][ 'error' ] != UPLOAD_ERR_OK ) {
				switch ( $_FILES[ 'pic1' ][ 'error' ] ) {
					case UPLOAD_ERR_INI_SIZE:
						die( 'The uploaded 1st image exceeds the upload_max_filesize directive ' . 'in php.ini.' );
						break;
					case UPLOAD_ERR_FORM_SIZE:
						die( 'The uploaded 1st exceeds the MAX_FILE_SIZE directive that ' . 'was specified in the HTML form.' );
						break;
					case UPLOAD_ERR_PARTIAL:
						die( 'The uploaded 1st image was only partially uploaded.' );
						break;
					case UPLOAD_ERR_NO_FILE:
						die( 'No 1st image was uploaded.' );
						break;
					case UPLOAD_ERR_NO_TMP_DIR:
						die( 'The server is missing a temporary folder.' );
						break;
					case UPLOAD_ERR_CANT_WRITE:
						die( 'The server failed to write the uploaded the uploaded 1st image to disk.' );
						break;
					case UPLOAD_ERR_EXTENSION:
						die( '1st image upload stopped by extension.' );
						break;
				} //$_FILES[ 'pic1' ][ 'error' ]
			} //$_FILES[ 'pic1' ][ 'error' ] != UPLOAD_ERR_OK
				$sql = "UPDATE tourDB
    SET
    pic_1_name = '$pic_1_name',
    pic_1_file_size = '$pic_1_file_size',
    pic_1_file_type = '$pic_1_file_type',
    pic_1_content = '$pic_1_content',
    image_date_1 = '$image_date_1'
    WHERE
    tour_id = '$tour_id'";
    $result = mysql_query( $sql ) or die( mysql_error() );
    if ( $result && mysql_affected_rows( $result ) != 0 ) {
      return true;
    } //$result && mysql_affected_rows( $result ) != 0
    else {
      return false;
    }

because i cant seem to upload images to this ..

 

i call out the function by this :

if ( $_POST[ 'edit' ] ) {
  $obj->transact_pic_1( $_POST[ 'edit' ] );
} 

the image is being uploaded but it is not being updated in the coloumn of  mediumblob. :/

Link to comment
https://forums.phpfreaks.com/topic/283130-help-with-mediumblob-update-php-script/
Share on other sites

Where is the variable $tour_id defined? You're using this variable in your query to only update the picture where the tour_id matches it.

$sql = "UPDATE tourDB
    SET
    pic_1_name = '$pic_1_name',
    pic_1_file_size = '$pic_1_file_size',
    pic_1_file_type = '$pic_1_file_type',
    pic_1_content = '$pic_1_content',
    image_date_1 = '$image_date_1'
    WHERE
    tour_id = '$tour_id'";  //<-- $tour_id is not defined anywhere

How can the database update a record based on a value you're not defining?

 

Also storing the actual image within the database is not recommended. Only store the path to the image and save the image to file system.

Edited by Ch0cu3r

I did that, id defined it,

here is the function..

public function transact_pic_1( $u ) {
  if ( $_POST[ 'tour_id' ] )
    $tour_id = mysql_real_escape_string( $_POST[ 'tour_id' ] );
  if ( isset( $_POST[ 'edit' ] ) && $_FILES[ 'pic1' ][ 'size' ] > 0 ) {
   $pic_1_name      = $_FILES[ 'pic1' ][ 'name' ];
   $pic_1_tmp_name  = $_FILES[ 'pic1' ][ 'tmp_name' ];
   $pic_1_file_size = $_FILES[ 'pic1' ][ 'size' ];
   $pic_1_file_type = $_FILES[ 'pic1' ][ 'type' ];
   $image_date_1    = @date( 'Y-m-d' );
   $pic_1_fp        = fopen( $pic_1_tmp_name, 'r' );
   $pic_1_content   = fread( $pic_1_fp, filesize( $pic_1_tmp_name ) );
   $pic_1_content   = addslashes( $pic_1_content );
   fclose( $pic_1_fp );
   if ( !get_magic_quotes_gpc() ) {
    $pic_1_name = addslashes( $pic_1_name );
   } //!get_magic_quotes_gpc()
   if ( $_FILES[ 'pic1' ][ 'error' ] != UPLOAD_ERR_OK ) {
    switch ( $_FILES[ 'pic1' ][ 'error' ] ) {
     case UPLOAD_ERR_INI_SIZE:
      die( 'The uploaded 1st image exceeds the upload_max_filesize directive ' . 'in php.ini.' );
      break;
     case UPLOAD_ERR_FORM_SIZE:
      die( 'The uploaded 1st exceeds the MAX_FILE_SIZE directive that ' . 'was specified in the HTML form.' );
      break;
     case UPLOAD_ERR_PARTIAL:
      die( 'The uploaded 1st image was only partially uploaded.' );
      break;
     case UPLOAD_ERR_NO_FILE:
      die( 'No 1st image was uploaded.' );
      break;
     case UPLOAD_ERR_NO_TMP_DIR:
      die( 'The server is missing a temporary folder.' );
      break;
     case UPLOAD_ERR_CANT_WRITE:
      die( 'The server failed to write the uploaded the uploaded 1st image to disk.' );
      break;
     case UPLOAD_ERR_EXTENSION:
      die( '1st image upload stopped by extension.' );
      break;
    } //$_FILES[ 'pic1' ][ 'error' ]
   } //$_FILES[ 'pic1' ][ 'error' ] != UPLOAD_ERR_OK
   $sql = "UPDATE tourDB
    SET
    pic_1_name = '$pic_1_name',
    pic_1_file_size = '$pic_1_file_size',
    pic_1_file_type = '$pic_1_file_type',
    pic_1_content = '$pic_1_content',
    image_date_1 = '$image_date_1'
    WHERE
    tour_id = '$tour_id'";
   $result = mysql_query( $sql ) or die( mysql_error() );
   if ( $result && mysql_affected_rows( $result ) != 0 ) {
    return true;
   } //$result && mysql_affected_rows( $result ) != 0
   else {
    return false;
   }
  } //isset( $_POST[ 'submit' ] ) && $_FILES[ 'pic1' ][ 'size' ] > 0
 }

here is the form i use for getting the tour id.. 

public function edit_package( ) {
  $id = $_GET[ 'id' ];
  $q  = "SELECT * FROM tourDB WHERE tour_id = '$id' ";
  $r  = mysql_query( $q );
  if ( $r !== false && mysql_num_rows( $r ) > 0 ) {
   while ( $mfa = mysql_fetch_assoc( $r ) ) {
    $tour_id             = stripslashes( $mfa[ 'tour_id' ] );
    $tour_type           = stripslashes( $mfa[ 'tour_type' ] );
    $tour_name           = stripslashes( $mfa[ 'tour_name' ] );
    $day                 = stripslashes( $mfa[ 'day' ] );
    $nights              = stripslashes( $mfa[ 'nights' ] );
    $tour_price          = stripslashes( $mfa[ 'tour_price' ] );
    $overview            = stripslashes( $mfa[ 'overview' ] );
    $itinerary           = stripslashes( $mfa[ 'itinerary' ] );
    $terms_conditons     = stripslashes( $mfa[ 'terms_conditons' ] );
    $inclusions          = stripslashes( $mfa[ 'inclusions' ] );
    $exclusions          = stripslashes( $mfa[ 'exclusions' ] );
    $twin_triple_sharing = stripslashes( $mfa[ 'twin_triple_sharing' ] );
    $single_occcupancy   = stripslashes( $mfa[ 'single_occcupancy' ] );
    $child_with_no_bed   = stripslashes( $mfa[ 'child_with_no_bed' ] );
    $inf_below           = stripslashes( $mfa[ 'inf_below' ] );
    $pricing_details     = stripslashes( $mfa[ 'pricing_details' ] );
    $url                 = stripslashes( $mfa[ 'url' ] );
    $keywords            = stripslashes( $mfa[ 'keywords' ] );
    $title               = stripslashes( $mfa[ 'title' ] );
    $description         = stripslashes( $mfa[ 'description' ] );
    $categories          = stripslashes( $mfa[ 'categories' ] );
    $image_alt_1         = stripslashes( $mfa[ 'image_alt_1' ] );
    $image_alt_2         = stripslashes( $mfa[ 'image_alt_2' ] );
    $image_alt_3         = stripslashes( $mfa[ 'image_alt_3' ] );
    $image_alt_4         = stripslashes( $mfa[ 'image_alt_4' ] );
    $image_alt_5         = stripslashes( $mfa[ 'image_alt_5' ] );
    if ( $tour_type == 'international' ) {
     $option1 = 'selected';
    } //$tour_type == 'international'
    elseif ( $tour_type == 'domestic' ) {
     $option2 = 'selected';
    } //$tour_type == 'domestic'
     elseif ( $tour_type == 'insta_deals' ) {
     $option3 = 'selected';
    } //$tour_type == 'insta_deals'
    else {
     $option = 'selected';
    }
    $edit_package = <<<EDIT_PACKAGE
<form action="{$_SERVER['PHP_SELF']}" method="post" enctype="multipart/form-data">
<script type="text/javascript" >
          $(function new_editor() {
           $('#transportation_$tour_id').wysiwyg({
              autoGrow: true,
              initialContent: "<p>Transportation Content</p>",
              maxHeight: 600
           });
          $('#payment-norms_$tour_id').wysiwyg({ 
              autoGrow: true,
              initialContent: "<p>Payment Content</p>",
              maxHeight: 600
          });
          $('#overview_$tour_id').wysiwyg({
              autoGrow: true,
              initialContent: "$overview",
              maxHeight: 600
          });
          $('#inclusions_$tour_id').wysiwyg({
              autoGrow: true,
              initialContent: "$inclusions",
              maxHeight: 600
          });
          $('#exclusions_$tour_id').wysiwyg({
              autoGrow: true,
              initialContent: "$exclusions",
              maxHeight: 600
          });
          $('#itinerary_$tour_id').wysiwyg({
              autoGrow: true,
              initialContent: "$itinerary",
              maxHeight: 600
          });
          $('#pricing_details_$tour_id').wysiwyg({
              autoGrow: true,
              initialContent: "$pricing_details",
            maxHeight: 600
          });
      });
          </script>
            <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">
                <input type="hidden" name="tour_id" value="$id" />
                <div class="package-element">
                  <p><span class="left" >Tour Name: <input type="text" name="tour_name" value= "$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" $option >Select Tour Type</option>
                      <option value="international" $option1 >International Tours</option>
                      <option value="domestic" $option2 > Domestic Tours </option>
                      <option value="insta_deals" $option3 >Insta Deals</option>
                    </select>
                  </p>
                </div>
                <div class="package-element">
                  <p>No. of Days: 
                    <input type="text" size="2" id="day" value="$day" name="day" />
                  </p>
                </div>
                <div class="package-element">
                  <p> No. of Nights:
                    <input type="text" name="nights" value="$nights" id="nights" size="2" />
                  </p>
                </div>
                <div class="package-element" >
                  <p> Sub categories 
                    <input type="text" name="categories" value="$categories" id="categories" 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" value="" id="overview_$tour_id" 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="left"><input type="file" accept ="image/gif, image/jpeg" name="pic1" id="pic1" /></span>
                      <span class="right" ><input  value="$image_alt_1" id="alt1" name="alt1" type="text" size="20" />
                      </span><span class="right">Alt of 1st image  </span>
                    </div>
                  <div class="chavi-element" >
                    <span class="left">2nd Image </span>
                    <span class="left"><input type="file" accept ="image/gif, image/jpeg" name="pic2" id="pic2" /></span>
                    <span class="right"><input value="$image_alt_2" name="alt2" id="alt2" type="text size="20" /></span>
                    <span class="right">Alt of 2nd image  </span>
                  </div>
                  <div class="chavi-element">
                    <span class="left" > 3rd Image</span>
                    <span class="left"><input type="file" accept ="image/gif, image/jpeg" name="pic3" id="pic3" /></span>
                    <span class="right" ><input value="$image_alt_3" name="alt3" id="alt3" type="text" size="20" /></span>
                    <span class="right" >Alt of 3rd image  </span> 
                  </div>
                  <div class="chavi-element" >
                    <span class="left" >4th Image</span>
                    <span class="left"><input type="file" accept ="image/gif, image/jpeg" name="pic4" id="pic4" /></span>
                    <span class="right"><input name="alt4" value="$image_alt_4" id="alt4" type="text" size="20" /></span>
                    <span class="right">Alt of 4th image  </span>
                  </div>
                  <div class="chavi-element" >
                    <span class="left" >5th Image</span>
                    <span class="left"><input type="file" accept ="image/gif, image/jpeg" name="pic5" id="pic5" /></span>
                    <span class="right"><input type="text" value="$image_alt_5" name="alt5" id="alt5" size="20" /></span>
                    <span class="right">Alt of 5th image  </span>
                  </div>
                </div>
                <div class="meta-info">
                  <div class="package-element-head" >
                    <p>Title:</p>
                  </div>
                  <div class="package-element" >
                    <input type="text" value="$title" size="30" id="title" name="title" />
                  </div>
                  <div class="package-element-head-2" >
                  Keywords:
                  </div>
                  <div class="package-element" >
                    <textarea rows="5" value="$keywords" cols="28" id="keywords" name="keywords" >$keywords</textarea>
                  </div>
                </div>
                <div class="meta-info" >
                  <div class="package-element-head" >
                    Description:
                  </div>
                  <div class="package-element" >
                    <textarea rows="5" cols="30" value="$description" name="description" id="description">$description</textarea>
                  </div>
                  <div class="package-element-head-2" >
                    URL of the page:
                  </div>
                  <div class="package-element" >
                    <input type="text" size="30" value="$url" 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_$tour_id"></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_$tour_id"></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_$tour_id"></textarea>
                </div> 
                <div class="cleaner"></div>
              </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" value="$twin_triple_sharing" 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" value=" $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" value="$child_with_no_bed" 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" value="$inf_below" size="7" name="inf_below" id="inf_below" />
                            </div>
                        </div>
                        <div class="package-element-head-2">Terms And Conditions:</div>
                        <div class="cleaner"></div>
                        <div class="package-element" >
                          <textarea rows="10" cols="70" id="pricing_details_$tour_id" name="terms_conditons" ></textarea>
                        </div>
                        <input type="submit" name="edit" id="submit" value="Create This Entry!" />
                        <div class="cleaner" ></div>
                      </div> 
              </div>
            </div>
          </form>

    </form>
    <br />
    </div>

EDIT_PACKAGE;
   } //$mfa = mysql_fetch_assoc( $r )
  } //$r !== false && mysql_num_rows( $r ) > 0
  else {
   echo 'invalid package !!';
  }

hopefully i could get the $_POST['tour_id'] via a hidden input <input type="hidden" name="tour_id" value="$id" /> isn't it ??

 

it's still not updating my MEDIUMBLOBS  :confused: ....

 

---EDITED--

 

okay its working although its giving me errors 

 

"Warning: mysql_affected_rows() expects parameter 1 to be resource, boolean given in/localhost/ssl/_class/tourCMS.php on line 2582

"

 

what does it means ???

Edited by cyber_alchemist

"Warning: mysql_affected_rows() expects parameter 1 to be resource, boolean given in........"

 

so does it mean that the variable,

 

 $result = mysql_query( $sql ) or die( mysql_error() );

 

is a boolean , and that i am putting it in mysql_affected_rows() which expects it to be resource ??? as

 

$result = mysql_query( $sql ); ????

 

Remove   $result from    mysql_affected_rows( $result ).

if ( $result && mysql_affected_rows() != 0 ) {

 

Ch0cu3r, good catch. I assumed the issue was with the query failing and $result was FALSE - but the mysql_affected_rows() take an optiona parameter of the mysql link resource - not the result source.

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.