di ko po alam kung saan ako nag kamali... basta ang output lagi.. pag tapos ko mag register, ang sinasabi....
This file has to be a jpeg, jpg or bmp!
kahit bmp nman yung inupload ko...
tinry ko gawing if (true) yung (($type=="image/jpg") || ($type=="image/bmp") || ($type=="image/jpeg"))
pero yung file parang wala.... walang laman yung images folder na dapat paglagyan nya....
eto yung codes.... dalawang file yan
dito ko manggagaling...
-- form.php --
<html>
<head>
<title>testsite</title>
</head>
<body>
<h3>Register From</h3>
<br />
<form enctype="multipart/form-data" method="post" action="insert.php">
<table>
<tr>
<td align="right">Name:</td>
<td><input type="text" name="name" maxlength="30" /></td>
</tr>
<tr>
<td align="right">Email:</td>
<td><input type="text" name="email" maxlength="30" /></td>
</tr>
<tr>
<td align="right">Password:</td>
<td><input type="password" name="password" maxlength="15" /></td>
</tr>
<tr>
<td align="right">Confirm Password:</td>
<td><input type="password" name="cpassword" maxlength="15" /></td>
</tr>
<input type="hidden" name="MAX_FILE_SIZE" value="10000" />
</table>
<br />
Choose your picture: <input type="file" name="upload" />
<br />
<input type="submit" name="submit" value="register" />
</form>
<br />
</body>
</html>
tapos d2 ako maredirect...
--insert.php--
<?php
$mypic = $_FILES['upload']['name'];
$temp = $_FILES['upload']['tmp_name'];
$type = $_FILES['upload']['type'];
$name = $_POST['name'];
$email = $_POST['email'];
$password = $_POST['password'];
$cpassword = $_POST['cpassword'];
if ($name && $email && $password && $cpassword) {
$con = mysqli_connect("localhost", "root") or die("Problem with connection...");
mysqli_select_db($con, "testsite");
$username = mysqli_query($con, "SELECT * FROM users WHERE name='$name'");
$rname = mysqli_num_rows($username);
$checkemail = mysqli_query($con, "SELECT * FROM users WHERE email='$email'");
$remail = mysqli_num_rows($checkemail);
if ($rname) {
echo "Username already exists! Please type another name.";
} elseif ($remail){
echo "E-mail already exists! Please type another e-mail.";
} elseif (!preg_match("/^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$/i", $email)) {
echo "Please enter a valid E-mail!";
} elseif ($password !== $cpassword) {
echo "Passwords you entered should match!";
} elseif (strlen($password) < 4 ){
echo "Password should be 4 to 15 characters long.";
} else {
if (($type == "image/jpg") || ($type == "image/bmp") || ($type == "image/jpeg")) {
move_uploaded_file($temp, "images/$mypic");
echo "What a pretty face!<br /><img border='1' width='70' height='70' src='images/$mypic' /><br />";
$passwordmd5 = md5($password);
mysqli_query($con, "INSERT INTO users(name, email, password) VALUES('$name', '$email', '$passwordmd5')");
$registered = mysqli_affected_rows($con);
echo "$registered was inserted";
} else {
echo "This file has to be a jpeg, jpg or bmp!";
}
}
mysqli_close($con);
} else {
echo "you have to complete the form!";
}
?>
parang di gumagana yung move_uploaded_file() na function...
or baka nman yung <form> yung di gumagana...
This file has to be a jpeg, jpg or bmp!
kahit bmp nman yung inupload ko...
tinry ko gawing if (true) yung (($type=="image/jpg") || ($type=="image/bmp") || ($type=="image/jpeg"))
pero yung file parang wala.... walang laman yung images folder na dapat paglagyan nya....
eto yung codes.... dalawang file yan
dito ko manggagaling...
-- form.php --
<html>
<head>
<title>testsite</title>
</head>
<body>
<h3>Register From</h3>
<br />
<form enctype="multipart/form-data" method="post" action="insert.php">
<table>
<tr>
<td align="right">Name:</td>
<td><input type="text" name="name" maxlength="30" /></td>
</tr>
<tr>
<td align="right">Email:</td>
<td><input type="text" name="email" maxlength="30" /></td>
</tr>
<tr>
<td align="right">Password:</td>
<td><input type="password" name="password" maxlength="15" /></td>
</tr>
<tr>
<td align="right">Confirm Password:</td>
<td><input type="password" name="cpassword" maxlength="15" /></td>
</tr>
<input type="hidden" name="MAX_FILE_SIZE" value="10000" />
</table>
<br />
Choose your picture: <input type="file" name="upload" />
<br />
<input type="submit" name="submit" value="register" />
</form>
<br />
</body>
</html>
tapos d2 ako maredirect...
--insert.php--
<?php
$mypic = $_FILES['upload']['name'];
$temp = $_FILES['upload']['tmp_name'];
$type = $_FILES['upload']['type'];
$name = $_POST['name'];
$email = $_POST['email'];
$password = $_POST['password'];
$cpassword = $_POST['cpassword'];
if ($name && $email && $password && $cpassword) {
$con = mysqli_connect("localhost", "root") or die("Problem with connection...");
mysqli_select_db($con, "testsite");
$username = mysqli_query($con, "SELECT * FROM users WHERE name='$name'");
$rname = mysqli_num_rows($username);
$checkemail = mysqli_query($con, "SELECT * FROM users WHERE email='$email'");
$remail = mysqli_num_rows($checkemail);
if ($rname) {
echo "Username already exists! Please type another name.";
} elseif ($remail){
echo "E-mail already exists! Please type another e-mail.";
} elseif (!preg_match("/^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$/i", $email)) {
echo "Please enter a valid E-mail!";
} elseif ($password !== $cpassword) {
echo "Passwords you entered should match!";
} elseif (strlen($password) < 4 ){
echo "Password should be 4 to 15 characters long.";
} else {
if (($type == "image/jpg") || ($type == "image/bmp") || ($type == "image/jpeg")) {
move_uploaded_file($temp, "images/$mypic");
echo "What a pretty face!<br /><img border='1' width='70' height='70' src='images/$mypic' /><br />";
$passwordmd5 = md5($password);
mysqli_query($con, "INSERT INTO users(name, email, password) VALUES('$name', '$email', '$passwordmd5')");
$registered = mysqli_affected_rows($con);
echo "$registered was inserted";
} else {
echo "This file has to be a jpeg, jpg or bmp!";
}
}
mysqli_close($con);
} else {
echo "you have to complete the form!";
}
?>
parang di gumagana yung move_uploaded_file() na function...
or baka nman yung <form> yung di gumagana...