Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 116735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T03:13:30+00:00 2026-05-11T03:13:30+00:00

Hi I am quite new to php but i have been following some tutorials

  • 0

Hi I am quite new to php but i have been following some tutorials but they don’t seem to work so I have tried to adapt them. I have tested this code and it works to a point but theres something else I can’t get my head around, the php file is not uploading (fine) but the details are still being writen to the datbase although the $ok is spose to be set to 0 (not fine). It might be easier if explain what is ment to happen here:

-The User can upload gif or jpeg files. Details added to the db. -The User can upload no file as a default will be used. Details added to the db. -The User should not be able to upload any other file. No record should be on the db, user should have to try again.

My Code so far:

<?php  //This is the directory where images will be saved $target = 'images/'; $target = $target . basename( $_FILES['photo']['name']); $ok=0;    //This gets all the other information from the form $name= mysql_real_escape_string ($_POST['nameMember']); $bandMember= mysql_real_escape_string ($_POST['bandMember']); $pic= mysql_real_escape_string ($_FILES['photo']['name']); $about= mysql_real_escape_string ($_POST['aboutMember']); $bands= mysql_real_escape_string ($_POST['otherBands']);  $uploaded_size=$_FILES['photo']['file_size'];  if ($uploaded_size > 350000) { echo 'Your file is too large, 35Kb is the largest file you can upload.<br>'; $ok=0; }  if ($uploaded_type =='text/php') { echo 'No PHP files<br>'; $ok=0; }   if (!($uploaded_type =='image/jpeg')) { echo 'JPEG<br>';$ok=1; }   if ($uploaded_type =='image/gif') { echo 'GIf<br>';$ok=1; }   if (empty($pic)){ echo 'You haven't uploaded a photo, a default will be used instead.<br/>';$ok=1;}   if ($ok==0) { Echo 'Sorry your file was not uploaded, please try again with the correct format.'; }  //If everything is ok we try to upload it else {   // Connects to your Database mysql_connect('localhost', '*******', '******') or die(mysql_error()) ; mysql_select_db('project') or die(mysql_error()) ;  //Writes the information to the database mysql_query('INSERT INTO dbProfile (nameMember,bandMember,photo,aboutMember,otherBands) VALUES ('$name', '$bandMember', '$pic', '$about', '$bands')') ;  //Writes the photo to the server if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) {  //Tells you if its all ok echo 'The file '. basename( $_FILES['uploadedfile']['name']). ' has been uploaded, and your information has been added to the directory<br/>'; print '<a class=\'blue\' href=\'createMember.php\'>Add Another Record</a> | <a class=\'blue\' href=\'listMember.php\'>Band Member Profiles and Affiliates Menu</a>'; } else {  //Gives and error if its not echo '<p>If you have uploaded a picture there may have been a problem uploading your file.</p>'; print '<a class=\'blue\' href=\'createMember.php\'>Add Another Record</a> | <a class=\'blue\' href=\'listMember.php\'>Band Member Profiles and Affiliates Menu</a>'; } } ?>  

Cheers in advance. CHL

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T03:13:30+00:00Added an answer on May 11, 2026 at 3:13 am

    The error probably is this if statement:

      if (!($uploaded_type =="image/jpeg"))   {     echo "JPEG<br>";$ok=1;   } 

    Because every time you upload an image that does not have a content type that equals "image/jpeg", $ok evaluates to 1, so everything gets written to the database.

    But also notice, that just checking the MIME type like this can get you into trouble, since the user is able to fake the MIME type of a file.

    You could use Imagick to get the correct image MIME type, for example. See more details here: https://www.php.net/manual/en/function.imagick-identifyimage.php

    Edit: Just noticed, that $uploaded_type does not get initialized anywhere in your script. As I said, you can do a rough estimation of the MIME type by using $_FILES[‘photo’][‘type’].

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm quite new to php and have been reading Larry Ullman book to develop
I'm new to PHP and web development in general, but have been a programmer
I'm quite new to PHP so I don't know how to solve this error.
I'm still quite new to OOP, and have been learning-as-I-go with CodeIgniter2+Doctrine2. I have
I have to admit in advance that I'm quite new to MVC, I've been
This is probably something really simple, however I am quite new to PHP, and
I'm quite new to c++, but I've got the hang of the fundamentals. I've
I have been playing around with Scala parser combinators for some time now, and
I am quite a new Zend Framework user but I am not new to
I've been searching for tutorials to better understand this, but I'm having no luck.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.