By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,299 Members | 1,228 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,299 IT Pros & Developers. It's quick & easy.

how can i change this from insert to modify

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


Expand|Select|Wrap|Line Numbers
  1. if(!empty($_POST['select1']) && $_POST['select1'] != 'default')
  2. $value = mysql_real_escape_string($_POST['select1']);
  3. elseif(!empty($_POST['select2']) && $_POST['select2'] != 'default')
  4. $value = mysql_real_escape_string($_POST['select2']);
  5. elseif(!empty($_POST['select3']) && $_POST['select3'] != 'default')
  6. $value = mysql_real_escape_string($_POST['select3']);
  7.  
  8.  
  9.  
  10.  
  11.     if ($_POST['name']=='')
  12.         $arrErrors['name'] = 'Please provide your name.';
  13.     if ($_POST['email']=='')
  14.         $arrErrors['email'] = 'A valid email address is required.';
  15.     if ($_POST['phone']=='')
  16.         $arrErrors['phone'] = 'Please provide your phone number.';
  17.  
  18.  
  19.         if ($_POST['campustype']=='')
  20.         $arrErrors['campustype'] = 'Please select category.';
  21.  
  22.  
  23.  
  24.  
  25.           if ($_POST['select1'] === 'default' && $_POST['select2'] === 'default' && $_POST['select3'] === 'default'){
  26.                 $arrErrors[howt] = 'Please select type';
  27.         }else{
  28.                 $possible = array('Concerts', 'Clubs', 'Festival', 'Opera');
  29.                 if (in_array($_POST['select1'], $possible) === false){
  30.                 }
  31.  
  32.                 $possible = array('Formula 1', 'Footbal', 'Basketball', 'Rugby', 'Cricket');
  33.                 if (in_array($_POST['select2'], $possible) === false){
  34.                 }
  35.  
  36.                 $possible = array('Comedy', 'Drama', 'Museus');
  37.                 if (in_array($_POST['select3'], $possible) === false){
  38.  
  39.              }
  40.  
  41.         }
  42.     if (count($arrErrors) == 0)
  43.  
  44.  
  45. $query="INSERT INTO photos values ('','$image','$name','$email','$phone','$campustype','$value')"; //into database
  46.             mysql_query( $query ); 
Apr 26 '10 #1
Share this Question
Share on Google+
2 Replies


Atli
Expert 5K+
P: 5,058
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.
Apr 26 '10 #2

P: 29
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

Expand|Select|Wrap|Line Numbers
  1.     $image=$_FILES['image']['name'];
  2.     //if it is not empty
  3.     if (strlen($image) >= 1)  //////////////////////////////////////////////////////// CHANGED
  4.     {
  5.         //get the original name of the file from the clients machine
  6.         $filename = stripslashes($_FILES['image']['name']);
  7.         //get the extension of the file in a lower case format
  8.         $extension = getExtension($filename);
  9.         $extension = strtolower($extension);
  10.         //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
  11.         if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif"))
  12.         {
  13.             //print error message
  14.             echo '<h1>Unknown extension!</h1>';
  15.             $errors=1;
  16.         }
  17.         else
  18.         {
  19.             //get the size of the image in bytes
  20.             //$_FILES['image']['tmp_name'] is the temporary filename of the file in which the uploaded file was stored on the server
  21.             $size=filesize($_FILES['image']['tmp_name']);
  22.             //compare the size with the maxim size we defined and print error if bigger
  23.             if ($size > MAX_SIZE*102400)
  24.             {
  25.                 echo '<h1>You have exceeded the size limit!</h1>';
  26.                 $errors=1;
  27.             }
  28.             //we will give an unique name, for example the time in unix time format
  29.             $image_name=time(). '.'.$extension;
  30.             //the new name will be containing the full path where will be stored (images folder)
  31.             $newname="images/".$image;
  32.  
  33.  
  34.  
  35.             $query="INSERT INTO photos values ('$image','$name','$email','$phone','$campustype','$value')"; //into database
  36.             mysql_query( $query );
  37.  
  38.  
  39.             $copied = copy($_FILES['image']['tmp_name'], $newname);
  40.  
  41.  
  42.             if (!$copied)
  43.             {
  44.                 echo '<h1>Copy unsuccessfull!</h1>';
  45.                 $errors=1;
  46.             }
  47.         }
Apr 27 '10 #3

Post your reply

Sign in to post your reply or Sign up for a free account.