When executing mysqlinsert, how does one insert two statements?

Source: Internet
Author: User
Tags unsupported
When executing mysqlinsert, how does one insert two statements? This post was last edited by Eason _________ at 11:25:44

MySQL database

// A mobile phone is used to upload images to the server. However, the insert statement must be executed twice!

// Index. php
 doWork();$i->imageCheck();$sql="insert into json_bbs values('','".$gettitle."','".$getcontent."','".$i->iamgePath."','".time()."','')";mysql_query($sql);?>


// UploadImage. php

 ImageStauts = 'Error! Wrong HTTP method! ';} If (is_array ($ file) & count ($ file)> 0 &&! Empty ($ destination) {$ this-> fileArray = $ file; $ this-> destination_folder = $ destination; $ this-> imageName = $ name; $ this-> imagePathTemp = $ dbPath; $ this-> updateImage = $ update;} else {$ this-> imageStauts = 'initialization failed ';}} /*** start image Upload */function imageStart () {if ($ this-> imageStauts = 1) {$ this-> imageCheck ();} if ($ this-> imageStauts = 1) {$ this-> doWork () ;}}/*** image check work */function imageCheck () {$ file = $ this-> fileAr Ray; // print_r ($ file); if (! Is_uploaded_file ($ file ['tmp _ name']) & $ this-> imageStauts = 1) {$ this-> imageStauts = 'the image does not exist! ';} If (uploadImage: max_file_size <$ file ['size'] & $ this-> imageStauts = 1) {$ this-> imageStauts = 'File too big ';}/* // Check the mime-typeif (! In_array (strtolower ($ file ['type']), $ this-> uptypes) & $ this-> imageStauts = 1) {$ this-> imageStauts = 'unsupported '. $ file ['type']. 'type file ';} * /// prevent php code from being added to the Comment field of the image metadata. // Check $ fileInfo = pathinfo ($ this-> fileArray ['name']) through binary matching. $ fileType = strtolower ($ fileInfo ['extension']); if (! In_array ($ fileType, $ this-> imageType) & $ this-> imageStauts = 1) {$ this-> imageStauts = 'unsupported '. $ fileType. 'type file';} if (! File_exists ($ this-> destination_folder) & $ this-> imageStauts = 1) {mkdir ($ this-> destination_folder, 0777 ); // Set file permissions}/*** start image Upload */function doWork () {$ fileName = $ this-> fileArray ['tmp _ name']; $ fileSize = getimagesize ($ fileName); $ fileInfo = pathinfo ($ this-> fileArray ['name']); $ fileType = strtolower ($ fileInfo ['extension']); $ n =! Empty ($ this-> imageName )? $ This-> imageName: date ("Y_n_d_H_ I _s"); $ destination = $ this-> destination_folder. $ n. '. '. $ fileType; // Local Image path $ this-> imagePathTemp = $ this-> imagePathTemp. $ n. '. '. $ fileType; // path to be saved in the database // upload the image. if the image does not exist, update the existing image if (file_exists ($ destination) & $ this-> imageStauts ===1 & $ this-> updateImage = 0) {$ this-> imageStauts = 'image already exists ';} // upload an image. if an existing image is updated, if ($ this-> imageStauts ===1 & $ this-> updateImage = 1) {$ deleteIMageD Estination = $ this-> destination_folder. $ n; // save the local path of the image, including the file name, but not the image suffix if ($ this-> deleteImage ($ deleteIMageDestination )) {} else {$ this-> imageStauts = 'failed to delete an existing image ';} if (! Move_uploaded_file ($ fileName, $ destination) & $ this-> imageStauts ===1) {$ this-> imageStauts = 'transmission error ';} if ($ this-> imageStauts ===1) {$ this-> iamgePath = $ this-> imagePathTemp; return $ this-> imageStauts ;}} /*** delete image ** @ param $ path save path of image locally * @ return success return 1 failure return 0 */function deleteImage ($ path) {if (! Empty ($ path) {foreach ($ this-> imageType as $ type) {$ _ path = $ path. '. '. $ type; if (file_exists ($ _ path) {// echo $ _ path; if (! Unlink ($ _ path) {$ this-> imageStauts = 'failed to delete an existing image '; return 0 ;}} return 1 ;} else {$ this-> imageStauts = 'image to be deleted path cannot be blank '; return 0 ;}}?>


Reply to discussion (solution)

Please take a look!

Index. php code is just like this?
Is it refreshed again after execution? Jump?

Index. php code is just like this?
Is it refreshed again after execution? Jump?
In addition, the title and content uploaded by js

Index. php code is just like this?
Is it refreshed again after execution? Jump?

If you determine index. php

if($_GET['title']!=''){$sql="insert into json_bbs values('','".$gettitle."','".$getcontent."','".$i->iamgePath."','".time()."','')";mysql_query($sql);}


Only one piece of data is inserted during execution, but the value of $ I-> iamgePath cannot be obtained. $ I-> iamgePath is null.

If this parameter is not determined, the following two pieces of data are inserted:
Id title content images time uid
127 aaa yyyyy 1374722311 0
128 2013_7_25_11_18_32.jpg 1374722312 0


Index. php code is just like this?
Is it refreshed again after execution? Jump?
In addition, the title and content uploaded by js

Title and content from js? How to Pass
Will the script be executed when the js is passed, and the insert statement is executed when the image is submitted and uploaded. So there are two records?


Index. php code is just like this?
Is it refreshed again after execution? Jump?

If you determine index. php

if($_GET['title']!=''){$sql="insert into json_bbs values('','".$gettitle."','".$getcontent."','".$i->iamgePath."','".time()."','')";mysql_query($sql);}


Only one piece of data is inserted during execution, but the value of $ I-> iamgePath cannot be obtained. $ I-> iamgePath is null.

If this parameter is not determined, the following two pieces of data are inserted:
Id title content images time uid
127 aaa yyyyy 1374722311 0
128 2013_7_25_11_18_32.jpg 1374722312 0


You can see that two different operations are inserted.
One of your two actions should be an update action, and the other should be an update action, not an insert action.

So you have a logical problem. it is normal to insert two data records.

Look at your form

Look at your form



Index. php code is just like this?
Is it refreshed again after execution? Jump?
In addition, the title and content uploaded by js

Title and content from js? How to Pass
Will the script be executed when the js is passed, and the insert statement is executed when the image is submitted and uploaded. So there are two records?

Transmitted in json


Look at your form

You give the form to the database ..
Is the form part of the code and js part of the code.



Look at your form

You give the form to the database ..
Is the form part of the code and js part of the code.

Ajax?
Will insert be executed if it is passed in?
The submitted form is executed again.
Isn't it just two pieces of data?


Look at your form


              
     
     
     
     
     
     
     
     
     
     
     

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.