Question

It is a regitration page in php where image is also uploading along with other user data but it is always showing error please help me to figure out the problem.It is always showing fail but i am using correct image. I also want to know how to set default value for profile image in phpmyadmin and how to query to update it when user enter his choice along with other user data that is to be inserted into database with insert query. and how to do insertion and updation at same time i.e inserting user data and updating default image.

<?php
include_once 'conn.inc';


if(isset($_POST["btnsave"])) {

    $filename=$_FILES['file']['name'];
    $size=$_FILES['file']['name'];
    $extenstion=pathinfo($filename,PATHINFO_EXTENSION);
    if($extenstion=='jpeg' || $extenstion=='png' || $extenstion=='jpg' && $size<=30000) {
        move_uploaded_file($_FILES["file"]["tmp_name"],
        "upload/" . $_FILES["file"]["name"]);

    }
     else {
        echo "failhhhhhhhhhh";
    }


    $name=mysql_real_escape_string($_POST["txtname"]);
    $fname=mysql_real_escape_string($_POST["txtfname"]);
    $gender=mysql_real_escape_string($_POST["gender"]);
    $image=$_FILES['file']['name'];
    $des=mysql_real_escape_string($_POST["des"]);
    $job=mysql_real_escape_string($_POST["txtjob"]);
    $country=mysql_real_escape_string($_POST["txtcountry"]);
    $state=mysql_real_escape_string($_POST["txtstate"]);
    $city=mysql_real_escape_string($_POST["txtcity"]);
    $contact=mysql_real_escape_string($_POST["txtcontact"]);
    $contactst=mysql_real_escape_string($_POST["contactst"]);
    $email=mysql_real_escape_string($_POST["txtemail"]);
    $emailst=mysql_real_escape_string($_POST["emailst"]);

    $query="insert into tblregistration values
    ('','$name','$fname','$gender','$image','$des','$job','$country','$state','$city','$contact','$contactst','$email','$emailst')" or die('neverve'.mysql_error());
    $res=mysql_query($query) or die('error 1'.mysql_error());
    if(mysql_affected_rows())
    {
        echo "success";
    }
    else {
        echo "failure";
    }
}
?>

html form

<form method="post" action="registration.php" enctype="multipart/form-data">
        <table>
            <tr>
                <td><label for="txtname">Name</label></td>
                <td><input type="text" name="txtname" value="Enter your name"/></td>
            </tr>
            <tr>
                <td><label for="txtfname">Father Name</label></td>
                <td><input type="text" name="txtfname" value="Enter your father's name"/></td>
            </tr>
            <tr>
                <td><label>Gender</label></td>
                <td>Male<input type="radio" name="gender" checked="checked" value="m" />
                    Female<input type="radio" name="gender" value="f" />
                </td>
            </tr>
            <tr>
            <td>
                <input onchange="readURL(this);" type="file"  name="file" /></td>
                 <td><img alt="Image Display Here" id="test" src="./upload/icon3.jpg" height="100px" width="100px"  /></td>
            </tr>

            <tr>
                <td><label>Designation</label></td>
                <td><select name="des">
                    <option value="-1">Select Designation</option>
                    <option value="Employed">Employed</option>
                    <option value="selfemployed">Self-Employed</option>
                    <option value="retired">Retired</option>          
                        </select></td>
            </tr>
            <tr>
                <td>
                    <label>Title of Job</label></td>
                    <td><input type="text" name="txtjob" value="title of job" /></td>
            </tr>

            <tr>
                <td>
                    <label>Country</label></td>
                    <td><input type="text" name="txtcountry" value="Enter your country" /></td>
            </tr>
            <tr>
                <td>
                    <label>State</label></td>
                    <td><input type="text" name="txtstate" value="Enter your State" /></td>
            </tr>
            <tr>
                <td>
                    <label>City</label></td>
                    <td><input type="text" name="txtcity" value="Enter your city" /></td>
            </tr>
            <tr>
                <td>
                    <label>Contact no</label></td>
                    <td><input type="tel" name="txtcontact" value="Enter your contact no" />
                        Private<input type="radio" name="contactst" value="0" />&nbsp;&nbsp;Public<input type="radio" name="contactst" checked="checked"  value="1"/>
                    </td>
            </tr>
            <tr>
                <td>
                    <label>Email</label></td>
                    <td><input type="email" name="txtemail" value="Enter your email" />
                        Private<input type="radio" name="emailst" value="0" />&nbsp;&nbsp;Public<input type="radio" name="emailst" checked="checked" value="1" />
                    </td>
            </tr>
            <tr>
                <td></td>
                <td><input type="submit" name="btnsave" value="submit" /></td>
            </tr>
        </table>
     </form>
Was it helpful?

Solution

$size=$_FILES['file']['name']; please check this condition

OTHER TIPS

Replace

$size=$_FILES['file']['name'];

with

$size=$_FILES['file']['size'];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top