473,412 Members | 4,127 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,412 software developers and data experts.

undefined index....

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. require_once('database_conn.php');
  3. session_start();
  4. if(isset($_SESSION['username']))
  5. if(isset($_GET['action']) && $_GET['action']=="submit")
  6. {
  7.     $cust_id=$_POST['cname'];
  8.     echo $cust_id;
  9. }
  10. else
  11. {
  12. ?>
  13. <html>
  14. <head>
  15. <script type="text/javascript">
  16. function cust_display()
  17. {
  18. if(document.getElementById('cname').value==0)
  19.  {
  20.    alert("Please Select Customer Name");
  21.  }
  22. else
  23.   {
  24.    document.getElementById('cust_id').value=document.getElementById('cname').value;
  25.    alert(document.getElementById('cust_id').value);
  26.    window.location="bill_index.php?action=submit";
  27.   }
  28. }
  29. </script>
  30. </head>
  31. <body>
  32. <?php
  33. include('adminlogin.php');  
  34. ?>
  35. <form action="#" method="post" name="cust">
  36.    <br />
  37.    <center>
  38.    Select Customer Name :
  39.    <select name="cname" id="cname"  class="bg2" onChange="cust_display()">
  40.    <option value="0">--Select--</option>
  41.    <?php
  42.  $query=mysql_query("select cust_name,cust_id from pms_customer");
  43.       while($r=mysql_fetch_object($query))
  44.     {
  45. ?>
  46.       <option value="<?php echo $r->cust_id;?>"><?php echo $r->cust_name;?></option>
  47. <?php
  48. }
  49.  
  50.      ?>
  51.    </select>
  52.  
  53. </form>
  54. <input type="hidden" name="cust_id" id="cust_id" />
  55. <?php
  56. }
  57. ?>
  58. </html>
  59. <?php
  60. }
  61. else
  62. {
  63.    header("location:login_index.php");
  64. }
  65. ?>                 
  66.  
when i execute this program....undefined index ...error appers....how to solve thi s problem....
Apr 5 '08 #1
14 3878
ronverdonk
4,258 Expert 4TB
I cannot see where you submit the form, is submitted at all.

Secondly, you mix $_GET and $_POST, so what is it?[php]if(isset($_GET['action']) && $_GET['action']=="submit")
{
$cust_id=$_POST['cname'];
echo $cust_id;
}[/php]Ronald
Apr 5 '08 #2
Atli
5,058 Expert 4TB
Hi.

That particular mix of GET and POST data looks kind of strange to me to.

I don't see a submit button for the form. The only thing I see there is a JavaScript redirect, which includes the "?action=submit" GET string.

If that is indeed what you are using to submit your form, you must realize that none of the form's <input> elements are being sent. The form is not actually being submitted, the browser is simply being redirected.

Which would cause the POST array to be empty, leading to the undefined index notice.

To solve this... set the <form> action to "?action=submit" and add a <input type=submit> element to submit the form.

Or have JavaScript submit the form via the: "form.submit()" function.
Apr 5 '08 #3
hsriat
1,654 Expert 1GB
.... :o

I think I posted in this thread.... but I can't see my post...
Apr 6 '08 #4
ronverdonk
4,258 Expert 4TB
.... :o

I think I posted in this thread.... but I can't see my post...
Sorry about that hsriat!

You posted in the duplicate thread. This mixup of threads is one of the reasons why duplicate threads are not allowed.

Your post can still be seen in that thread HERE

Ronald
Apr 6 '08 #5
hsriat
1,654 Expert 1GB
Sorry about that hsriat!

You posted in the duplicate thread. This mixup of threads is one of the reasons why duplicate threads are not allowed.

Your post can still be seen in that thread HERE

Ronald
oh its cool!!. No need to apologize... :)

I was actually confused about whether I pressed Submit Reply or not. :D


Regards,
Harpreet
Apr 6 '08 #6
ronverdonk
4,258 Expert 4TB
I suggest that you just post your reply again. I could do that. but that would be an infringement of your copyright :-)

Ronald
Apr 6 '08 #7
hsriat
1,654 Expert 1GB
I suggest that you just post your reply again. I could do that. but that would be an infringement of your copyright :-)

Ronald
Well, after reading the code again, I think the main problem is not what I thought earlier. But its at line 27, in the JavaScript code.

@selvialagar

Remove line 27 and write the following lines instead.
Expand|Select|Wrap|Line Numbers
  1. document.forms[0].action = "bill_index.php?action=submit";
  2. document.forms[0].submit();
If problem still persists, replace && in line 6 with & (single ampersand).


Harpreet
Apr 6 '08 #8
Atli
5,058 Expert 4TB
...
If problem still persists, replace && in line 6 with & (single ampersand).


Harpreet
Or you could just write "and".

PHP understands all of them...
(& == && == and) if that makes any sense ;)
Apr 6 '08 #9
hsriat
1,654 Expert 1GB
Or you could just write "and".

PHP understands all of them...
(& == && == and) if that makes any sense ;)
Sorry about that, but it has to be either && or and, but NOT &.

I got confused between & and &&.

& would actually give error here. & usually gives same results as && does but not always.

In case of &&, if first condition is false, it will return false, without caring to check the second one.
But & will always check both conditions before returning anything.

I tested it with this example:[php]<?php
echo "With <b>&amp;&amp;:</b><br>";
if (A(false) && B(true))
{
echo "0";
}
echo "<br>------------<br>With <b>&amp;:</b><br>";
if (A(false) & B(true))
{
echo "0";
}

function A($c)
{
echo "Function A executed<br>";
return $c;
}
function B($c)
{
echo "Function B executed<br>";
return $c;
}
?>
[/php]


