Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Undefined variable - Need Help
Old 04-06-2005, 05:56 PM Undefined variable - Need Help
merlin's Avatar
Skilled Talker

Posts: 52
Trades: 0
Hi Again,

I have attached my code for easier viewing. I'm getting an Undefined variable error on line 97.

Line 97 has
PHP Code:
if ($an && $ts && $ds) { //if everything’s OK 
but according to the manual I have everything is fine. Can someone with more experience than I (That's just about everyone) have a look at me code.

Thanks.............


PHP Code:
<?php
ob_start
();
session_start();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>NCC Cheque Register - Update</title>
<?php
include ('..\includes\cssinclude.php');
include (
'..\includes\meta.php');
?>
<script language="javascript" src="..\cal2.js">
/*
Xin's Popup calendar script-  Xin Yang (http://www.yxscripts.com/)
Script featured on/available at http://www.dynamicdrive.com/
This notice must stay intact for use
*/`
</script>
<script language="javascript" src="..\cal_conf2.js">
</script>
</head>

<body>
<div id="content">
<?php
$today 
date("F j, Y");  // Date Format: Month Day, Year
include ('..\includes\outline.php');
?>
<br>
<form action="chq_register.php" method="post" name="chq_register2" onsubmit="return invalid_entry(chq_register2)">
<p align="left"><fieldset><legend>Update the Date Forwarded:</legend></p><br>
<table width="60%"  border="0" align="center" cellspacing="4">
  <tr>
    <td width="42%"><div align="right">Account Number </div></td>
    <td width="58%"><input type="text" name="Account_Number_2" onfocus="document.chq_register2.Account_Number_2.style.backgroundColor='#F4F4B7'"   onblur="document.chq_register2.Account_Number_2.style.backgroundColor='white'"></td>
  </tr>
  <tr>
    <td><div align="right">Cheque Total </div></td>
    <td><input type="text" name="Total_2" onfocus="document.chq_register2.Total_2.style.backgroundColor='#F4F4B7'"   onblur="document.chq_register2.Total_2.style.backgroundColor='white'"></td>
  </tr>
  <tr>
    <td><div align="right">Date Forwarded </div></td>
    <td><input type="text" name="Date_Sent_2" onclick="chq_register2.Date_Sent_2.value=''" onfocus="document.chq_register2.Date_Sent_2.style.backgroundColor='#F4F4B7'"   onblur="document.chq_register2.Date_Sent_2.style.backgroundColor='white'">
        <a href="javascript:showCal('Calendar4')"><img src="date.png"></a></td>
  </tr>
</table>
<br>
<div align="center">
    <input type="submit" name="Submit1" value="Add to Account">
    </div>
<?php
//if the user pressed the submit button (if it is set)
    
if (isset($_POST['Submit1'])) {
    

        require_once(
'Cheq_Register\mysql_connect_register.php');
        
        function 
escape_data ($data) {
            global 
$dbc;
            if (
int_get('magic_quotes_gpc')) {
                
$data stripslashes($data);
            }
            return 
mysql_real_escape_string($data$dbc);
        } 
//End of function
        
$message NULL// Create an empty variable
        
// Check for an Account Number
    
if(empty($_POST['Account_Number_2'])) {
        
$an FALSE;
        
$message .='<p>You Forgot to enter the Account Number</p>';
    } else {
        
$an escape_data($_POST['Account_Number_2']);
        
    }
    
// Check for a Cheque Total
    
if(empty($_POST['Total_2'])) {
        
$ts FALSE;
        
$message .='<p>You Forgot to enter the Cheque Total</p>';
    } else {
        
$ts escape_data($_POST['Total_2']);
        
    }

// Check for a Date Forwarded
    
if(empty($_POST['Date_Sent_2'])) {
        
$ds FALSE;
        
$message .='<p>You Forgot to enter the Date Forwarded</p>';
    } else {
        
$ds escape_data($_POST['Date_Sent_2']);
        
    }
}

    if (
$an && $ts && $ds) { //if everthing's OK
    
    
$query "SELECT Account_Number FROM accounts WHERE (Account_Number_2='$an' AND Total_2='$ts')";
    
$result = @mysql_query ($query);
    
$num mysql_num_rows ($results);
    if (
$num == 1) {
    
$row mysql_fetch_arry($resultMYSQL_NUM);
    
    
// Make the query to update the datebase
    
$query "UPDATE accounts SET Date_Sent_2='$ds' WHERE Account_Number_2=$row[0]";
    
$result = @mysql_query ($query); //Run the query
    
if (mysql_affected_rows() == 1) { //if it ran OK
    
echo '<p><b>Done as per your request</p></b>';
    exit(); 
//Quit the script
    
    
} else { //if it did not run OK
    
$message '<p>An Error has occured</p><p>' mysql_error() . '</p>';
    }
    
mysql_close(); //close the connection

if (isset($message)) {
    echo 
"<font color=\"red\">" $message "</font>"

    }
    }
    }
?>
<p>&nbsp;</p>
</fieldset>
</form>
</div>
</body>
</html>
merlin is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-06-2005, 06:12 PM
pitbull82's Avatar
Super Talker

Posts: 147
Name: Marcin Nabiałek
Location: Poland, Częstochowa
Trades: 0
Try in that line instead of
PHP Code:
if ($an && $ts && $ds) { //if everything’s OK 
this code
PHP Code:
if (isset($an) && isset($ts) && isset($ds)) { //if everything’s OK 
That should help...
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
pitbull82 is offline
Reply With Quote
View Public Profile Visit pitbull82's homepage!
 
Old 04-06-2005, 06:14 PM
Python's Avatar
Ultra Talker

Latest Blog Post:
A new site is launched
Posts: 374
Trades: 0
im not entirely sure but isnt that the exact same thing?

because the original one it is checking if each variable contains a value(if they do then it must have been set). this is the exact same as using isset()
__________________

Please login or register to view this content. Registration is FREE

- Affordable web site design solutions
Python is offline
Reply With Quote
View Public Profile Visit Python's homepage!
 
Old 04-06-2005, 07:10 PM
leavethisplace's Avatar
Ultra Talker

Posts: 297
Trades: 0
Hi Merlin

You have a slight error in the if-then-else argument. If you want to supply more than one argument with in the IF bracket, we have to split them up, so using brackets is the way to do this.

PHP Code:
if ((isset($an)) && (isset($ts)) && (isset($ds))) { //if everything’s OK 
Try to get into the habit of making sure that you use isset to check if variables have been valued, this way an error can be easily thrown up and you'll know what the problem is straight away

Hope that helps!
__________________
A lie gets halfway around the world before the truth has a chance to get its pants on. - Sir Winston Churchill

Please visit my sites:
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
leavethisplace is offline
Reply With Quote
View Public Profile
 
Old 04-07-2005, 01:41 AM
pitbull82's Avatar
Super Talker

Posts: 147
Name: Marcin Nabiałek
Location: Poland, Częstochowa
Trades: 0
Quote:
im not entirely sure but isnt that the exact same thing?
Nope. It's not the same...

Quote:
You have a slight error in the if-then-else argument. If you want to supply more than one argument with in the IF bracket, we have to split them up, so using brackets is the way to do this.
? Extra brackets are unneccessary in that case...

I've just checked it running PHP but I had to add error_reporting(E_ALL); to see the notice... When I changed it as I've written here, there's no notice...


And please understand that errors, notices and warnings in PHP are not the same things
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by pitbull82; 04-07-2005 at 05:47 AM..
pitbull82 is offline
Reply With Quote
View Public Profile Visit pitbull82's homepage!
 
Old 04-07-2005, 05:43 AM
leavethisplace's Avatar
Ultra Talker

Posts: 297
Trades: 0
oh right, i've always used the double brackets rule. I dunno why, but im sure when i didn't use them when i first started coding an error was thrown up (ok ok, maybe it was a warning) referring to the line with the if statement on, so i threw the brackets in and worked fine.

Does it actually really matter about having brackets or not?
__________________
A lie gets halfway around the world before the truth has a chance to get its pants on. - Sir Winston Churchill

Please visit my sites:
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
leavethisplace is offline
Reply With Quote
View Public Profile
 
Old 04-07-2005, 05:53 AM
pitbull82's Avatar
Super Talker

Posts: 147
Name: Marcin Nabiałek
Location: Poland, Częstochowa
Trades: 0
Quote:
when i first started coding an error was thrown up (ok ok, maybe it was a warning)
But that was rather some other case, not exactly the same code as here...

Quote:
Does it actually really matter about having brackets or not?
In that case not because it's conjunction of free bools in fact. But when you use many different operators, it's better to use extra brackets if you're not sure in which order, the logical value would be counted...
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
pitbull82 is offline
Reply With Quote
View Public Profile Visit pitbull82's homepage!
 
Old 04-07-2005, 05:54 AM
leavethisplace's Avatar
Ultra Talker

Posts: 297
Trades: 0
ooo, learn something new every day! Cool, thanks.
__________________
A lie gets halfway around the world before the truth has a chance to get its pants on. - Sir Winston Churchill

Please visit my sites:
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
leavethisplace is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Undefined variable - Need Help
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.41571 seconds with 12 queries