how can i change this from insert to modify

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lisa007
    New Member
    • Apr 2010
    • 29

    #1

    how can i change this from insert to modify

    how can i change this which insert into the database to display and modify i then resave back into the database


    Code:
    if(!empty($_POST['select1']) && $_POST['select1'] != 'default')
    $value = mysql_real_escape_string($_POST['select1']);
    elseif(!empty($_POST['select2']) && $_POST['select2'] != 'default')
    $value = mysql_real_escape_string($_POST['select2']);
    elseif(!empty($_POST['select3']) && $_POST['select3'] != 'default')
    $value = mysql_real_escape_string($_POST['select3']);
    
    
    
        
        if ($_POST['name']=='')
            $arrErrors['name'] = 'Please provide your name.';
        if ($_POST['email']=='')
            $arrErrors['email'] = 'A valid email address is required.';
        if ($_POST['phone']=='')
            $arrErrors['phone'] = 'Please provide your phone number.';
            
            
            if ($_POST['campustype']=='')
            $arrErrors['campustype'] = 'Please select category.';
            
            
            
            
              if ($_POST['select1'] === 'default' && $_POST['select2'] === 'default' && $_POST['select3'] === 'default'){
                    $arrErrors[howt] = 'Please select type';
            }else{
                    $possible = array('Concerts', 'Clubs', 'Festival', 'Opera');
                    if (in_array($_POST['select1'], $possible) === false){
                    }
                   
                    $possible = array('Formula 1', 'Footbal', 'Basketball', 'Rugby', 'Cricket');
                    if (in_array($_POST['select2'], $possible) === false){
                    }
                   
                    $possible = array('Comedy', 'Drama', 'Museus');
                    if (in_array($_POST['select3'], $possible) === false){
                            
                 }
            
            }
        if (count($arrErrors) == 0)
    
    
    $query="INSERT INTO photos values ('','$image','$name','$email','$phone','$campustype','$value')"; //into database
                mysql_query( $query );
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    To display a database record, you use the SELECT query. To be able to modify the data from the select query, print it into a <form> element. To update the record with the modified data, have the <form> element submit the modified data to a PHP page and use a UPDATE query to update the database.

    Comment

    • lisa007
      New Member
      • Apr 2010
      • 29

      #3
      i did try but the proble is that the part wher it says copy image to the images folders doesnt get to copy no longer do i change copy with uptdate too or something

      Code:
      	$image=$_FILES['image']['name'];
      	//if it is not empty
      	if (strlen($image) >= 1)  //////////////////////////////////////////////////////// CHANGED
      	{
      		//get the original name of the file from the clients machine
      		$filename = stripslashes($_FILES['image']['name']);
      		//get the extension of the file in a lower case format
      		$extension = getExtension($filename);
      		$extension = strtolower($extension);
      		//if it is not a known extension, we will suppose it is an error and will not upload the file, otherwize we will do more tests
      		if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif"))
      		{
      			//print error message
      			echo '<h1>Unknown extension!</h1>';
      			$errors=1;
      		}
      		else
      		{
      			//get the size of the image in bytes
      			//$_FILES['image']['tmp_name'] is the temporary filename of the file in which the uploaded file was stored on the server
      			$size=filesize($_FILES['image']['tmp_name']);
      			//compare the size with the maxim size we defined and print error if bigger
      			if ($size > MAX_SIZE*102400)
      			{
      				echo '<h1>You have exceeded the size limit!</h1>';
      				$errors=1;
      			}
      			//we will give an unique name, for example the time in unix time format
      			$image_name=time(). '.'.$extension;
      			//the new name will be containing the full path where will be stored (images folder)
      			$newname="images/".$image;
       
       
       
      			$query="INSERT INTO photos values ('$image','$name','$email','$phone','$campustype','$value')"; //into database
      			mysql_query( $query );
       
       
      			$copied = copy($_FILES['image']['tmp_name'], $newname);
       
       
      			if (!$copied)
      			{
      				echo '<h1>Copy unsuccessfull!</h1>';
      				$errors=1;
      			}
      		}

      Comment

      Working...