Here is my html, code check it if there is any 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 BE 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 SIX characters");
document.f1.pname.focus();
return false;
}
else
if (document.f1.role.value == "")
{
window.alert("role should NOT BE 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 SIX characters");
document.f1.role.focus();
return false;
}
else
if (document.f1.role.value == "")
{
window.alert("role should NOT BE empty");
document.f1.role.focus();
return false;
}
else
if (document.f1.education.value == "")
{
window.alert("education should NOT BE 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 SIX characters");
document.f1.education.focus();
return false;
}
else
if (document.f1.education.value == "")
{
window.alert("education should NOT BE empty");
document.f1.education.focus();
return false;
}
else
if (document.f1.hobbies.value == "")
{
window.alert("hobbies should NOT BE 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 SIX characters");
document.f1.hobbies.focus();
return false;
}
else
if (document.f1.hobbies.value == "")
{
window.alert("hobbeis should NOT BE empty");
document.f1.hobbies.focus();
return false;
}
else
if (document.f1.best.value == "")
{
window.alert("what is your best one liner should NOT BE 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 is your best one liner must have atleast SIX characters");
document.f1.best.focus();
return false;
}
else
if (document.f1.best.value == "")
{
window.alert("what is your best one liner should NOT BE empty");
document.f1.best.focus();
return false;
}
else
if (document.f1.look.value == "")
{
window.alert("who do they say you look like should NOT BE 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 do they say you look like must have atleast SIX characters");
document.f1.look.focus();
return false;
}
else
if (document.f1.look.value == "")
{
window.alert("who do they say you look like should NOT BE empty");
document.f1.look.focus();
return false;
}
else
if (document.f1.role.value == "")
{
window.alert("role should NOT BE 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 SIX characters");
document.f1.role.focus();
return false;
}
else
if (document.f1.role.value == "")
{
window.alert("role should NOT BE empty");
document.f1.role.focus();
return false;
}
else
{
window.alert("ur entire Given input is 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 is your best one liner?</td>
<td>:</td>
<td><input name="best" type="text" id="t5" onblur="best_validateForm();"></td>
</tr>
<tr>
<td>Who do they say you look like?</td>
<td>:</td>
<td><input name="look" type="text" id="t6" onblur="look_validateForm();"></td>
</tr>
<tr>
<td>What people do not like about me?</td>
<td>:</td>
<td><input name="about" type="text" id="t7" onblur="about_validateForm();"></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input name="submit" class="btn_login" type="submit" value="Submit" /></td>
</tr>
</form>
</table>
Here is my database connection code i don't know why it was not storing the registration form data in database but simply showing some blank page
I tried many times but it won't work please help me to find out error :
<?php
Here is the database connections :
$host = "localhost"; // Host name
$username = "root"; // Mysql username
$password = ""; // Mysql password
$db_name = "project"; // Database name
Connect to server and select database :
mysql_connect("$host", "$username", "$password") or die("cannot connect");
mysql_select_db("$db_name") or die("cannot select DB");
Checking the image type and get the image from 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 to generate image thumbnails
function make_thumb($src, $dest, $desired_width) {
/* read the source image */
$source_image = imagecreatefromjpeg($src);
$width = imagesx($source_image);
$height = imagesy($source_image);
/* find the "desired height" of this thumbnail, relative to the desired width */
$desired_height = floor($height * ($desired_width / $width));
/* create a new, "virtual" image */
$virtual_image = imagecreatetruecolor($desired_width, $desired_height);
/* copy source image at a resized size */
imagecopyresampled($virtual_image, $source_image, 0, 0, 0, 0, $desired_width, $desired_height, $width, $height);
/* create the physical thumbnail image to its destination with 100% quality */
imagejpeg($virtual_image, $dest, 100);
}
// Get values from 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 for 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> already exists</div>');
}
if (move_uploaded_file($_FILES['file_upload']['tmp_name'], $target)) {
//$query = "INSERT INTO photos (image,) VALUES ('$photoname','$date')";
$query = "INSERT INTO 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) FROM 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 for the make_thumb function
$source = "../uploads/" . $photoname;
$destination = "../thumbnails/thumb_" . $maxId . $ext . "";
//specify your desired width for your thumbnails
$width = "282";
//Finally call the 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 was a problem uploading your file.</div>';
}
} else {
$msg = '<div class="error">The file type you are trying to upload is not allowed!</div>';
}
}
else {
echo "ERROR";
}
?>
You should always use the path to the file and not relative paths when dealing with uploads.
$target = "../uploads/";
It should contain the path to the folder since this is a relative path to the script executing the commands. (Something like this depending on the exact location of the target folder.)
$target = $_SERVER['DOCUMENT_ROOT'].'/uploads/';
Additionally this file should have the path as well:
$destination = $_SERVER['DOCUMENT_ROOT']."/thumbnails/thumb_" . $maxId . $ext . "";
Also this should not include the @ sign and it should be the name of the file, so you can pull that from the $_FILES
array:
$pimg = $_FILES['file_upload']['name'];
For testing you can print the output of the $_FILES
array to make sure you're capturing the right array key(index) fields if the problem still exists after the change. Since the undefined index error means the value you're trying to pull isn't in the array.
print_r($_FILE);