473,394 Members | 1,887 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Form Sends Data But Also Shows Errors?

27
i have a html form it and some php script to post it to database but every time i open page it show some error on the top but when i input data and send it it also send so how can i remove these errors?

Errors:

Notice: Undefined index: fromcombo in C:\wamp\www\site\booking.php on line 8

Notice: Undefined index: tocombo in C:\wamp\www\site\booking.php on line 8

Notice: Undefined index: DV in C:\wamp\www\site\booking.php on line 8

php script:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. mysql_connect("localhost", "root", "password");
  3.  
  4. mysql_select_db("online_bus_project");
  5.  
  6. mysql_query("INSERT INTO trip (gender, country, date) VALUES ('$_POST[fromcombo]', '$_POST[tocombo]', '$_POST[DV]')");
  7.  
  8. ?>

Html Form:

Expand|Select|Wrap|Line Numbers
  1. <form name="tstest" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
  2.    <CENTER>From : <select name="fromcombo">
  3. <option value="khairpur">Khairpur</option>
  4. <option value="sukkur">Sukkur</option>
  5. </select>       
  6.  
  7. To : <select name="tocombo">
  8. <option value="karachi">Karachi</option>
  9. <option value="hyderabad">Hyderabad</option>
  10. </select></CENTER><br /><br><br>
  11.  
  12. <CENTER>Date : <script type="text/javascript" language="javascript">
  13. (INPUT(NAME("DV")+READONLY())+INPUT(TYPE("button")+VALUE("Calender")+ONCLICK("popCal(this.form.DV)"))).FORM().write();
  14. </script></CENTER><br><br><br>
  15.  
  16. <center><input type="submit" value="Submit Info" /></CENTER>
  17.  
  18. </form>
May 9 '09 #1
6 1558
prabirchoudhury
162 100+
This error appears because of your PHP error reporting settings. Usually,
it appears when your variable is not properly set. every time you getinto the page its try to insert the data into table
but your post variables are empry

Check if $_POST['action'] is set before insert into dataabse. if the form is not being submited then $_POST['action'] is not being set, so it would not try to insert into table.

PHP script
Expand|Select|Wrap|Line Numbers
  1. if (isset($_POST['action'])){
  2.  
  3. mysql_connect("localhost", "root", "password");
  4.  
  5. mysql_select_db("online_bus_project");
  6.  
  7. mysql_query("INSERT INTO trip (gender, country, date) VALUES ('$_POST[fromcombo]', '$_POST[tocombo]', '$_POST[DV]')");
  8.  
  9. }

Html Form

Expand|Select|Wrap|Line Numbers
  1. <form name="tstest" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
  2. <CENTER>From : <select name="fromcombo">
  3. <option value="khairpur">Khairpur</option>
  4. <option value="sukkur">Sukkur</option>
  5. </select> 
  6.  
  7. To : <select name="tocombo">
  8. <option value="karachi">Karachi</option>
  9. <option value="hyderabad">Hyderabad</option>
  10. </select></CENTER><br /><br><br>
  11.  
  12. <CENTER>Date : <script type="text/javascript" language="javascript">
  13. (INPUT(NAME("DV")+READONLY())+INPUT(TYPE("button") +VALUE("Calender")+ONCLICK("popCal(this.form.DV)") )).FORM().write();
  14. </script></CENTER><br><br><br>
  15.  
  16. // add this hidden field here as an action flag
  17. <input type="hidden" name="action" value="add">
  18. <center><input type="submit" value="Submit Info" /></CENTER>
  19.  
  20. </form> 
May 9 '09 #2
Markus
6,050 Expert 4TB
On a further note: you're also inserting raw, potentially malicious data into your database. Have a look at SQL Injection, and your array indices should be wrapped with single or double quotes.

Expand|Select|Wrap|Line Numbers
  1. // Wrong
  2. $_POST[key_name];
  3. // Correct
  4. $_POST['key_name'];
  5.  
May 10 '09 #3
obtrs
27
marcus after adding this it shows this error
// Correct
$_POST['key_name'];
Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in C:\wamp\www\site\booking.php on line 8
May 10 '09 #4
obtrs
27
after addning action isset its working fine thanx for the help prabirchoudhury's & Marcus.



close the tread
May 10 '09 #5
Markus
6,050 Expert 4TB
@obtrs
Of course. I was only showing how you should use quotes when accessing array elements.
May 10 '09 #6
obtrs
27
thanx man...........
May 10 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

16
by: Philippe C. Martin | last post by:
Hi, I am trying to change the data in a form field from python. The following code does not crash but has no effect as if "form" is just a copy of the original html form. Must I recreate the...
9
by: Denise | last post by:
I have posted a similar message in 2 other forums but got no response. I have spent more hours than I can count researching this. Can anyone provide some insight...? Our ASP.Net application...
5
by: Navillus | last post by:
Hey gang, I have a login form that is empty by default, but can be filled with values from a previous form: <input type=text maxlength="40" size="40" name="user" value="`usr`"> <input...
2
by: Elliot Rodriguez | last post by:
I have a form that contains a mix of dynamic controls and declared controls. All of them are intrinsic .NET controls. Several functions within the page use Request.Form to query the value of the...
1
by: Billy | last post by:
I'm using the POST method to submit a simple form html page with yes/no and checkbox fields to an asp response page which stores the values in a new dim string, then uses it to build a new table...
3
by: Bill | last post by:
I'm using the POST method to submit a simple form html page with yes/no and checkbox fields to an asp response page which stores the values in a new dim string, then uses it to build a new table...
2
by: drakorq | last post by:
I got stuck on this, and it would be really great if anybody could point me in the right direction. I was trying setting up these scripts following instructions in a book from 2003, so I thought...
7
ak1dnar
by: ak1dnar | last post by:
Hi, I got this scripts from this URL There is Error when i submit the form. Line: 54 Error: 'document.getElementbyID(....)' is null or not an object What is this error. Complete Files
4
by: szimek | last post by:
Hi, I've already posted an email with this problem, but this time I think I got a bit more info. The app I'm currently working on works like this: when user clicks on a clickable element, it...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.