Jump to content

Problem in sending data from drop down list to mysql...


drinking_eyez

Recommended Posts

Hello buddies... I am stuck with this problem since last 2 week but can find any solution. I can't insert the value of drop down list into mysql database. it takes all other values but gives error on country field. error is: 'Notice: Undefined index: customer_country in C:\..'

Any help please?

I am sending my piece of code below:

 

 

<?php

 

import_request_variables("pg", "form_");

$hostname = "localhost";

$db_user = "root";

$db_password = "*******";

$db_table = "customer";

 

$db = mysql_connect($hostname, $db_user, $db_password);

mysql_select_db("rdms",$db);

?>

<html>

<head>

<title>Adding New Contact in Record</title>

</head>

<link rel="stylesheet" type="text/css" media="screen" href="abc.css" />

<body>

<fieldset>

<legend>

New Customer Entry

</legend>

<img src="header.jpg"

align="top">

<h2>Adding New Contact in Record</h2><hr>

<?php

if (isset($_REQUEST['Submit']))

{

 

$form_cust_country = $_POST['customer_country'];

$sql = "INSERT INTO $db_table(customer_id, customer_name, customer_add, customer_add1, customer_phone, customer_mobile,

customer_fax, customer_city, customer_county, customer_postcode, customer_country, customer_email,

customer_position, customer_website, customer_comment)

values ('$form_cust_id', '$form_cust_name','$form_cust_add','$form_cust_add 1','$form_cust_phone',

'$form_cust_mobile','$form_cust_fax','$form_cust_c ity','$form_cust_county','$form_cust_postcode',

'$form_cust_country','$form_cust_email','$form_cus t_position','$form_cust_website,''$form_cust_comme nt')";

if($result = mysql_query($sql ,$db))

{

echo "Thank you, Your information has been entered into our database";

}

else

{

echo "ERROR: ".mysql_error();

}

 

}

else

{

?>

 

<form method="post" action="">

 

<table width="470">

<tbody>

 

<tr>

<td>ID:</td>

<td><input type="text" name="cust_id" class="abc"></td>

</tr>

<tr>

<td> Name:</td>

<td><input type="text" name="cust_name" class="abc"></td>

</tr>

<tr>

<td>Address:</td>

<td><input type="text" name="cust_add" class="abc"></td>

</tr>

<tr>

<td>Line 2:</td>

<td><input type="text" name="cust_add1" class="abc"></td>

</tr>

<tr>

<td>Phone:</td>

<td><input type="text" name="cust_phone" class="abc"></td>

</tr>

<tr>

<td>Mobile:</td>

<td><input type="text" name="cust_mobile" class="abc"></td>

</tr>

<tr>

<td>Fax: </td>

<td><input type="text" name="cust_fax" class="abc"></td>

</tr>

<tr>

<td>City:</td>

<td><input type="text" name="cust_city" class="abc"></td>

 

</tr>

 

<tr>

<td>County:</td>

<td><input type="text" name="cust_county" class="abc"></td>

</tr>

<tr>

<td>Post code:</td>

<td><input type="text" name="cust_postcode" class="abc"></td>

</tr>

</tbody></table>

<table width="450">

<tbody>

<tr>

<td>Country:</td>

 

<select name="customer_country" class="abc">

 

<option value="" selected="selected">Select a Country</option>

 

<option value="United States">United States</option>

 

<option value="United Kingdom">United Kingdom</option>

</select>

</tr>

 

<tr>

<td>Email:</td>

<td><input type="text" name="cust_email" class="abc"></td>

</tr>

<tr>

<td>Position: </td>

<td><input type="text" name="cust_position" class="abc"></td>

</tr>

<tr>

<td>Website:</td>

<td><input type="text" name="cust_website" class="abc"></td>

</tr>

<tr>

<td>Comments:</td>

<td><input type="text" name="cust_comment" class="abc"></td>

</tr>

 

</tbody></table>

</fieldset>

 

<br><br>

<input type="submit" name="Submit" value="Submit">

</form>

<?php

}

?>

</body>

</html>

Link to comment
Share on other sites

First fix your query and get back to us, cause once I fixed it everything is fine

