The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> PHP Development
|
PHP-DB - Php-mysql error undefined index for every variable
Discuss Php-mysql error undefined index for every variable in the PHP Development forum on Dev Shed. Php-mysql error undefined index for every variable PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

December 7th, 2012, 03:53 AM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 4
Time spent in forums: 16 m 10 sec
Reputation Power: 0
|
|
|
PHP-DB - 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??
|

December 7th, 2012, 04:50 AM
|
 |
pollyanna
|
|
Join Date: Jul 2012
Location: Germany
|
|
|
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.
|

December 7th, 2012, 06:05 AM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 4
Time spent in forums: 16 m 10 sec
Reputation Power: 0
|
|
thank you...
deleting enctype="text/plain" from the code worked... 
|

December 7th, 2012, 07:15 AM
|
 |
pollyanna
|
|
Join Date: Jul 2012
Location: Germany
|
|
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?
|

December 7th, 2012, 11:19 PM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 4
Time spent in forums: 16 m 10 sec
Reputation Power: 0
|
|
|
i copied it from somewhere i found on internet...not from w3school.
i am a big fan of w3school...
|

December 7th, 2012, 11:51 PM
|
 |
pollyanna
|
|
Join Date: Jul 2012
Location: Germany
|
|
Quote: | Originally Posted by prashantminku i copied it from somewhere i found on internet...not from w3school. |
OK.
Quote: | 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).
|

December 10th, 2012, 12:16 AM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 4
Time spent in forums: 16 m 10 sec
Reputation 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.
|

December 10th, 2012, 06:39 AM
|
 |
pollyanna
|
|
Join Date: Jul 2012
Location: Germany
|
|
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.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|