Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > Pro PHP
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Pro PHP Advanced PHP coding discussions. Beginning-level questions will be redirected to the Beginning PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro PHP section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 2nd, 2004, 02:04 AM
Authorized User
 
Join Date: Apr 2004
Location: malacca, malacca, Malaysia.
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to junemo
Default Undefined index

hi, please help me...........

I always getting error msg:
Notice: Undefined index: cur in line............
Notice: Undefined index: ..........
Notice: Undefined index: ................
Notice: Undefined variable: valid in line..........

What's wrong and how to solve this problem?

Thanks in advance.

Reply With Quote
  #2 (permalink)  
Old June 2nd, 2004, 02:38 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , USA.
Posts: 101
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Moharo
Default

do you use arrays?

say if you have something like $_POST["test"], you have to check whether such index exists by doing this:

if(isset($_POST["test"]))

what is your "register global" setting in php?

:D

the genuine genius
Reply With Quote
  #3 (permalink)  
Old June 2nd, 2004, 03:04 AM
Authorized User
 
Join Date: Apr 2004
Location: malacca, malacca, Malaysia.
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to junemo
Default

"register global" = off
Attach code:
recordset.php:
<?php
$bill = $_POST['bill'];
$ship = $_POST['ship'];

$date = $_POST['date'];
$no = $_POST['no'];
$po = $_POST['po'];
$dn = $_POST['dn'];
$cur = $_POST['cur'];
$pri = $_POST['pri'];
$term = $_POST['term'];

$line = $_POST['line'];
$no = $_POST['no'];
$po1 = $_POST['po1'];
$stock1 = $_POST['stock1'];
$qty1 = $_POST['qty1'];
$uom1 = $_POST['uom1'];
$pri1 = $_POST['pri1'];
$amo1 = $_POST['amo1'];
$total = $_POST['total'];
?>
admin_mod.php:
<table class=Table1Border width= "30%" id= table2 style="TEXT-TRANSFORM: uppercase">
<?php
include("recordset.php");

//Set up table and database names
$db_name = "invoice_db";

//Connect to server and select database
$connection = mysql_connect("localhost","phpuser","") or die(mysql_error());

$db = mysql_select_db($db_name,$connection) or die(mysql_error());

//Display the record
$sql ="SELECT line FROM item WHERE line = '$_POST[mlineno]'";
$result =mysql_query($sql,$connection)or die(mysql_error());

//get results for display
while ($row =mysql_fetch_array($result)){

    $line =$row ['line'];
}


?>

    <tr>
        <td class="Label1Text">LINE NO: </td>
        <td class="text8Arial1"><INPUT name="line" VALUE="<? echo $line; ?>" ></td>
    </tr>
    <tr>
        <td class="Label1Text">INVOICE DATE: </td>
        <td class="text8Arial1"><INPUT name="date" VALUE="<? echo $date; ?>" ></td>
    </tr>
    <tr>
        <td class="Label1Text">INVOICE NO:</td>
        <td class="text8Arial1"><INPUT name="no" VALUE="<? echo $no; ?>" ></td>
    </tr>
    <tr>
        <td class="Label1Text"> YOUR PO NO: </td>
        <td class="text8Arial1"><INPUT name="po" VALUE="<? echo $po; ?>" ></td>
    </tr>
        <tr>
        <td class="Label1Text"> DN NO: </td>
        <td class="text8Arial1"><INPUT name="dn" VALUE="<? echo $dn; ?>" ></td>
    </tr>
    </table>

When I run at browser, display all error msg: Undefined index in recordset.php.
So, what's wrong? Can you please point out the error.

Thanks in advance.

Reply With Quote
  #4 (permalink)  
Old June 2nd, 2004, 04:34 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , USA.
Posts: 101
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Moharo
Default

this is what you should do....

<?php

$bill = isset($_POST['bill']) ? $_POST["bill"] : "";
$ship = isset($_POST['ship']) ? $_POST['ship'] : "";

