必须提交表单两次/三次更新/插入到mysql中

时间:2014-06-22 20:17:19

标签: php mysql

我的process.php中有这段代码。但是,我要提交表单两次甚至有时三次更新/插入mysql数据库中的数据。有人可以告诉我纠正我在这里所犯错误的方法吗?

    <?php
ini_set("display_errors",1);
if(isset($_POST))
{
require '../_inc/db.php';


$Destination = '../uploads';
if(!isset($_FILES['ImageFile']) || !is_uploaded_file($_FILES['ImageFile']['tmp_name']))
{
    //die('Something went wrong with Upload!');
    $NewImageName= 'default.png';

    move_uploaded_file($_FILES['ImageFile']['tmp_name'], "$Destination/$NewImageName");
}
else{
$RandomNum   = rand(0, 9999999999);

$ImageName      = str_replace(' ','-',strtolower($_FILES['ImageFile']['name']));
$ImageType      = $_FILES['ImageFile']['type']; //"image/png", image/jpeg etc.

$ImageExt = substr($ImageName, strrpos($ImageName, '.'));
$ImageExt = str_replace('.','',$ImageExt);

$ImageName      = preg_replace("/\.[^.\s]{3,4}$/", "", $ImageName);

//Create new image name (with random number added).
$NewImageName = $ImageName.'-'.$RandomNum.'.'.$ImageExt;

move_uploaded_file($_FILES['ImageFile']['tmp_name'], "$Destination/$NewImageName");
}


require 'authenticationforupload.php';

$user_firstname=$_REQUEST['user_firstname'];
$user_lastname=$_REQUEST['user_lastname'];
$user_email=$_REQUEST['user_email'];
$user_username=$_REQUEST['user_username'];
$user_password=$_REQUEST['user_password'];
    $user_profession=$_REQUEST['user_profession'];
    $user_address=$_REQUEST['user_address'];
$user_shortbio=$_REQUEST['user_shortbio'];   
$user_longbio=$_REQUEST['user_longbio'];   
$user_dob=$_REQUEST['user_dob'];
$user_gender=$_REQUEST['user_gender'];
$user_country=$_REQUEST['user_country'];
$user_website=$_REQUEST['user_website'];
$user_facebook=$_REQUEST['user_facebook'];
$user_twitter=$_REQUEST['user_twitter'];
$user_googleplus=$_REQUEST['user_googleplus'];
$user_skype=$_REQUEST['user_skype'];
$user_github=$_REQUEST['user_github'];
$user_youtube=$_REQUEST['user_youtube'];
$user_vimeo=$_REQUEST['user_vimeo'];
$user_pinterest=$_REQUEST['user_pinterest'];
$user_profilebackgroundcolor=$_REQUEST['user_backgroundcolor'];
$user_profilefontcolor=$_REQUEST['user_profilefontcolor'];
  $sql1="UPDATE user SET user_firstname='$user_firstname',user_lastname='$user_lastname',user_profession='$user_profession',user_address='$user_address',user_avatar='$NewImageName',user_email='$user_email',user_username='$user_username',user_password='$user_password',user_shortbio='$user_shortbio',user_longbio='$user_longbio',user_dob='$user_dob',user_gender='$user_gender',user_country='$user_country',user_website='$user_website',user_facebook='$user_facebook',user_twitter='$user_twitter',user_googleplus='$user_googleplus',user_skype='$user_skype',user_github='$user_github',user_youtube='$user_youtube',user_vimeo='$user_vimeo',user_pinterest='$user_pinterest',user_backgroundcolor='$user_profilebackgroundcolor',user_profilefontcolor='$user_profilefontcolor' WHERE user_username = '$user_username'";


$sql2="INSERT INTO user (user_firstname,user_lastname,user_username,user_email,user_password,user_shortbio,user_longbio,user_dob,user_gender,user_country,user_website,user_facebook,user_googleplus,user_twitter,user_skype,user_github,user_youtube,user_vimeo,user_pinterest,user_backgroundcolor,user_profilefontcolor,user_profession,user_address,user_avatar) VALUES ('$user_firstname','$user_lastname','$user_username','$user_email','$user_password','$user_shortbio','$user_longbio','$user_dob','$user_gender','$user_country','$user_website','$user_facebook','$user_googleplus','$user_twitter','$user_skype','$user_github','$user_youtube','$user_vimeo','$user_pinterest','$user_profilebackgroundcolor','$user_profilefontcolor',user_profession','$,user_address','$,user_NewImageName') WHERE user_username = '$user_username'";

$result = mysql_query("SELECT * FROM user WHERE user_username = '$user_username'");
if( mysql_num_rows($result) > 0) {
mysql_query($sql1)or die(mysql_error());
}
else{
mysql_query($sql2)or die(mysql_error());
}  
}    




?>

0 个答案:

没有答案