• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Cant insert dropdown seleted item to MySQL through PHP  RSS feed

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
………………..main.php……………………..



……………. INSERT.PHP ……………………..

 
Sheriff
Posts: 21742
102
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch!

I think the problem is that your option elements do not have a value attribute. Option elements have two major elements:
* the value attribute, which is what will be the select's value and what will be sent to the server.
* the text (between the start and end tags), which is what you see on screen.

Since you have no value attributes, the value remains empty when sent to insert.php.


And can you please use code tags next time? I've added them for you this time.
 
Rob Spoor
Sheriff
Posts: 21742
102
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I also noticed that your select element has no name. Just like input elements, select elements need a name to be sent to the server. You can then retrieve the value of the selected option from the $_POST array.
 
Antony Martin
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sir,

i added this code to insert.php

$combo.=$_post["combo."];

$sql = "INSERT INTO member (designation) VALUES ('$combo.')";

but error showing....i want insert my selective dropdown item to mysql database

below mentioned error message

Notice: Undefined variable: _post in C:\xampp\htdocs\csmspunalur\insert.php on line 55

Notice: Undefined variable: combo in C:\xampp\htdocs\csmspunalur\insert.php on line 55

please mention me the code

Thanks
 
Rob Spoor
Sheriff
Posts: 21742
102
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) It's $_POST, not $_post. PHP is case sensitive.
2) You use $combo.=. The .= means that you want to append to an existing variable. Since this is the first occurrence of $combo you should drop the .: $combo=$_POST["combo"];
 
Antony Martin
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Sir

$combo=$_POST["combo"];

$sql = "INSERT INTO member (designation) VALUES ('$combo')"

Error message is shwoing

Undefined index: combo in C:\xampp\htdocs\csmspunalur\insert.php on line 54

can you please write correct code...i want insert this selected item to mysql



thanks for the great support

 
Antony Martin
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dear Sir

Thanks for the great support...I am visual basic programmer last 15 years working...Now i am learning php ...

Once again thanks

 
Rob Spoor
Sheriff
Posts: 21742
102
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you give the select element a name called "combo"? Did you also give the option elements all a value attribute? If not, then the selected value will not be sent to insert.php (correctly).
 
Antony Martin
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes sir

Its working now....thanks

I gave name the select....Now its working proper

Thanks for the great support

Have a nice day
 
Rob Spoor
Sheriff
Posts: 21742
102
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have the same problem ,.. this is my insert file :



there is no view error  at display monitor, but the data still no insert at all in MySql, why should i do? ( sorry my bad english ).. thanks for your attention and great support
 
Rob Spoor
Sheriff
Posts: 21742
102
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch!

Try removing the header call. That causes a redirect, which means you cannot see any errors anymore. Without the redirect you will at least be able to see any output your PHP file produces.

Also, your code is very vulnerable for SQL injection. I suggest using PDO with parameter binding, or at least mysqli_real_escape_string.
 
Henry Leonardy
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you for your answer Rob,...  but, i am beginner for programming, could you please to show me the code :

1> how romoving the header call ? maybe, for the next step, i have to using PDO for parameter binding...

thanks again.
 
Rob Spoor
Sheriff
Posts: 21742
102
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Remove that line. That causes the redirect.
 
Henry Leonardy
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Rob,... it is solved !  thanks again
 
Rob Spoor
Sheriff
Posts: 21742
102
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!