PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 7th, 2012, 03:53 AM
prashantminku prashantminku is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 4 prashantminku User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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??

Reply With Quote
  #2  
Old December 7th, 2012, 04:50 AM
Jacques1's Avatar
Jacques1 Jacques1 is offline
pollyanna
Click here for more information.
 
Join Date: Jul 2012
Location: Germany
Posts: 1,861 Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 1 Day 18 h 21 m 40 sec
Reputation Power: 813
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.

Reply With Quote
  #3  
Old December 7th, 2012, 06:05 AM
prashantminku prashantminku is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 4 prashantminku User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 16 m 10 sec
Reputation Power: 0
thank you...
deleting enctype="text/plain" from the code worked...

Reply With Quote
  #4  
Old December 7th, 2012, 07:15 AM
Jacques1's Avatar
Jacques1 Jacques1 is offline
pollyanna
Click here for more information.
 
Join Date: Jul 2012
Location: Germany
Posts: 1,861 Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 1 Day 18 h 21 m 40 sec
Reputation Power: 813
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?

Reply With Quote
  #5  
Old December 7th, 2012, 11:19 PM
prashantminku prashantminku is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 4 prashantminku User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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...

Reply With Quote
  #6  
Old December 7th, 2012, 11:51 PM
Jacques1's Avatar
Jacques1 Jacques1 is offline
pollyanna
Click here for more information.
 
Join Date: Jul 2012
Location: Germany
Posts: 1,861 Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 1 Day 18 h 21 m 40 sec
Reputation Power: 813
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).

Reply With Quote
  #7  
Old December 10th, 2012, 12:16 AM
prashantminku prashantminku is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 4 prashantminku User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #8  
Old December 10th, 2012, 06:39 AM
Jacques1's Avatar
Jacques1 Jacques1 is offline
pollyanna
Click here for more information.
 
Join Date: Jul 2012
Location: Germany
Posts: 1,861 Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 1 Day 18 h 21 m 40 sec
Reputation Power: 813
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > PHP-DB - Php-mysql error undefined index for every variable

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap