Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End trying to insert data from Webpage to database

  • This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #169055
    dnyanesh
    Participant

    Hello Traq,
    i am trying to insert data into the database. could you please help to understand where i went wrong. i am inserting information but database is storing the field names in the database like username, password ,firstname, lastname ……

    in last mail you said while writing insert query use $ help me to understand how i can use it.
    here is the code –
    <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”&gt;
    <html xmlns=”http://www.w3.org/1999/xhtml”&gt;
    <head>
    <meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
    <title>User registration form</title>
    <link rel=”stylesheet” type=”text/css” href=”style.css” />
    </head>

     &lt;?php 
     $con = mysql_connect("localhost","root","");
     mysql_select_db("training",$con);
     if(isset($_POST['submit']))
     {
         $username = $_POST['username'];
         $password = $_POST['password'];
         $firstname= $_POST['firstname'];
         $lastname = $_POST['lastname'];
         $email = $_POST['email'];
         $mobile = $_POST['mobile'];
         $sex = $_POST['sex'];
         $city = $_POST['city'];
         $state = $_POST['state'];
         $country = $_POST['country'];
    
     }
        $sql = "insert into user_frm values('','username','password','firstname','lastname','email','mobile','sex','city','state','country')";
        $rec = mysql_query($sql);
    
     ?&gt;
    &lt;body&gt;
    <div>
      &lt;form id="form1" name="form1"  method="post" onsubmit="return validateform()" action=""&gt;
        &lt;table class="usertbl" align="center" width="600" &gt;
          &lt;tr style="border-radius:40px"&gt;
              &lt;td colspan="2"  bgcolor="#006600" width="100" align="center" style="color:#CCC"  style="font-weight:bold" &gt;
            User Registration Form
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;td class="tbldata"&gt;Username :&lt;/td&gt;
            &lt;td class="tbldata"&gt;&lt;input  onfocus="if(this.value=='Username')this.value='';"  value="Username" class="text" type="text" name="username"  /&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;td class="tbldata"&gt;Password :&lt;/td&gt;
            &lt;td class="tbldata"&gt;&lt;input class="text" type="password" name="password"  /&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;td class="tbldata"&gt;First Name:&lt;/td&gt;
            &lt;td class="tbldata"&gt;&lt;input onfocus="if(this.value=='First Name')this.value='';" value="First Name" class="text"  type="text" name="firstname"  /&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;td class="tbldata"&gt;Last Name:&lt;/td&gt;
            &lt;td class="tbldata"&gt;&lt;input onfocus="if(this.value=='Last Name')this.value='';" value="Last Name" class="text"  type="text" name="lastname"  /&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;td class="tbldata"&gt;E-mail :&lt;/td&gt;
            &lt;td class="tbldata"&gt;&lt;input  onfocus="if(this.value=='E-mail')this.value=''; " value="E-mail" class="text"  type="text" name="email"  /&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;td class="tbldata"&gt;Mobile :&lt;/td&gt;
            &lt;td class="tbldata"&gt;&lt;input  onfocus="if(this.value=='Mobile')this.value=''; " value="Mobile" class="text" type="text" name="mobile"  /&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;td class="tbldata"&gt;Sex :&lt;/td&gt;
            &lt;td align="center" &gt;&lt;input   type="radio" name="sex"  value="Male" checked="checked"&gt;
              Male
              &lt;/input&gt;
              &lt;input type="radio" name="sex"  value="Female"&gt;
              Female
              &lt;/input&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;td class="tbldata"&gt;City :&lt;/td&gt;
            &lt;td class="tbldata"&gt;&lt;input  onfocus="if(this.value=='City')this.value='';" value="City" class="text" type="text" name="city"  /&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;td class="tbldata"&gt;State :&lt;/td&gt;
            &lt;td class="tbldata"&gt;&lt;input  onfocus="if(this.value=='State')this.value=''; " value="State" class="text"  type="text" name="state"  /&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;td class="tbldata"&gt;Country :&lt;/td&gt;
            &lt;td class="tbldata"&gt;&lt;input onfocus="if(this.value=='Enter your Country')this.value=''; " value="Enter your Country" class="text"       type="text" name="country"  /&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;td class="tbldata"&gt;&lt;/td&gt;
            &lt;td  class="tbldata" colspan="2" &gt;&lt;input class="text" style="background-color: #6F6"  style="border:#F00" type="submit" name="submit" value="Submit" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
        &lt;/table&gt;
      &lt;/form&gt;
      &lt;script  type="text/javascript"&gt;
        var frmvalidator = new Validator("form1");
        frmvalidator.addValidation("mobile","maxlen=10");
        frmvalidator.addValidation("mobile","numeric");
    
    function validateform()
    {
        var x = document.forms['form1']['username'].value;
        if(x==null || x=="")
        {
            alert("User name must be Filled out");
            return false;
        }
        if(x=="Username")
        {
            alert("Enter User name");
            return false;
        }
        var x = document.forms['form1']['password'].value;
        if(x==null || x=="" )
        {
            alert("Enter password and should be more than 5 digit");
            return false;
        }
        if(x.length &lt; 5)
        {
            alert("Enter 5 digit password");
            return false;
        }
        var x = document.forms['form1']['firstname'].value;
        if(x==null || x=="")
        {
            alert("First name must be Filled out");
            return false;
        }
        if(x=="First Name")
        {
            alert("Enter your first name");
            return false;
        }
        var x = document.forms['form1']['lastname'].value;
        if(x==null || x=="")
        {
            alert("Last name must be Filled out");
            return false;
        }
        if(x=="Last Name")
        {
            alert("Enter your last name");
            return false;
        }
        var x = document.forms['form1']['email'].value;
        var atpos=x.indexOf("@");
        var dotpos=x.lastIndexOf(".");
        if(atpos&lt;1 || dotpos&lt;atpos+2 || dotpos+2&gt;=x.lenght)
        {
            alert("Not a valid Email address");
            return false;
        }
    
        if(x==null || x=="")
        {
            alert("Email must be Filled out");
            return false;
        }
    
        var x = document.forms['form1']['mobile'].value;
        if(isNaN(x) || x.indexOf(" ")!=-1)
        {
            alert("Enter Numeric Value");
            return false;
        }
        if(x.length &lt; 10)
        {
            alert("Enter 10 digit mobile number");
            return false;
        }
        if(x.charAt(0)!="9")
        {
            alert("Mobile number should start with 9");
            return false;
        }
        if(x==null || x=="")
        {
            alert("Mobile must be Filled out");
            return false;
        }
        var x = document.forms['form1']['city'].value;
        if(x==null || x=="")
        {
            alert("City  must be Filled out");
            return false;
        }
        if(x=="City")
        {
            alert("Enter your City");
            return false;
        }
        var x = document.forms['form1']['state'].value;
        if(x==null || x=="")
        {
            alert("State must be Filled out");
            return false;
        }
        if(x=="State")
        {
            alert("Enter your State");
            return false;
        }
        var x = document.forms['form1']['country'].value;
        if(x==null || x=="")
        {
            alert("Country must be Filled out");
            return false;
        }
        if(x=="Enter your Country")
        {
            alert("Enter your Country");
            return false;
        }
    }
    
    &lt;/script&gt; 
    </div>
    &lt;/body&gt;
    &lt;/html&gt;
    
    #169066
    __
    Participant

    I made a reply in your original discussion (why did you start a new discussion on this same topic?), but it seems to have disappeared.

    I will see if a moderator can get my post back. It would be much better to keep the conversation in one place. In addition, my post touched on a few topics that would be important to discuss before you continue.

    #169072
    Paulie_D
    Member

    @traq

    Can’t see anything ‘Pending’ in the stack so it looks like the reply might have hit the filter and gotten remove.

    #169081
    __
    Participant

    Can’t see anything ‘Pending’ in the stack so it looks like the reply might have hit the filter and gotten remove.

    Crap. It was a big one. It displayed (to me, anyways) for about an hour and a half, then it was gone this morning.


    @dnyanesh
    , I’ll try to reconstruct it for you. I’m going to post back in the original discussion, though, so things don’t get confusing.

    See you there

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.