drinking_eyez Posted July 8, 2008 Share Posted July 8, 2008 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> Quote Link to comment Share on other sites More sharing options...
craygo Posted July 8, 2008 Share Posted July 8, 2008 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 Quote Link to comment Share on other sites More sharing options...
drinking_eyez Posted July 8, 2008 Author Share Posted July 8, 2008 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... Quote Link to comment Share on other sites More sharing options...
craygo Posted July 8, 2008 Share Posted July 8, 2008 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 Quote Link to comment Share on other sites More sharing options...
drinking_eyez Posted July 8, 2008 Author Share Posted July 8, 2008 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')"; Quote Link to comment Share on other sites More sharing options...
craygo Posted July 8, 2008 Share Posted July 8, 2008 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(); } Quote Link to comment Share on other sites More sharing options...
drinking_eyez Posted July 8, 2008 Author Share Posted July 8, 2008 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? Quote Link to comment Share on other sites More sharing options...
craygo Posted July 8, 2008 Share Posted July 8, 2008 what is the structure of the table?? Quote Link to comment Share on other sites More sharing options...
drinking_eyez Posted July 8, 2008 Author Share Posted July 8, 2008 dont know how to explain structure... have a look on attachment please.. [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
craygo Posted July 8, 2008 Share Posted July 8, 2008 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 Quote Link to comment Share on other sites More sharing options...
drinking_eyez Posted July 8, 2008 Author Share Posted July 8, 2008 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 Quote Link to comment Share on other sites More sharing options...
craygo Posted July 8, 2008 Share Posted July 8, 2008 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 Quote Link to comment Share on other sites More sharing options...
drinking_eyez Posted July 8, 2008 Author Share Posted July 8, 2008 i fixed it... thanks ray... can you tell me how can i redirect to another page as submit button presses? Quote Link to comment Share on other sites More sharing options...
craygo Posted July 8, 2008 Share Posted July 8, 2008 change the action in the form tag <form method="post" action="somepage.php"> What was the problem?? Ray Quote Link to comment Share on other sites More sharing options...
drinking_eyez Posted July 8, 2008 Author Share Posted July 8, 2008 <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... Quote Link to comment Share on other sites More sharing options...
drinking_eyez Posted July 8, 2008 Author Share Posted July 8, 2008 <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... Quote Link to comment Share on other sites More sharing options...
drinking_eyez Posted July 8, 2008 Author Share Posted July 8, 2008 $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] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.