Debugging Help Needed Please!<

liunx

Guest
The purpose of the code below is for the user to enter a job number and that job's details will be displayed on the screen.

What happens is that my entry form is displayed each time (which shouldn't happen) and that neither confirmation nor error messages are displayed.

All contributions gratefully received :)<?php
ob_start();
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Add Comments</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script language="javascript" type="text/javascript"><!--

//--></script>
</head>

<body>
<?php
if ($Submit) {

// process form

$db_username = "xxxxx";
$db_password = "xxxxx";
$db_hostname = "localhost";
$db_connect = mysql_connect($db_hostname, $db_username, $db_password) or die("Unable to connect to server");
$db = mysql_select_db("alex_bpprogress",$db_connect);

$jobNo=$_POST['jobNo'];

$sql="SELECT * FROM job_details WHERE job_no='$jobNo'";
$details = mysql_query($sql) or die ("Couldn't execute SELECT query.");

$found_job=mysql_num_rows($details);

if ($found_job==1) {
$job_details=mysql_fetch_array($details);
print "<p>Found!</p>";
} else {
print "<p>Job number not found in database.<br />If it does not exist as a PDF, would you like to <a href=http://www.htmlforums.com/archive/index.php/\"newjob.php\">create it?</a></p>";
unset($Submit);
}
} else {
?>
<form name="selectjob" id="selectjob" method="post" action="<?php echo $PHP_SELF?>">
<table width="250" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="106">Job Number</td>
<td width="144"><input name="jobNo" type="text" maxlength="6" /></td>
</tr>
<tr>
<td></td>
<td><br>
<input type="submit" name="Submit" value="Submit" /></td>
</tr>
</table>
</form>
<?php
}

if ($found_job==1) {
print "Job number: {$job_details['job_no']}<br>Customer: {$job_details['customer']}";
}
?>
</body>
</html>
<?php
ob_flush();
?>Edit: Amended code tag to php tag :)Originally posted by Kalessin
The purpose of the code below is for the user to enter a job number and that job's details will be displayed on the screen.

What happens is that my entry form is displayed each time (which shouldn't happen) and that neither confirmation nor error messages are displayed.

All contributions gratefully received :)<?php
ob_start();
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Add Comments</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script language="javascript" type="text/javascript"><!--

//--></script>
</head>

<body>
<?php
if ($Submit) {

// process form

$db_username = "xxxxx";
$db_password = "xxxxx";
$db_hostname = "localhost";
$db_connect = mysql_connect($db_hostname, $db_username, $db_password) or die("Unable to connect to server");
$db = mysql_select_db("alex_bpprogress",$db_connect);

$jobNo=$_POST['jobNo'];

$sql="SELECT * FROM job_details WHERE job_no='$jobNo'";
$details = mysql_query($sql) or die ("Couldn't execute SELECT query.");

$found_job=mysql_num_rows($details);

if ($found_job==1) {
$job_details=mysql_fetch_array($details);
print "<p>Found!</p>";
} else {
print "<p>Job number not found in database.<br />If it does not exist as a PDF, would you like to <a href=http://www.htmlforums.com/archive/index.php/\"newjob.php\">create it?</a></p>";
unset($Submit);
}
} else {
?>
<form name="selectjob" id="selectjob" method="post" action="<?php echo $PHP_SELF?>">
<table width="250" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="106">Job Number</td>
<td width="144"><input name="jobNo" type="text" maxlength="6" /></td>
</tr>
<tr>
<td></td>
<td><br>
<input type="submit" name="Submit" value="Submit" /></td>
</tr>
</table>
</form>
<?php
}

if ($found_job==1) {
print "Job number: {$job_details['job_no']}<br>Customer: {$job_details['customer']}";
}
?>
</body>
</html>
<?php
ob_flush();
?>Edit: made the thread title (slightly) more informative ;)


are register globals on or off on your server?if they're off...$submit will be unset always...you have to use $_POST["submit"]



$submit = $_POST["submit"];

if($submit)
{
//do something
}


hth ^_^

ps: when posting php code...always post it with the [ php ] [ /php ] tags instead of the code tags,this allows for syntax highlightingRegister globals are on, and the if ($submit) works on another page in the site on the same server.

The only reason I used $_POST in another part of the page is because I lifted the code from a different script.

So, thanks, but no, that's not it. But I went back and did that thing with the php tags. I've seen others use it but forgot about it myself :)first why are you usnig ob_start(); ther eis no need for it.

second if you have globals ON then using _POST will cause issues, you can't use it.


are you positive that they are ON?

take the ob_start(); off and see if you get errors?I'm not positive... all I said was, there's a page elsewhere in the site that uses if ($Submit) and that works fine, so I assume they are.

Ah, now I'm positive (<!-- m --><a class="postlink" href="http://test.alexcoles.com/test.php">http://test.alexcoles.com/test.php</a><!-- m -->) :)

I've turned output buffering off, and also removed the _POST and the page behaves exactly as it did before.

No error messages... just displays the form and nothing else.ok, php looks good, so what does the form look like once the page has been rendered? you know the source of the html on this page.It looks like this (<!-- m --><a class="postlink" href="http://test.alexcoles.com/addcomments.php">http://test.alexcoles.com/addcomments.php</a><!-- m -->). Does that help? I really appreciate any assistance you can offer on this one, scoutt :)

In case you wondered, entering the number 149065 should find a match, anything else won't. Of course, nothing finds anything at the moment, but you get the point ;)worked for me

Found!
Job number: 149065
Customer:That could not be more weird. I get the form displayed again, as though it's the first time it's loaded.

And you didn't get a customer name displayed... stranger and stranger.well try to put an hidden field and check if the hidden field has been submitted instead of checking $submit...


and why displaying the result after everything when you did check if they are some earlier?


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Add Comments</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>

<body>
<?php
if (isset($_POST['form_submit'])) {

// process form

$db_username = "xxxxx";
$db_password = "xxxxx";
$db_hostname = "localhost";
$db_connect = mysql_connect($db_hostname, $db_username, $db_password) or die("Unable to connect to server");
$db = mysql_select_db("alex_bpprogress",$db_connect);

$jobNo=$_POST['jobNo'];

$sql="SELECT * FROM job_details WHERE job_no='$jobNo'";
$details = mysql_query($sql) or die ("Couldn't execute SELECT query.");
if (mysql_num_rows($details)==1) {
$job_details=mysql_fetch_array($details);
print "<p>Found!</p>";
print "Job number: {$job_details['job_no']}<br>Customer: {$job_details['customer']}";

} else {
print "<p>Job number not found in database.<br />If it does not exist as a PDF, would you like to <a href=http://www.htmlforums.com/archive/index.php/\"newjob.php\">create it?</a></p>";
}
} else {
?>
<form name="selectjob" id="selectjob" method="post" action="<?php echo $PHP_SELF?>">
<input type="hidden" name="form_post" value="yes">
<table width="250" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="106">Job Number</td>
<td width="144"><input name="jobNo" type="text" maxlength="6" /></td>
</tr>
<tr>
<td></td>
<td><br>
<input type="submit" name="Submit" value="Submit" /></td>
</tr>
</table>
</form>
<?php
}
?>
</body>
</html>Thanks illogique, that worked a treat -- once I changedif (isset($_POST['form_submit'])) {toif (isset($_POST['form_post'])) { to match the hidden field :)

Very pleased that it's working now, and grateful for all your help; kinda peeved that it didn't work before, as I have a similar script that works using if ($Submit).

Weird.

Ta anyway :)
 
Back
Top