and so forth..

you get this error because you did NOT submit values to recordset.php using POST method

<form action="file.php" method="post">
  ...
</form>

:D

the genuine genius
Reply With Quote
  #5 (permalink)  
Old June 2nd, 2004, 04:35 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , USA.
Posts: 101
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Moharo
Default

if you are using $_POST array make sure you SUBMIT values to that page thru <form method="post">

or if you are using $_GET array, make sure you submit values to recordset.php thru <form method="get">
Reply With Quote
  #6 (permalink)  
Old June 3rd, 2004, 12:21 AM
Authorized User
 
Join Date: Apr 2004
Location: malacca, malacca, Malaysia.
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to junemo
Default

But in recordset.php file don't submit any form value. This file will include in other php file to get the value.
Do you know what mean?
Look at my previous post:
1 attach code is recordset.php
2 attach code is admin_mod.php

That mean recordset.php will include in admin_mod.php to get the value from HTML form.
Before this, my system can run and fully function. Later I want the system run at new browser then it display the error msg!
Notice: Undefined index in line.............
Notice: Undefined variable in line.............

Can we set undisplay the E_NOTICE in php.ini? How?
Thanks in advance.


Reply With Quote
  #7 (permalink)  
Old June 3rd, 2004, 01:00 AM
richard.york's Avatar
Wrox Author
Points: 5,506, Level: 31
Points: 5,506, Level: 31 Points: 5,506, Level: 31 Points: 5,506, Level: 31
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Camby, IN, USA.
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default


Sure you can turn them off, but turning off the E_NOTICE level errors isn't a very good idea. Not seeing these errors can lead to you missing all kinds of potential logic errors and security holes. It's better to just initialize the variables. There's a reason that these errors exist! You should validate variables that come in from outside sources anyway, otherwise anyone who wants to can pass bunk information to your scripts.

I see people always assigning the values of $_POST and $_GET variables to other variables, I think that's a waste of time and space! What I would suggest is rewriting your scripts to use these variables where they're acutally used in the context of the script, it makes your scripts easier to understand and more lightweight.

Consider this rewrite of your code:
<?php

// snip

    function check(&$var)
    {
        return (isset($var))? $var : '';
    }

    echo " <tr>\n".
         " <td class='Label1Text'>\n".
         " LINE NO:\n".
         " </td>\n".
         " <td class='text8Arial1'>\n".
         " <INPUT name='line' VALUE='".check($_POST['line'])."'>\n".
         " </td>\n".
         " </tr>\n".
         " <tr>\n".
         " <td class='Label1Text'>\n".
         " INVOICE DATE:\n".
         " </td>\n".
         " <td class='text8Arial1'>\n".
         " <INPUT name='date' VALUE='".check($_POST['date'])."'>\n".
         " </td>\n".
         " </tr>\n".
         " <tr>\n".
         " <td class='Label1Text'>\n".
         " INVOICE NO:\n".
         " </td>\n".
         " <td class='text8Arial1'>\n".
         " <INPUT name='no' VALUE='".check($_POST['no'])."'>\n".
         " </td>\n".
         " </tr>\n".
         " <tr>\n".
         " <td class='Label1Text'>\n".
         " YOUR PO NO:\n".
         " </td>\n".
         " <td class='text8Arial1'>\n".
         " <INPUT name='po' VALUE='".check($_POST['po'])."'>\n".
         " </td>\n".
         " </tr>\n".
         " <tr>\n".
         " <td class='Label1Text'>\n".
         " DN NO:\n".
         " </td>\n".
         " <td class='text8Arial1'>\n".
         " <INPUT name='dn' VALUE='".check($_POST['dn'])."'>\n".
         " </td>\n".
         " </tr>\n".
         "</table>\n";
?>
[/code]

Instead of writing something like:
echo (isset($_POST['line']))? $_POST['line'] : '';

