0

I am trying to insert data from my php form into mysql database but it is giving me error. I am pretty new to learn php Here is my code. When I am sending details by form it is displaying me error as I have echo in my modified.php file.

<html>    
<head>    
    <title>Registration Form</title>    
</head>    
<body>    
    <link href = "registration.css" type = "text/css" rel = "stylesheet" />    
    <h2>Registration form Sign Up</h2>    
    <form name = "form1" action="modified.php" method = "post" enctype = "multipart/form-data" >    
        <div class = "container">    
            <div class = "form_group">    
                <label>First Name:</label>    
                <input type = "text" name = "fname" value = "" required/>    
            </div>    
            <div class = "form_group">    
                <label>Middle Name:</label>    
                <input type = "text" name = "mname" value = "" required />    
            </div>    
            <div class = "form_group">    
                <label>Last Name:</label>    
                <input type = "text" name = "lname" value = "" required/>    
            </div>    
            <div class = "form_group">    
                <label>Password:</label>    
                <input type = "password" name = "pwd" value = "" required/>    
            </div> 
            <div class = "form_group">    
                <label>Confirm Password:</label>    
                <input type = "password" name = "cpwd" value = "" required/>    
            </div>  
            <div class = "form_group">    
                <label>Email:</label>    
                <input type = "text" name = "email" value = "" required/>    
            </div>  
            <div class = "form_group">    
                <label>Contact no:</label>    
                <input type = "number" name = "phone" value = "" required/>    
            </div>
            <div class = "form_group">    
                <label>Gender:</label>    
                <input type = "radio" name = "gender" <?php
/**
* Class and Function List:
* Function list:
* Classes list:
*/
if (isset($gender) && $gender == "female") echo "checked"; ?> Female  
                    <input type = "radio" name = "gender" <?php if (isset($gender) && $gender == "male") echo "checked"; ?> Male
                    <input type = "radio" name = "gender" <?php if (isset($gender) && $gender == "others") echo "checked"; ?> Others   
                </div>
                <div class = "form_group">    
                    <label>Address:</label>
                    <textarea rows="4" cols="30" input type = "text" name = "" value = "" required></textarea> 
                </div>
                <div class = "form_group">    
                    <label>Pin Code:</label>    
                    <input type = "number" name = "pin code" value = "" required/>    
                </div>
                <div class = "form_group">    
                    <label>City:</label>    
                    <select>
                    <option selected disabled>--Select City--</option>
                    <optgroup label="Metros">
                    <option>New Delhi</option>
                    <option>Kolkata</option>
                    <option>Mumbai</option>
                    <option>Chennai</option>
                    </optgroup>
                    <optgroup label="Others">
                    <option>Noida</option>
                    <option>Gurgram</option>
                    <option>Faridabad</option>
                    <option>Gaziabad</option>
                    </optgroup>                            
                    </select>   
                </div>
                <div class = "form_group">    
                    <label>Country:</label>
    <select>
        <option selected disabled>--Select Country--</option>
        <option>India</option>
        <option>Israel</option>
        <option>UK</option>
        <option>Australia</option>
    </select>
            </div>
<div class = "form_group">    
                    <label>Skills:</label>    
                    <input type = "radio" name = "skills" <?php if (isset($skills) && $skills == "PHP") echo "checked"; ?> PHP  
                    <input type = "radio" name = "skills" <?php if (isset($skills) && $skills == "Java") echo "checked"; ?> Java  
                    <input type = "radio" name = "skills" <?php if (isset($skills) && $skills == "JQUERY") echo "checked"; ?> JQUERY
                    <input type = "radio" name = "skills" <?php if (isset($skills) && $skills == ".NET") echo "checked"; ?> .NET     
                </div>  
                <div class = "form_group">    
    <label for="resume">Resume:</label> 
    <input type="file" id="resume">   
                </div> 
                <div class = "form_group">       
                <label></label> 
                <input type="radio" >: I have read terms and conditions
                </div>  
                <div class = "form_group">       
                <label></label> 
                <input type="submit" id="submit" name="submit" value="submit"/>
                </div> 
        </form>    
    </body>  
</html>
James Z
  • 12,209
  • 10
  • 24
  • 44
  • 1
    If you're getting an error, it would be a really good idea to tell us what it says and which line it says the error happens on. We cannot guess :-) – ADyson Jun 25 '21 at 09:59
  • Also you don't seem to have shown us the code which deals with processing the form when it's submitted. – ADyson Jun 25 '21 at 10:00
  • 1
    There are some elements with no `name` attribute. Also ... ` – brombeer Jun 25 '21 at 10:00
  • @ADyson I am trying to submit data from form but it is not inserting into mysql database. It is printing error. Here is my mysql code. – Piyush Trivedi Jun 25 '21 at 10:17
  • 1
    Please [edit] your question and paste relevant code there, not in the comments. As for `$_POST['First_Name']`: there is no element with that name, it's `fname` – brombeer Jun 25 '21 at 10:19
  • @brombeer I think it was just defined to increase address block size. Also in gender hwo can I add values with radio option because when trying to add in regilar way only radio button is displaying – Piyush Trivedi Jun 25 '21 at 10:21
  • MDN has a nice page on [Value](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/radio#value) for radio inputs. And also nice pages on how to set up a `
    ` in general. And PHP has pages on [Dealing with Forms](https://www.php.net/manual/en/tutorial.forms.php)
    – brombeer Jun 25 '21 at 10:22
  • 2
    `it is not inserting into mysql database. It is printing error`...yes, you already said that. I asked to you tell us exactly what the error is. If you don't know the exact error then please enable error reporting in PHP and mysqli. Instructions here: https://stackify.com/php-error-logs-guide/ (php error logging/reporting) https://stackoverflow.com/a/22662582/5947043 (mysqli exception reporting) – ADyson Jun 25 '21 at 10:25

0 Answers0