php - Database not storing data from form -


here html, code check if there error

    <html>     <head>     <title> add team </title>     <link href="css/style.css" rel="stylesheet" type="text/css" />     <link rel="stylesheet" href="css/thickbox.css" type="text/css" media="screen" />     <link href="css/styles.css" rel="stylesheet" type="text/css" />     <script language="javascript">          var re = /^.+@.+\..{3}$/;         var re1 = /^[a-za-z]+$/;         var re2 = /^[0-9]{10}$/;          function validateform()         {         if (document.f1.pname.value == "")         {         window.alert(" name should not empty");         document.f1.pname.focus();         return false;         }         else         if (re1.test(document.f1.pname.value) == false)         {         alert("invalid format");         return false;         }         else         if (document.f1.pname.value.length < 6)         {         window.alert("name must have atleast 6 characters");         document.f1.pname.focus();         return false;         }         else         if (document.f1.role.value == "")         {         window.alert("role should not empty");         document.f1.role.focus();         return false;         }         else         if (re1.test(document.f1.role.value) == false)         {         alert("invalid format");         return false;         }         else         if (document.f1.role.value.length < 6)         {         window.alert("role must have atleast 6  characters");         document.f1.role.focus();         return false;         }         else         if (document.f1.role.value == "")         {         window.alert("role should not empty");         document.f1.role.focus();         return false;         }         else         if (document.f1.education.value == "")         {         window.alert("education should not empty");         document.f1.education.focus();         return false;         }         else         if (re1.test(document.f1.education.value) == false)         {         alert("invalid format");         return false;         }         else         if (document.f1.education.value.length < 6)         {         window.alert("education must have atleast 6 characters");         document.f1.education.focus();         return false;         }         else         if (document.f1.education.value == "")         {         window.alert("education should not empty");         document.f1.education.focus();         return false;         }         else         if (document.f1.hobbies.value == "")         {         window.alert("hobbies should not empty");         document.f1.hobbies.focus();         return false;         }         else         if (re1.test(document.f1.hobbies.value) == false)         {         alert("invalid format");         return false;         }         else         if (document.f1.hobbies.value.length < 6)         {         window.alert("hobbies must have atleast 6 characters");         document.f1.hobbies.focus();         return false;         }         else         if (document.f1.hobbies.value == "")         {         window.alert("hobbeis should not empty");         document.f1.hobbies.focus();         return false;         }         else         if (document.f1.best.value == "")         {         window.alert("what best 1 liner should not empty");         document.f1.best.focus();         return false;         }         else         if (re1.test(document.f1.best.value) == false)         {         alert("invalid format");         return false;         }         else         if (document.f1.best.value.length < 6)         {         window.alert("what best 1 liner must have atleast 6 characters");         document.f1.best.focus();         return false;         }         else         if (document.f1.best.value == "")         {         window.alert("what best 1 liner should not empty");         document.f1.best.focus();         return false;         }         else         if (document.f1.look.value == "")         {         window.alert("who should not empty");         document.f1.look.focus();         return false;         }         else         if (re1.test(document.f1.look.value) == false)         {         alert("invalid format");         return false;         }         else         if (document.f1.look.value.length < 6)         {         window.alert("who  must have atleast 6 characters");         document.f1.look.focus();         return false;         }         else         if (document.f1.look.value == "")         {         window.alert("who should not empty");         document.f1.look.focus();         return false;         }         else         if (document.f1.role.value == "")         {         window.alert("role should not empty");         document.f1.role.focus();         return false;         }         else         if (re1.test(document.f1.role.value) == false)         {         alert("invalid format");         return false;         }         else         if (document.f1.role.value.length < 6)         {         window.alert("role must have atleast 6 characters");         document.f1.role.focus();         return false;         }         else         if (document.f1.role.value == "")         {         window.alert("role should not empty");         document.f1.role.focus();         return false;         }         else         {         window.alert("ur entire given input valid..");         return true;         }          }     </script></head> <body>     <table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#cccccc" >              <tr>         <form name="f1" method="post"  onsubmit="return validateform();" action="connect.php" enctype="multipart/form-data">             <td>                 <table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#fffff">                     <tr>                         <td colspan="3"><strong>team member </strong></td>                     </tr>                     <tr>                         <td width="78">name</td>                         <td width="6">:</td>                         <td width="294"><input name="pname" type="text" id="t1" onblur="pname_validateform();"></td>                     </tr>                     <tr>                         <td>role</td>                         <td>:</td>                         <td><input name="role" type="text" id="t2" onblur="role_validateform();"></td>                     </tr>                     <tr>                         <td>profile image</td><td>:</td>                         <td><input type="file" name="file_upload" id="upload_file" /> </td>                     </tr>                     <tr>                         <td>education</td>                         <td>:</td>                         <td><input name="education" type="text" id="t3" onblur="education_validateform();"></td>                     </tr>                     <tr>                         <td>hobbies</td>                         <td>:</td>                         <td><input name="hobbies" type="text" id="t4" onblur="hobbies_validateform();"></td>                     </tr>                     <tr>                         <td>what best 1 liner?</td>                         <td>:</td>                         <td><input name="best" type="text" id="t5" onblur="best_validateform();"></td>                     </tr>                     <tr>                         <td>who like?</td>                         <td>:</td>                         <td><input name="look" type="text" id="t6" onblur="look_validateform();"></td>                     </tr>                     <tr>                         <td>what people not me?</td>                         <td>:</td>                         <td><input name="about" type="text" id="t7" onblur="about_validateform();"></td>                     </tr>                     <tr>                         <td>&nbsp;</td>                         <td>&nbsp;</td>                         <td><input name="submit" class="btn_login" type="submit" value="submit" /></td>                     </tr>              </form>        </table> 