over and over again I've created a function that does that for me, although I'd validate the data even more to be sure that I'm getting the information requested in the form, but for the sake of argument if I just want to test if the variable isset, I pass it by reference to the function, in the function definition that's what the amphersand in front of the variable means, what that does is send the variable to the function but while inside of the function the variable being referenced there is the original and not a copy of it.

Here's more on references:
http://www.php.net/manual/en/language.references.php

So you can use isset and empty to test for values and eliminate the E_NOTICE level error. These errors can be helpful too. What if you mispelled a variable?? It might take hours to track down if E_NOTICE level errors are turned off. Just speaking from personal experience I'd rather have all error information available to me.

The security benefits are also worth mentioning but I'll leave it to the manual to explain them.
http://www.php.net/manual/en/security.errors.php

HTH!

Regards,
Rich

::::::::::::::::::::::::::::::::::::::::::
The Spicy Peanut Project
http://www.spicypeanut.net
::::::::::::::::::::::::::::::::::::::::::
Reply With Quote
  #8 (permalink)  
Old June 3rd, 2004, 02:47 AM
Authorized User
 
Join Date: Apr 2004
Location: malacca, malacca, Malaysia.
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to junemo
Default

how about this line:
$sql ="SELECT line FROM item WHERE line = '$_POST[mlineno]'";
Error msg-
Notice: Use of undefined constant mlineno - assumed 'mlineno' in line............

Thanks in advance.

Reply With Quote
  #9 (permalink)  
Old October 31st, 2007, 05:45 PM
Registered User
 
Join Date: Oct 2007
Location: , , Philippines.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to p3allen2000
Default

[quote]Originally posted by Moharo
 this is what you should do....

<?php

$bill = isset($_POST['bill']) ? $_POST["bill"] : "";
$ship = isset($_POST['ship']) ? $_POST['ship'] : "";

******************************************

mine doesn't seem to work, I've the similar coding but still i can't work it out this is my code:

for($saverec=1; $saverec<$recno; $saverec++)
    {


        $ccont="reccont".$saverec;
        $ccont = isset($_POST["$ccont"]) ? $_POST["$ccont"]: ";

        $ccode="reccode".$saverec;
        $ccode=isset($_POST["$ccode"]) ? $_POST["$ccode"]: ";

    $ccat="reccat".$saverec;
        $ccat=isset($_POST["$ccat"]) ? $_POST["$ccat"]: ";

    $cprice="recprice".$saverec;
        $cprice=isset($_POST["$cprice"]) ? $_POST["$cprice"]: ";

    $cRFC="recRFC".$saverec;
        $cRFC=isset($_POST["$cRFC"]) ? $_POST["$cRFC"]: ";

    $cdim="recdim".$saverec;
        $cdim=isset($_POST["$cdim"]) ? $_POST["$cdim"]: ";

    $cclass="recclass".$saverec;
        $cclass=isset($_POST["$cclass"]) ? $_POST["$cclass"]: ";

    $ccman="reccman".$saverec;
        $ccman=isset($_POST["$ccman"]) ? $_POST["$ccman"]: ";

        $recfile="recfile".$saverec;
        $recfile=isset($_POST["$recfile"]) ? $_POST["$recfile"]: ";

        $chidid="rechidid".$saverec;
        $chidid=isset($_POST["$chidid"]) ? $_POST["$chidid"]: ";

        $crec="recfile".$saverec;
        $crec=isset($_POST["$crec"]) ? $_POST["$crec"]: ";

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Notice: Undefined index: username in latinquarter PHP Databases 1 April 18th, 2008 11:37 AM
Chapter 13 problem(undefined index) linux-penguin BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 2 February 15th, 2008 06:10 AM
undefined index and variable p3allen2000 Pro PHP 1 November 1st, 2007 04:49 PM
Undefined Index Error rit01 Beginning PHP 0 March 1st, 2006 10:03 AM
Undefined index ashinotani Beginning PHP 2 August 17th, 2004 03:31 PM



All times are GMT -4. The time now is 04:00 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.