Regards,
Harpreet
Apr 6 '08 #10
Atli
5,058 Expert 4TB
Sorry about that, but it has to be either && or and, but NOT &.

I got confused between & and &&.

& would actually give error here. & usually gives same results as && does but not always.

In case of &&, if first condition is false, it will return false, without caring to check the second one.
But & will always check both conditions before returning anything.

I tested it with this example:
...

Regards,
Harpreet
Ahh, I see.
Nice catch, I never thought to check that.

I think this would actually qualify as a bug, as checking the extra parameters does nothing but degrade performance and cause possible errors. I can't think of any real reason why you would want the extra parameters checked if the others fail.

And like you say, in this case, using the single & would cause the undefined index notice if the first check fails.
Apr 6 '08 #11
Atli
5,058 Expert 4TB
To contradict my previous post :P...

After digging a little deeper, I find that the single & is in fact NOT a logical operator, which "and" and "&&" are...
It is in fact a bitwise operator, which explains why it evaluates everything before returning.

It is meant to compare all the parameters and "set" all bits that are identical (which in the case of boolean values, will always be 0 (false) unless all parameters are true).

Also...
There are slight differences between "&&" and "and".

They will work identically when used inside an if statement, but when used on variables, they differ slightly.

Consider this:
Expand|Select|Wrap|Line Numbers
  1. $a = true && false; // evaluates into: false
  2. $b = true and false; // evaluates into: true
  3.  
The difference...
"&&" has higher precedence than "=", so "true && false" is evaluated and then stored in $a
"and" has lower precedence than "=", so "$b = false" is evaluated first, which is then evaluated against "and false", which changes nothing and $b remains true.

Lastly... we seem to have wandered slightly of topic.
My apologies for that :)
Apr 6 '08 #12
Markus
6,050 Expert 4TB
To contradict my previous post :P...

After digging a little deeper, I find that the single & is in fact NOT a logical operator, which "and" and "&&" are...
It is in fact a bitwise operator, which explains why it evaluates everything before returning.

It is meant to compare all the parameters and "set" all bits that are identical (which in the case of boolean values, will always be 0 (false) unless all parameters are true).

Also...
There are slight differences between "&&" and "and".

They will work identically when used inside an if statement, but when used on variables, they differ slightly.

Consider this:
Expand|Select|Wrap|Line Numbers
  1. $a = true && false; // evaluates into: false
  2. $b = true and false; // evaluates into: true
  3.  
The difference...
"&&" has higher precedence than "=", so "true && false" is evaluated and then stored in $a
"and" has lower precedence than "=", so "$b = false" is evaluated first, which is then evaluated against "and false", which changes nothing and $b remains true.

Lastly... we seem to have wandered slightly of topic.
My apologies for that :)
Wow!

Seems like i'm thanking you alot, recently!

Haha.

Cheers(again).
Apr 6 '08 #13
thank u very much for your guidence..........
Apr 7 '08 #14
coolsti
310 100+
Here is where a bit of discipline in script writing can go a long way. Writing clear and understandable code helps not only yourself in debugging it but also others in helping you.

I have two hopefully helpful comments in this regard:

You have a line something like "$query = mysql_query(" etc. ")" and it really threw me off when I looked at your code, that you used the variable name $query here. The query is actually the argument of this function, not its return value. I use the variable $result instead. This maybe seems like nitpicking, but using an appropriate variable name helps make the code clearer.

Another point is that you should try to separate a bit more clearly the code that produces HTML output to the requester's browser, and the code that does other tasks, such as database queries.
Apr 7 '08 #15

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

Similar topics

7
by: Coder Droid | last post by:
I decided to run some code with errors set to E_ALL, just to see what I would run across. It caught a few things, but 90% or better of the messages were of the 'undefined' kind: PHP Notice: ...
9
by: petermichaux | last post by:
Hi, I am curious about how php deals with the following situation where I use an undefined index into an array. PHP seems to be behaving exactly how I want it to but I want to make sure that it...
4
by: John Oliver | last post by:
PHP Notice: Undefined index: name in /home/www/reformcagunlaws.com/new.php on line 6 PHP Notice: Undefined index: address in /home/www/reformcagunlaws.com/new.php on line 7 PHP Notice: ...
9
by: Alan Schroeder | last post by:
The following code produces the expected results on a PC using gcc, but I need to port it (or least something similar) to a different platform/compiler. I don't think I've introduced any undefined...
7
by: deepak | last post by:
Using 'char' as an array index is an undefined behavior?
3
cassbiz
by: cassbiz | last post by:
Here are the errors that are coming up in my error_log Notice: Undefined index: andatum in /zipcode.php on line 11 Notice: Undefined index: andatum in /zipcode.php on line 12 Notice: Undefined...
3
by: number1yan | last post by:
Can anyone help me, i am creating a website and am using a php script that recomends the website to other people. I keep getting the same error and can not work out why. The error is: Notice:...
15
by: bill | last post by:
I am trying to write clean code but keep having trouble deciding when to quote an array index and when not to. sometimes when I quote an array index inside of double quotes I get an error about...
5
by: siyaverma | last post by:
Hi, I am new to php, i was doing some small chnages in a project developed by my collegue who left the job and i got the responsibility for that, After doing some changes when i run it on my...
3
by: sickboy | last post by:
$channels=$_GET; if (empty($channels)) { $channels='blank'; } changechannels($channels); $theatre=$_GET; if (empty($theatre)) { $theatre='splash'; } changetheatre($theatre); $info=$_GET; if...
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
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
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,...
0
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...

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.