Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie - "0:" displayed before any other output 2

Status
Not open for further replies.

whinger74

Programmer
Aug 13, 2002
25
GB
Hi,
Sorry, this is probably very basic, but I can't find the answer to this anywhere. I have a fairly simple php page that displays some dynamic data (mysql_query(), mysql_fetch_array, etc)
The data displays alright, but at the top of the page before any other output a zero and colon is displayed - 0: Does anyone know why this occurs?
This has happened to me before, but I can't remember how I fixed it! :)
Thanks in advance for any help
 
Code:
contents of you page here please

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
could you post a piece of code? at least the begining up to the first echo/print statment...
 
sorry!
<?php
session_start();
if (!session_is_registered("user"))
{
// User not logged in, redirect to login page
Header("Location: login.php");
}
include "database.php";

$sql = "SELECT * FROM tbltickets, tblurgency, tblusers WHERE tbltickets.ticketid = ".$_GET['ticketid']." AND tbltickets.urgency = tblurgency.statusid AND tbltickets.child='0' AND tbltickets.user = tblusers.userID";

$sql2 = "SELECT * FROM tbltickets, tblusers WHERE child = ".$_GET['ticketid']." AND tblusers.userID = tbltickets.user ORDER BY ticketid ASC";

$result = mysql_query ($sql, $conn);
if(!$result){
echo mysql_errno() . ": " . mysql_error();

}

$row = mysql_fetch_array($result);

$result2 = mysql_query ($sql2, $conn);
if(!$result2){
echo mysql_errno() . ": " . mysql_error();

}

if (isset($_POST['response']))
{

$sqladd = "INSERT INTO tbltickets SET
user = " .$row['user']. ",
subject = '-',
timestamp = '".mktime()."',
status = 'Open',
ticketname = '-',
email = '".$_SESSION['email']."',
urgency = 3,
company = ".$_SESSION['company'].",
admin = '-',
child = ".$_GET['ticketid'].",
question = '".$_POST['response']."'";

$add = mysql_query ($sqladd, $conn);
//refresh the page so the new response is shown
Header("Location: readticket.php?ticketid=".$_GET['ticketid']."");
}
if(!$add){
echo mysql_errno() . ": " . mysql_error();

}

mysql_close ($conn);

?>

It's a simple helpdesk system - it's probably not too efficient to have 2 queries, but I just wanted to get it working for now
 
It could be something in database.php, too. Could we see that?

What is your PHP run environment? OS, web server, running as a module or a CGI?


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
<?

/**
* Connect to the mysql database.
*/
$conn = mysql_connect("localhost", "username", "") or die;
('I cannot connect to the database because:' .mysql_error());
mysql_select_db('dbname', $conn) or die(mysql_error());

?>
 
My guesss is the 0 is a zero response from mysql, you do a colon after mysql_errno so the format would be ok for that. Can you label each echo where you do mysql so we can see which statement is doing it please .
 
This is actually hosted on my free Lycos Tripod webspace! (don't laugh), but the phpinfo script says:
OS = Linux (Debian GNU/Linux)
server API = CGI

I would guess the web server is Apache(?)

Thanks again
 
possible other stuff, you have a header inside an if so that is probabbly not executed, but you do make a check on $add (which you set in the if)which is probabbly the cause of your error, in any case not good !, I wonder why you dont get a variable not declared error here ?
 
This is getting a bit out of hand - sorry, I thought this would be a common error!
<form enctype="multipart/form-data" name="form1" action="<?php echo $_SERVER['PHP_SELF'] ?>?ticketid=<?php echo $_GET['ticketid'] ?>" method="post" onsubmit="return validate()">
<table width="75%" cellspacing="1" cellpadding="1" border="1" class="mainbody" align="center">
<tr>
<td width="50%" valign="top">
<table width="97%" cellspacing="1" cellpadding="1" border="1" class="mainbody align="center">
<tr>
<td colspan="2"><p><b>Ticket <?php echo $row['ticketid'] ?> Details</b></p></td></tr>
<tr><td width="30"><p><b><font size="3">Subject:</font></b></p></td>
<td colspan="2"><p><font size="3"><?php echo $row['subject'] ?></font></p></td>
</tr>
<tr><td><p><b>User:</b></p></td>
<td colspan="2"><p><?php echo $_SESSION['user'] ?></p></td>
</tr>
<tr>
<td><p><b>Email:</b></p></td>
<td colspan="2"><p><?php echo $row['email'] ?></p></td>
</tr>

<tr>
<td><p><b>Urgency:</b></p></td>
<td colspan="2"><p><b><?php echo $row['statusname'] ?></b></p></td>
</tr>
<tr><td><p><b>Status:</b></p></td>
<td colspan="2"><p><?php echo $row['status'] ?></p></td>
</tr>
</table>
<div style="padding-top:5px"></div>

<table width="97%" cellspacing="1" cellpadding="1" border="1" align="center">
<tr>
<td><p><b>Respond</b></p></td>
</tr>
<tr>
<td align="right"><p>
<textarea name="response" cols="63" rows="10"></textarea>
<input type="submit" value="Submit" />
</p></td></tr>
</table><div style="padding-top:5px"></div>
<br /></td>
<td width="50%" valign="top">

<table width="97%" cellspacing="1" cellpadding="1" border="1" align="center">
<tr>
<td><p><b><font size="2">Original ticket:</font></b></p></td>
<td width="50%" align="right"><p><?php echo date("d M Y G:i",$row['timestamp']) ?></p></td></tr>
<tr>
<td colspan="2"><p><?php echo $row['question'] ?></p></td></tr>
<?php
while ($row2 = mysql_fetch_array($result2))
{
?>
<tr>
<td colspan="2"><p>Response by <?php echo $row2['username'] ?>, <?php echo date("d M Y G:i",$row2['timestamp']) ?></p></td></tr>
<tr><td colspan="2"><p><?php echo $row2['question'] ?></p></td> </tr>
<?php
}
?>
 
it might be a common error !, can you provide the diagnostics I asked for ???
 
thanks for looking into this.
labelled echoes:

name="form1" action="<?php echo $_SERVER['PHP_SELF'] ?>?ticketid=<?php echo $_GET['ticketid'] ?>"

<b>Ticket <?php echo $row['ticketid'] ?> Details</b>

<font size="3"><?php echo $row['subject'] ?></font>

<p><?php echo $_SESSION['user'] ?></p>

<p><?php echo $row['email'] ?></p>

<b><?php echo $row['statusname'] ?></b>

<p><?php echo $row['status'] ?></p>

<p><?php echo date("d M Y G:i",$row['timestamp']) ?></p>

<p><?php echo $row['question'] ?></p>

<?php
while ($row2 = mysql_fetch_array($result2))
{
?>
<p>Response by <?php echo $row2['username'] ?>, <?php echo date("d M Y G:i",$row2['timestamp']) ?></p>

<p><?php echo $row2['question'] ?></p>
<?php
}
?>

 
// set $result as the response from the query
$result = mysql_query ($sql, $conn);

// this is where we fail ladies and gents, because 0 has no value so !0 is always false.
if(!$result){
echo mysql_errno() . ": " . mysql_error();

}

much better to do :

$result = mysql_query ($sql, $conn) or die (mysql_errno .":". mysql_error());



______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Thanks - this doesn't display a zero anymore! :)
Thanks for everyone that looked into this
 
Fo reference I should have said how it was fixed!
I changed:
$result = mysql_query ($sql, $conn);
if(!$result){
echo mysql_errno() . ": " . mysql_error();
}

to:

$result = mysql_query ($sql, $conn) or die (mysql_errno .":". mysql_error());

erm.. also I can't seem to thank/star anyone in this thread?!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top