• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Cant insert dropdown seleted item to MySQL through PHP

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
………………..main.php……………………..



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

 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Remove that line. That causes the redirect.
 
Henry Leonardy
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks Rob,... it is solved !  thanks again
 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how to insert values id to table having fk and fk value id taken from drop down list from another table?
[prod]
||id||prod_name||c_id||
|cell 1|cell 2|cell3|
[/table]

[colour]
||id||c_name||
|cell1|cell 2|
[/table]

Model: model_test.php



Controller: controller_test.php



Index: index.php


data is showing in colour field in index page and I can select it. but when I entering product name and selecting colour and then submitting receiving success message but it is not added in mysql product table.
 
Curse your sudden but inevitable betrayal! And this tiny ad too!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic