473,396 Members | 1,734 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,396 software developers and data experts.

WHats wrong with this code

The folowing code produces an error althought i cant understand why it
does this can any one help? THANKS

ERROR = Notice: Undefined variable: tab in
C:\Inetpub\wwwroot\carpound\table\table1.php on line 32

<?php
$link = mysql_connect("localhost","root","admin") or
die(mysql_error());
mysql_select_db("car") or die (mysql_error());

$query = "SELECT
make,
modal,
reg
FROM
cars";

$result = mysql_query($query,$link) or die(mysql_error());
$num_movies = mysql_num_rows($result);

$head=<<<EOD
<h2><center>car</center></h2>
<table width='70%' border='1' cellpadding='2'
cellspacing='2' align='center'>
<tr>
<th>Car Make</th>
<th>Car Model</th>
<th>Car Reg number</th>
</tr>
EOD;

while($row = mysql_fetch_array($result))
{
$make = $row['make'];
$modal = $row['modal'];
$reg = $row['reg'];

$tab .=<<<EOD
<tr>
<td height=50>$make</td>
<td>$modal</td>
<td>$reg</td>
</tr>

EOD;
}

$tab .=<<<EOD
<tr>
<td> </td>
</tr>
<tr>
<td>Total :$num_movies Movies</td>
</tr>
EOD;
$bottom ="</table>";

$movie =<<<MOVIE
$head
$tab
$bottom
MOVIE;

print $movie;
?>
Jul 17 '05 #1
6 1610
adam wrote:
The folowing code produces an error althought i cant understand why it
does this can any one help? THANKS

ERROR = Notice: Undefined variable: tab in
C:\Inetpub\wwwroot\carpound\table\table1.php on line 32


Just like the error indicates: you failed to initialize the $tab variable
before using it.

To fix this, just put $tab = ''; at the top of your page.
JW

Jul 17 '05 #2
Carved in mystic runes upon the very living rock, the last words of
Janwillem Borleffs of comp.lang.php make plain:
adam wrote:
The folowing code produces an error althought i cant understand why
it does this can any one help? THANKS

ERROR = Notice: Undefined variable: tab in
C:\Inetpub\wwwroot\carpound\table\table1.php on line 32


Just like the error indicates: you failed to initialize the $tab
variable before using it.

To fix this, just put $tab = ''; at the top of your page.


Or turn off notice-level messages.

--
Alan Little
Phorm PHP Form Processor
http://www.phorm.com/
Jul 17 '05 #3
Alan Little wrote:
Or turn off notice-level messages.


Nope. Application should be able to run anywhere without specific ini
settings to keep them portable.

Especially when developing, error_reporting should be set to strictest level
(E_ALL).
JW

Jul 17 '05 #4
adam wrote:
The folowing code produces an error althought i cant understand why it
does this can any one help? THANKS

ERROR = Notice: Undefined variable: tab in
C:\Inetpub\wwwroot\carpound\table\table1.php on line 32

....
...
.. $tab .=<<<EOD ....
...
..
$tab .=<<<EOD

$tab .= xxxx

is the same as writing

$tab = $tab . xxxx

thus, PHP is looking for previous declarations/definitions of the variable
$tab, and not finding any.

it is probably a good idea to just initialise it earlier:

$tab = '';

or some such thing.

mark.


--
I am not an ANGRY man. Remove the rage from my email to reply.
Jul 17 '05 #5
.oO(Alan Little)
Or turn off notice-level messages.


Not on a development system. Good code is notice-free.

Micha
Jul 17 '05 #6
Hi

Because in yr 'php.ini' file error_reporting directive is set to show
'Notice Info' from php parser.

To debug replace this "$tab .=<<<EOD" with "$tab =<<<EOD"
Note: just remove concatenate operator.

Amits

Thanks

Jul 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Colin Steadman | last post by:
I have created a function to kill all session variables that aren't in a safe list. This is the function - Sub PurgeSessionVariables For Each Item In Session.Contents Select Case Trim(Item)...
3
by: Chris Geerdink | last post by:
combo with PHP. what is wrong with the Javascript? else { include("mysql.php"); $query1 = mysql_query("INSERT INTO gbook (naam, email, text) VALUES ('".$_POST."', '".$_POST."',...
4
by: asdf | last post by:
Hello! Can someone tell me whats wrong with this piece of code: Option Compare Database Option Explicit Sub retrieve() Dim rst As ADODB.Recordset Dim i As Integer
1
by: aa | last post by:
When I am reading from local disk (d:), everithing is OK, but then I am reading from map disk I am geting the this error. Whats wrong. Thanks Server Error in '/Extra' Application....
3
by: mahsa | last post by:
Hi do you know whats wrong with this code? <asp:HyperLink id="HLink_Help" runat="server" NavigateUrl='<%# "javascript:window.open('comments.aspx?id=1,width=500,height=600, scrollBars=yes');"...
4
by: blah | last post by:
Hello everyone, Ive been trying to get my application to "click" on a button in another application using SendMessage, Ive gotten this far but Im not sure whats wrong with this code, here is the...
7
by: Mike Barnard | last post by:
It's a simple test... VERY SIMPLE. But... In an external stlyesheet some attributes don't show. With the same styles cut and pasted to the test internally it works as expected. Anyone tell...
1
by: Abubakar | last post by:
Hi, In my application, Some of my thread gets stuck somewhere. The vs2k5 debugging "Thread" window shows that stuck thread and I can I dentify it. In its Name column the following text is...
5
by: islayer | last post by:
can someone tell me what is wrong with the bold code? i am just learning perl. the program should create a perl file with a random name (5 letters, followed by a number), but the name is always just...
5
by: hiqu | last post by:
This issue is driving me nuts and not able to figure out whats wrong. I've this code in my firefox extension. Firefox always hangs and reports the script is busy. if I introduce a break...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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:
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
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...
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.