473,657 Members | 2,414 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Form Sends Data But Also Shows Errors?

27 New Member
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\sit e\booking.php on line 8

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

Notice: Undefined index: DV in C:\wamp\www\sit e\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 1568
prabirchoudhury
162 New Member
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 Recognized Expert Expert
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 New Member
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\sit e\booking.php on line 8
May 10 '09 #4
obtrs
27 New Member
after addning action isset its working fine thanx for the help prabirchoudhury 's & Marcus.



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

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

Similar topics

16
2883
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 form order to do that ? My point is for the client to be able to re-read the modified data.
9
1847
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 needs to transparently log a user on to a separate secure web site (PHP - not controlled by us). We want to save the user the step of typing in his username and password and having to press submit. I could accomplish this by using the <form...
5
17696
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 type=password maxlength="8" name="password" value="`pss`"> where usr and pss are sent from the previous form.
2
1582
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 dynamic controls when the page is posted back. I also have a server side function that validates data ensuring it falls within a given range after the post back. If the range is not valid, I am Throw-ing a new Exception object; the validation...
1
1153
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 using ADO. I'm getting sometimes correct values, sometimes null values (when I know I pass a valid default value) and other times multiple values! I know what the values coming over are because I do a response.write to see it before the error...
3
2333
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 using ADO. I'm getting sometimes correct values, sometimes null values (when I know I pass a valid default value) and other times multiple values! I know what the values coming over are because I do a response.write to see it before the error...
2
2477
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 maybe some of the code might be outdated. Basically this is what Is supposed to happen: 1.- Display a form, enter details into fields and click submit. 2.- After having clicked on submit you're redirected to another page that will display the...
7
3601
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
2272
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 handles its onclick event and sets values of input fields in hidden form according to event data etc. The form is submitted, on the server side there's some javascript generated that is injected into a hidden frame (the same where the hidden form...
0
8402
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8315
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8734
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8608
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7341
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6172
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5633
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4323
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1962
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.