#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    4
    Rep Power
    0

    Php-mysql error undefined index for every variable


    i am getting this as error.i have checked the spellings correctly.But can't find the solution...please help me solve this.


    Notice: Undefined index: name in C:\xampp\htdocs\new\email.php on line 3

    Notice: Undefined index: email in C:\xampp\htdocs\new\email.php on line 4

    Notice: Undefined index: mobile in C:\xampp\htdocs\new\email.php on line 5

    Notice: Undefined index: query in C:\xampp\htdocs\new\email.php on line 6





    Here is the html form on the page **Contacts.php**.I want this to be inserted into the database.



    <form id="ContactForm" action="email.php" method="post" name="ContactForm" enctype="text/plain" >
    <div class="commentForm">

    <input type="text" id="nameField" class="nameField" name="name" />
    <input type="text" id="emailField" class="emailField" name="email" />
    <input type="text" id="mobileField" class="mobileField" name="mobile" />
    <textarea id="queryField" class="queryField" name="query" cols="10" rows="5" ></textarea>
    <input type="submit" id="sendButton" value="Send" class="sendButton" onClick="return validate();" />
    </div>
    </form>




    And this is the **email.php** page.the name of the database is admissionworld and the name of table is contact.




    <?php

    $name = $_POST['name'];
    $email = $_POST['email'];
    $mobile = $_POST['mobile'];
    $query = $_POST['query'];
    $db_host = "localhost";
    $db_username = "root";
    $db_pass = "";
    $db_name = "admissionworld";

    mysql_connect("$db_host","$db_username", or die("Could not connect to database");
    mysql_select_db("$db_name") or die("No Database");

    mysql_query("Insert into contact(name1,email1,mobile1,query1) VALUES ('$name','$email','$mobile','$query')") or die (mysql_error());

    ?>




    i have used this also **var_dump($_POST);**
    But it says array(0) { }.
    Can you please tell me what is the problem??
  2. #2
  3. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,957
    Rep Power
    1045
    Hi,

    where do you have that enctype="text/plain" from? w3schools? Just leave it out.

    I assume that we're talking about the email.php script after a form submission? Because when you just open the script, there's obviously no POST data.

    You should also open the developer tools of your browser to have a look at the actual data being sent (in Chrome, it's "Network" -> "Headers").

    Apart from that, your script is wide open to SQL injections. Anybody can manipulate your INSERT query and fetch, for example, your admin password or other critical data.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    4
    Rep Power
    0
    thank you...
    deleting enctype="text/plain" from the code worked...
  6. #4
  7. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,957
    Rep Power
    1045
    Just out of curiosity, where did you have the enctype from? That "text/plain" value is not even defined, so whatever book or tutorial said you should use it, told you bullsh*t.

    Let me guess: Is it the famous w3schools?
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    4
    Rep Power
    0
    i copied it from somewhere i found on internet...not from w3school.
    i am a big fan of w3school...
  10. #6
  11. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,957
    Rep Power
    1045
    Originally Posted by prashantminku
    i copied it from somewhere i found on internet...not from w3school.
    OK.



    Originally Posted by prashantminku
    i am a big fan of w3school...
    Well, I can tell you that's not a good resource. They have a lot of bullsh*t, obsolete information and bad code on their website (see W3Fools for an in-depth explanation). In fact, it looks like their sole purpose is to sell "certificates" by pretending they're somehow related to the W3C (which they're not!).

    Funny thing is, they also list this "text/plain" as a possible enctype.

    You should generally be careful with what you copy from where, the Internet is full of bad code. In the best case, it will simply not work. In the worst case, it will create giant security holes and make your server vulnerable to all kinds of attacks (like your code currently is due to the queries).
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    4
    Rep Power
    0

    Call to undefined function session_register()


    Hello Jacques1 sir,

    I am getting another problem...when i post the form, i get this as fatal error...
    Call to undefined function session_register()...
    i changed it with $_session(),but still it is not working..

    can you tell me what is the problem??





    This is the index.html page.


    <form class="login active" method="post" action="login.php">
    <h3>Login</h3>
    <div>
    <label>Username:</label>
    <input type="text" name="myusername"/>
    <span class="error">This is an error</span>
    </div>
    <div>
    <label>Password:</label>
    <input type="password" name="mypassword" />
    <span class="error">This is an error</span>
    </div>
    <div class="bottom">
    <div class="remember"><input type="checkbox" /><span>Keep me logged in</span></div>
    <input type="submit" value="Login"></input>
    <div class="clear"></div>
    </div>
    </form>




    This is the login.php page..



    <?php
    $host="localhost";
    $username="root";
    $password="";
    $db_name="Example";
    $tbl_name="login";

    mysql_connect("$host", "$username", "$password")or die("cannot connect");
    mysql_select_db("$db_name")or die("cannot select DB");

    $myusername=$_POST['myusername'];
    $mypassword=$_POST['mypassword'];

    $myusername = stripslashes($myusername);
    $mypassword = stripslashes($mypassword);
    $myusername = mysql_real_escape_string($myusername);
    $mypassword = mysql_real_escape_string($mypassword);
    $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
    $result=mysql_query($sql);

    $count=mysql_num_rows($result);

    if($count>0){

    session_register("$myusername");
    session_register("$mypassword");
    header("location:welcome.php");
    }
    else {
    echo "Wrong Username or Password!";
    }
    ?>

    Thi is welcome.php page..

    <?php
    session_start();
    if(!session_is_registered(myusername)){
    header("location:index.html");
    }
    ?>

    <html>
    <body>
    Login Successful
    </body>
    </html>


    Sir,this is my 1st database work...please help.
  14. #8
  15. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,957
    Rep Power
    1045
    Hi,

    this session_register() is yet another obsolete function which has been removed in modern PHP versions. See the PHP manual. Sessions nowadays use the $_SESSION array, as you can see in the manual.

    I think you really need to take your information from better sources. The mysql_ functions are obsolete, too. Use php.net for first-hand information. I also find the Quakenet/#php Tutorial quite good, because they actually seem to update their stuff. Many other "tutorials" still have 10 year old code online.

IMN logo majestic logo threadwatch logo seochat tools logo