$sql = "INSERT INTO $db_table(customer_id, customer_name, customer_add, customer_add1, customer_phone, customer_mobile,
customer_fax, customer_city, customer_county, customer_postcode, customer_country, customer_email,
customer_position, customer_website, customer_comment)
values ('$form_cust_id', '$form_cust_name','$form_cust_add','$form_cust_add 1','$form_cust_phone',
'$form_cust_mobile','$form_cust_fax','$form_cust_city','$form_cust_county','$form_cust_postcode',
'$form_cust_country','$form_cust_email','$form_cust_position','$form_cust_website', '$form_cust_comment')";

 

Ray

Link to comment
Share on other sites

First fix your query and get back to us, cause once I fixed it everything is fine

$sql = "INSERT INTO $db_table(customer_id, customer_name, customer_add, customer_add1, customer_phone, customer_mobile,
customer_fax, customer_city, customer_county, customer_postcode, customer_country, customer_email,
customer_position, customer_website, customer_comment)
values ('$form_cust_id', '$form_cust_name','$form_cust_add','$form_cust_add 1','$form_cust_phone',
'$form_cust_mobile','$form_cust_fax','$form_cust_city','$form_cust_county','$form_cust_postcode',
'$form_cust_country','$form_cust_email','$form_cust_position','$form_cust_website', '$form_cust_comment')";

 

Ray

 

Ray thanks for quickest response...

But I sorry I cannot see any problem in query. I am not saying its OK but what I am saying is I cannot identify it... :-[

Link to comment
Share on other sites

your values are messed up. there are spaced in your values and you forgot a comma.

 

$sql = "INSERT INTO $db_table(customer_id, customer_name, customer_add, customer_add1, customer_phone, customer_mobile,

customer_fax, customer_city, customer_county, customer_postcode, customer_country, customer_email,

customer_position, customer_website, customer_comment)

values ('$form_cust_id', '$form_cust_name','$form_cust_add','$form_cust_add 1','$form_cust_phone',

'$form_cust_mobile','$form_cust_fax','$form_cust_c ity','$form_cust_county','$form_cust_postcode',

'$form_cust_country','$form_cust_email','$form_cus t_position','$form_cust_website,''$form_cust_comme nt')";

 

Ray

Link to comment
Share on other sites

My apologize... That was a silly mistake that I couldn't find in 2 weeks... :-[

 

Well... what happening now is ... its inserting data into table, but not 'customer_country' field is empty... Tried to change query like this but still the same

 

$cust_country = htmlspecialchars($_POST['customer_country']);

$sql = "INSERT INTO $db_table(customer_id, customer_name, customer_add, customer_add1, customer_phone, customer_mobile,

customer_fax, customer_city, customer_county, customer_postcode, customer_country, customer_email,

customer_position, customer_website, customer_comment)

values ('$form_cust_id','$form_cust_name','$form_cust_add','$form_cust_add1','$form_cust_phone',

'$form_cust_mobile','$form_cust_fax','$form_cust_city','$form_cust_county','$form_cust_postcode',

'$cust_country','$form_cust_email','$form_cust_position','$form_cust_website','$form_cust_comment')";

Link to comment
Share on other sites

The only thing that would cause that is the database table. What type is the field and how long is it?

 

do you get any error??

 

try this to check

 

$result = mysql_query($sql ,$db);
if($result)
{
echo "Thank you, Your information has been entered into our database";
}
else
{
echo "ERROR: ".mysql_error();
}

Link to comment
Share on other sites

No it does'nt give any error. it shows the message "Thank you, Your Information has been entered into our database" and insert other text field values into table but just customer_country field is empty

 

What will be code line to send it to another page when pressed submit button?

Link to comment
Share on other sites

try and echo out the query and see what you get

 

$sql = "INSERT INTO $db_table(customer_id, customer_name, customer_add, customer_add1, customer_phone, customer_mobile,
customer_fax, customer_city, customer_county, customer_postcode, customer_country, customer_email,
customer_position, customer_website, customer_comment)
values ('$form_cust_id', '$form_cust_name','$form_cust_add','$form_cust_add 1','$form_cust_phone',
'$form_cust_mobile','$form_cust_fax','$form_cust_city','$form_cust_county','$form_cust_postcode',
'$form_cust_country','$form_cust_email','$form_cust_position','$form_cust_website', '$form_cust_comment')";
echo $sql."<br>";
$result = mysql_query($sql ,$db);
if($result)
{
echo "Thank you, Your information has been entered into our database";
}
else
{
echo "ERROR: ".mysql_error();
}

 

Ray

 

Link to comment
Share on other sites

Here is output... country field is empty.... that means its not getting value from drop box list or whatever...

INSERT INTO customer(customer_id, customer_name, customer_add, customer_add1, customer_phone, customer_mobile, customer_fax, customer_city, customer_county, customer_postcode, customer_country, customer_email, customer_position, customer_website, customer_comment) values ('123','humayun','hud','york','111111', '232222','23424','manchester','lancs','m8833', '','abc@xyz.com','manager','www.example.com','nuffing')

Thank you, Your information has been entered into our database

Link to comment
Share on other sites

Not sure what else it can be. I have this

<?php

import_request_variables("pg", "form_");
$hostname = "localhost";
$db_user = "root";
$db_password = "*******";
$db_table = "customer";

//$db = mysql_connect($hostname, $db_user, $db_password);
//mysql_select_db("rdms",$db);
?>
<html>
<head>
<title>Adding New Contact in Record</title>
</head>
<link rel="stylesheet" type="text/css" media="screen" href="abc.css" />
<body>
<fieldset>
<legend>
New Customer Entry
</legend>
<img src="header.jpg"
align="top">
<h2>Adding New Contact in Record</h2><?php
if (isset($_REQUEST['Submit']))
{

$form_cust_country = $_POST['customer_country'];
$sql = "INSERT INTO $db_table(customer_id, customer_name, customer_add, customer_add1, customer_phone, customer_mobile,
customer_fax, customer_city, customer_county, customer_postcode, customer_country, customer_email,
customer_position, customer_website, customer_comment)
values ('$form_cust_id', '$form_cust_name','$form_cust_add','$form_cust_add 1','$form_cust_phone',
'$form_cust_mobile','$form_cust_fax','$form_cust_city','$form_cust_county','$form_cust_postcode',
'$form_cust_country','$form_cust_email','$form_cust_position','$form_cust_website','$form_cust_comment')";
echo $sql."<br />";
if($result = mysql_query($sql ,$db))
{
echo "Thank you, Your information has been entered into our database";
}
else
{
echo "ERROR: ".mysql_error();
}

}
else
{
?>

<form method="post" action="">

<table width="470">
<tbody>

<tr>
<td>ID:</td>
<td><input type="text" name="cust_id" class="abc"></td>
</tr>
<tr>
<td> Name:</td>
<td><input type="text" name="cust_name" class="abc"></td>
</tr>
<tr>
<td>Address:</td>
<td><input type="text" name="cust_add" class="abc"></td>
</tr>
<tr>
<td>Line 2:</td>
<td><input type="text" name="cust_add1" class="abc"></td>
</tr>
<tr>
<td>Phone:</td>
<td><input type="text" name="cust_phone" class="abc"></td>
</tr>
<tr>
<td>Mobile:</td>
<td><input type="text" name="cust_mobile" class="abc"></td>
</tr>
<tr>
<td>Fax: </td>
<td><input type="text" name="cust_fax" class="abc"></td>
</tr>
<tr>
<td>City:</td>
<td><input type="text" name="cust_city" class="abc"></td>

</tr>

<tr>
<td>County:</td>
<td><input type="text" name="cust_county" class="abc"></td>
</tr>
<tr>
<td>Post code:</td>
<td><input type="text" name="cust_postcode" class="abc"></td>
</tr>
</tbody></table>
<table width="450">
<tbody>
<tr>
<td>Country:</td>

<select name="customer_country" class="abc">

<option value="" selected="selected">Select a Country</option>

<option value="United States">United States</option>

<option value="United Kingdom">United Kingdom</option>
</select>
</tr>

<tr>
<td>Email:</td>
<td><input type="text" name="cust_email" class="abc"></td>
</tr>
<tr>
<td>Position: </td>
<td><input type="text" name="cust_position" class="abc"></td>
</tr>
<tr>
<td>Website:</td>
<td><input type="text" name="cust_website" class="abc"></td>
</tr>
<tr>
<td>Comments:</td>
<td><input type="text" name="cust_comment" class="abc"></td>
</tr>

</tbody></table>
</fieldset>




<input type="submit" name="Submit" value="Submit">
</form>
<?php
}
?>
</body>
</html>

 

and when I echo the sql I get this

INSERT INTO customer(customer_id, customer_name, customer_add, customer_add1, customer_phone, customer_mobile, customer_fax, customer_city, customer_county, customer_postcode, customer_country, customer_email, customer_position, customer_website, customer_comment) values ('1', 'Hello','222 nnjjh ave','222 nnjjh ave 1','4015554444', '5555555555','1544455654','somecity','some county','025558', 'United States','sjklkgh@jklghlkjh.com','position','www.domain.com','jklglkg')

 

Ray

Link to comment
Share on other sites

<td >Country:</td>

<td><SELECT name="customer_country" class="abc">

these quotes where like funny, just wrote this line again and it worked...

 

 

any idea who to insert multi forms in one page... like i want Menu on the left side of the page (in form) and other page on the right side. For example the attachment of table structure, same like that...

i know how to do it in HTML but that is not working in php...

 

Link to comment
Share on other sites

<td >Country:</td>

<td><SELECT name="customer_country" class="abc">

these quotes where like funny, just wrote this line again and it worked...

 

 

any idea who to insert multi forms in one page... like i want Menu on the left side of the page (in form) and other page on the right side. For example the attachment of table structure, same like that...

i know how to do it in HTML but that is not working in php...

 

 

$form_cust_country = $_POST['customer_country'];
$sql = "INSERT INTO $db_table(customer_id, customer_name, customer_add, customer_add1, customer_phone, customer_mobile,
customer_fax, customer_city, customer_county, customer_postcode, customer_country, customer_email,
customer_position, customer_website, customer_comment)
values ('$form_cust_id', '$form_cust_name','$form_cust_add','$form_cust_add 1','$form_cust_phone',
'$form_cust_mobile','$form_cust_fax','$form_cust_city','$form_cust_county','$form_cust_postcode',
'$form_cust_country','$form_cust_email','$form_cust_position','$form_cust_website','$form_cust_comment')";

if($result = mysql_query($sql ,$db))
{
echo "Thank you, Your information has been entered into our database";
}
else
{
echo "ERROR: ".mysql_error();
}

}
else
{
?>
[color=red]<!--
<ul id='menu'>

<li><a href='home.php'>Home</a></li>
<li><a href='new_contact.php'>New Contact</a></li>
<li><a href='search_contact.php'>Search Contact</a></li>
<li><a href='send_main.php'>Send Mail to Contact</a></li>
<li><a href='send_sms.php'>Send SMS to Contact</a></li>
<li><a href='contact_us.php'>Contact Us</a></li>

</ul> 
-->
[/color]

<form method="post" action="">

<table width="470">
<tbody>

<tr>
	<td>ID:</td>
	<td><input type="text" name="cust_id" class="abc"></td>
</tr>
<tr>	

 

if you see this code (highlighted) i want this menu on left side, but when i add it all text fields move downwards...

Link to comment
Share on other sites

$form_cust_country = $_POST['customer_country'];
$sql = "INSERT INTO $db_table(customer_id, customer_name, customer_add, customer_add1, customer_phone, customer_mobile,
customer_fax, customer_city, customer_county, customer_postcode, customer_country, customer_email,
customer_position, customer_website, customer_comment)
values ('$form_cust_id', '$form_cust_name','$form_cust_add','$form_cust_add 1','$form_cust_phone',
'$form_cust_mobile','$form_cust_fax','$form_cust_city','$form_cust_county','$form_cust_postcode',
'$form_cust_country','$form_cust_email','$form_cust_position','$form_cust_website','$form_cust_comment')";

if($result = mysql_query($sql ,$db))
{
echo "Thank you, Your information has been entered into our database";
}
else
{
echo "ERROR: ".mysql_error();
}

}
else
{
?>
[color=red]<!--
<ul id='menu'>

<li><a href='home.php'>Home</a></li>
<li><a href='new_contact.php'>New Contact</a></li>
<li><a href='search_contact.php'>Search Contact</a></li>
<li><a href='send_main.php'>Send Mail to Contact</a></li>
<li><a href='send_sms.php'>Send SMS to Contact</a></li>
<li><a href='contact_us.php'>Contact Us</a></li>

</ul> 
-->
[/color]

<form method="post" action="">

<table width="470">
<tbody>

<tr>
	<td>ID:</td>
	<td><input type="text" name="cust_id" class="abc"></td>
</tr>
<tr>	

 

if you see this code (highlighted) i want this menu on left side, but when i add it all text fields move downwards...

[sorry for double post]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.