here database connection code don't know why not storing registration form data in database showing blank page

i tried many times won't work please me find out error :

   <?php 

here database connections :

       $host = "localhost"; // host name        $username = "root"; // mysql username         $password = ""; // mysql password        $db_name = "project"; // database name 

connect server , select database :

     mysql_connect("$host", "$username", "$password") or die("cannot connect");      mysql_select_db("$db_name") or die("cannot select db"); 

checking image type , image form :

   if (isset($_post['submit'])) {     $target = "../uploads/";     $allowedexts = array("jpg", "jpeg");     $value = explode(".", $_files["file_upload"]["name"]);     $extension = strtolower(array_pop($value));     //$extension = end(explode(".", $_files["file_upload"]["name"]));     $target = $target . basename($_files['file_upload']['name']);      //$date = date("y-m-d h:i:s");     //function generate image thumbnails      function make_thumb($src, $dest, $desired_width) {        /* read source image */     $source_image = imagecreatefromjpeg($src);       $width = imagesx($source_image);     $height = imagesy($source_image);      /* find "desired height" of thumbnail, relative desired width  */     $desired_height = floor($height * ($desired_width / $width));      /* create new, "virtual" image */     $virtual_image = imagecreatetruecolor($desired_width, $desired_height);      /* copy source image @ resized size */     imagecopyresampled($virtual_image, $source_image, 0, 0, 0, 0, $desired_width, $desired_height, $width, $height);      /* create physical thumbnail image destination 100% quality */     imagejpeg($virtual_image, $dest, 100); }    // values form     $pname = $_post['pname'];     $role = $_post['role'];     $pimg = @$_post['file_upload'];     $education = $_post['education'];     $hobbies = $_post['hobbies'];     $best = $_post['best'];     $look = $_post['look'];     $about = $_post['about'];   //check allowed extensions if ((($_files["file_upload"]["type"] == "image/jpg") || ($_files["file_upload"]["type"] == "image/jpeg")) && in_array($extension, $allowedexts)) {     $photoname = $_files["file_upload"]["name"];     if (file_exists("../uploads/" . $pimg)) {         die('<div class="error">sorry <b>' . $pimg . '</b> exists</div>');     }      if (move_uploaded_file($_files['file_upload']['tmp_name'], $target)) {         //$query = "insert photos (image,) values ('$photoname','$date')";         $query = "insert teams(name,role,pimg,education,hobbies,best,look,about)values('$pname','$role','$pimg','$education','$hobbies','$best','$look','$about')";         mysql_query($query);         $sql = "select max(id) photos";         $max = mysql_query($sql);         $row = mysql_fetch_array($max);         $maxid = $row['max(id)'];          $type = $_files["file_upload"]["type"];         switch ($type) {             case "image/jpeg":                 $ext = ".jpeg";                 break;             case "image/jpg";                 $ext = ".jpg";                 break;         }          //define arguments make_thumb function         $source = "../uploads/" . $photoname;         $destination = "../thumbnails/thumb_" . $maxid . $ext . "";         //specify desired width thumbnails         $width = "282";         //finally call make_thumb function         make_thumb($source, $destination, $width);          $msg = '<div class="success">                     <b>upload: </b>' . basename($photoname) . '<br />                     <b>type: </b>' . $_files["file_upload"]["type"] . '<br />                     <b>size: </b>' . ceil(($_files["file_upload"]["size"] / 1024)) . 'kb<br />                 </div>';     } else {         $msg = '<div class="error">sorry, there problem uploading file.</div>';     } } else {     $msg = '<div class="error">the file type trying upload not allowed!</div>'; } }  else { echo "error"; }  ?> 

you should use path file , not relative paths when dealing uploads.

$target = "../uploads/"; 

it should contain path folder since relative path script executing commands. (something depending on exact location of target folder.)

$target = $_server['document_root'].'/uploads/'; 

additionally file should have path well:

$destination = $_server['document_root']."/thumbnails/thumb_" . $maxid . $ext . ""; 

also should not include @ sign , should name of file, can pull $_files array:

$pimg = $_files['file_upload']['name']; 

for testing can print output of $_files array make sure you're capturing right array key(index) fields if problem still exists after change. since undefined index error means value you're trying pull isn't in array.

print_r($_file); 

Comments