Jump to content
Larry Ullman's Book Forums

bahaa

Members
  • Posts

    147
  • Joined

  • Last visited

Everything posted by bahaa

  1. Hi all, I need some help validation questions and answers in a survey. I have a survey that can take x number of questions and each questions can have x number of answers. questions 1 answer 1 answer 2 answer3 question 2 answer 1 answer 2 answer3 The questions and their associated answers are coming from the database so I don't know the the values fof each questions and the values of each answer. How do I test to make sure the user selected one answer from each question and get the values? Bahaa,
  2. can you provide us with a print screen to your page so we migh get an idea of what you are trying to achive ? I really don't know what are you trying to do and if your problem with doing it in php or your database design is not good.
  3. When you do an update query, you only include the one you want to update.... You don't incclude all fields in your table every table you do a select or update query.... choose only the one you need to do select on or update.
  4. You use the header to retrive the image if you put the image directory out of the root, but if you don't but it out of the root you don't need to use header to retrive the image, you just do like I show you above.
  5. I don't get an errors when I insert the image name into the database. when you call your image you need to put the path to your image directory and add the variable name that represent the image name in the database. something like this <img src="../upload/<?php echo $image; ?>" width="" height="" alt ="">
  6. I am only inserting the name of the image to the database not the image its self and I upload the image to a folder on the server. I did not show the insert query because it works the same as other insert quiers. You insert the name of the image same any other data you insert to the database. If you need more clarification let me know.
  7. here is the function to validat the file function ValidateUpload($File) { global $mysqli; if(!empty($File)) { $errors = array(); // get the file from user $fileName = basename($File['name']); $tempFilename = $File['tmp_name']; $fileSize = $File['size']; $fileType = strtolower($File['type']); $fileExtension = strtolower(substr(strchr($fileName,'.'), 1)); $imageInfo = getimagesize($tempFilename); $imageInfo = $imageInfo['mime']; $width= $imageInfo[0]; $height = $imageInfo[1]; //Convert all applicable characters to HTML entities $fileName = htmlentities($fileName); $fileType = htmlentities($fileType); //Validate the type.Should be JPEG , PNG Or GIF $allowed = array('image/pjepg', 'image/jpeg', 'image/JPG', 'image/X-PNG', 'image/PNG', 'image/png', 'image/x-png', 'image/gif', 'image/GIF'); if(!in_array($fileType, $allowed)) { $errors[]="<p>إمتداد الملف الذي قمت بتحميله غير مصرح به.</p>"; }// end of if(in_array($_FILES['upload']['type'], $allowed)){ if(!in_array($imageInfo, $allowed)) { $errors[]="<p>- نوع الملف الذي تحاوله رفعه غير معروف.</p>"; } if(!is_numeric($fileSize)) { $errors[]="<p>- الملف الذي تحاول رفعه غير مصرح به.</p>"; } }//End if(!empty($_FILES['upload']['name'])) return $errors; } and this is the function to upload the file function UploadFile($File,$tempFilename, $fileName,$fileExtension) { global $mysqli; if(!empty($File)) { $targetPath = "../uploads/"; if(move_uploaded_file($tempFilename, $targetPath.$fileName)) { if(file_exists($targetPath.$fileName)) { //Generate uniqe file name $Image = uniqid(md5(time())).".".$fileExtension; //Rename the file to an uniqid version rename($targetPath . $fileName, $targetPath . $Image); }//end of if(file_exists($target_path/$filename)){ }//end of if(move_uploaded_file($temp_filename, $target_path.$file_name)){ } //END if(!empty($_FILES['Image']['name'])){ return $Image; } and here is an example of how I use them in my code if(!empty($_FILES['Image']['name'])) { $File = $_FILES['Image']; $errors = ValidateUpload($File); }//End if(!empty($_FILES['upload']['name'])) else { $Image = NULL; } if(!empty($_FILES['Image']['name'])) { $File = $_FILES['Image']['name']; $fileName = basename($_FILES['Image']['name']); $tempFilename = $_FILES['Image']['tmp_name']; $fileExtension = strtolower(substr(strchr($fileName,'.'), 1)); $Image = UploadFile($File,$tempFilename, $fileName,$fileExtension); }//END if(!empty($_FILES['Image']['name']))
  8. You can easily upload a file to a directory and assign the image any name you want, weather a user id or random name. I read the book a long time ago and I don't remember exactly the exaple but I think there was a problem with the uploading script... I guess the image is uploaded without the extenstion and thats why you why try to access it , it doesn't work. I will provide you with a code I use to upload image to a directory. In my case use random name for my image and I save it in the database with the associated record. You don't have to name the image with the user ID and rather than that you can save its name in the database and refer to it by a fk
  9. I know you can add as many as fields to track in a seprate table but I was just curious about the things you want to track. In such site I would not track such things, If i was handling a sensitiv data like banking information and confidential infromation for patient, then I would track who created the record ,when, who edited it, when was edited, who viewed a record and such things.
  10. I had the same problem with my pages and my solution to this was to store any messages I want to pass with a cookie or session and upon submission I do redirect to the same page then I echo my cookie or msg and then set it to null.
  11. What modifications do you can get other than who created the record, updated , what date was created and what date it was updated? I can think of the IP address for the one who made the changes but what other things?? If I was yo go your route I would only make one table not a mod table for each table. What if you have a really larg database like a thousand table, would you make another thousand table to track each table? I think there is no problem with having nullable Fks in your tracking table since(what I think) when fetching the table the nullable fields are skipped so it won't have any effect on the performance.
  12. my table called user not admin, I log users to the admin area based on their access level... I have a table called user_group that has a fk in the user table. users activate thier membership by an activation link sent to thier email upon registration here is the table CREATE TABLE IF NOT EXISTS `user`( UserID INT UNSIGNED AUTO_INCREMENT, UserName VARCHAR(75) NOT NULL, FirstName VARCHAR(60) NOT NULL, LastName VARCHAR(60) NOT NULL, Email VARCHAR(100) NOT NULL, Password CHAR(40) NOT NULL, PasswordLastUpdated timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, Gender CHAR(1), DOB DATE, RegistrationDate DATETIME, LastVisit DATETIME, RegistrationKey VARCHAR(32) NULL, TemporaryPassword VARCHAR(55), IsActivated TINYINT UNSIGNED DEFAULT 0, ReceiveEmail TINYINT UNSIGNED DEFAULT 1, IP CHAR(15), GroupID INT UNSIGNED NOT NULL COMMENT 'Fk to the usergroup', CountryID INT UNSIGNED NOT NULL COMMENT 'Fk to the country table', CONSTRAINT pk_user_UserID PRIMARY KEY(UserID), CONSTRAINT fk_usergroup_user_groupID FOREIGN KEY(GroupID) REFERENCES usergroup(GroupID), CONSTRAINT fk_country_user_countryID FOREIGN KEY(CountryID) REFERENCES country(CountryID), CONSTRAINT ck_user_userName UNIQUE(userName), CONSTRAINT ck_user_userEmail UNIQUE(Email), INDEX(userName), INDEX(FirstName), INDEX(LastName), INDEX(IsActivated) )ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci;
  13. Yes the admin_id is related to those tables but you don't add the admin_id in the table and instread you make those fields fk to the admin_id here is an example of my tables CREATE TABLE IF NOT EXISTS `category`( CategoryID INT UNSIGNED AUTO_INCREMENT, ParentID INT UNSIGNED, Title VARCHAR(120), Description TEXT NULL, Ordering INT UNSIGNED NOT NULL DEFAULT 1, Visible TINYINT DEFAULT 0, CreationDate DATETIME, CreatedBy INT UNSIGNED NOT NULL COMMENT 'Fk to the user table', LastEdited timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, LastEditedBy INT UNSIGNED COMMENT 'Fk to the user table', CONSTRAINT pk_category_CategoryID PRIMARY KEY(CategoryID), CONSTRAINT fk_user_category_CreatedBy FOREIGN KEY(CreatedBy) REFERENCES user(UserID), CONSTRAINT fk_user_category_LastEditedBy FOREIGN KEY(LastEditedBy) REFERENCES user(UserID), CONSTRAINT fk_category_ParentID FOREIGN KEY(ParentID) REFERENCES category(CategoryID) ON DELETE CASCADE, INDEX(Ordering), INDEX(Visible) )ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci;
  14. I am workin on webe site and in my database design i added those fields to my tables CreationDate, LastEdited, CreatedBy and LastEditedBy.... the createdBy and LastEditedBy are fk to the user table. When an admin make a changes to a record in a table, I use the userID in the session to add the userID to those fields for example, if the admin Bahaa make a changes to x record in the category table I add the userID for bahaa in the LastEditedBy fields. If you still don't understand any point let me know and I will be happy to help you.
  15. No, you should not add the admin_id to those table. the admin_id in the mod table should be a fk to the admin table
  16. If you want to follow Hartley suggetion about making sperate table to track the changes, take off the admin_id from the clinet table because don't need it there. Second, the tracking table should be for all of other tables, you can't make a tracking table for each table. In the tracking table add the other tables ids. When an admin make a changes to the client table for example you add this record to the mod table the id for the client_id the date and the id for the admin and the ids for the other tables should be null
  17. He can add those fileds to every table and get who made the changnes, I have them in my table and I manage to get such information. For example, in admin area I have a page called categories_manager that display the categorty information plus the creation date, modification date, created by and last eduted by for each record.
  18. I don't remember the movie tables and I did not read the whole book but I think the table in between is because the many to many relation ship in movies case. An actor can have many movies and a movie can have many actors.
  19. You cam add auditing fields to the other tables and you can add more than one field to each table example of fields: CreationDate CreatedBy LastEdited LastEditedBy The client table did not have a contact name like first name and last name. I noticed you use varchar(255) for all of your varchar fields, you should only use the size you need , for example you won't need 255 for a city name or first name. for the city name I don't think you would need more than varchar(30), first name maybe 55. for the location, if you want to have more than one address for the same person then you to make a bridge table between the client table and the adress table. You also can break the location table into these tables: country and city
  20. admin AdminID FirstName LastName Password client ClientID FirstName LastName location LocationID Address ClientID FK to the client table website WebsiteID Url ClientID Fk to the client table image ImageID Image ClientID FK to the Client ID
  21. Why did you put the cl_id in the client table? You break the normalization when you store the full name in one filed, if you store the full name in one field you want be able to do any sotring on the names. you should make one filed for first name and another one for last name I think you only need 5 tables
×
×
  • Create New...