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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

No output for form 2

Status
Not open for further replies.

dmacster

Technical User
Jan 28, 2005
670
US
I've tried to modify something I've found to do a CRUD form, but I'm not getting any output at all.

Here's the code I'm using
Code:
<?php
require_once("includes/connection.php");
?>
<table align="center" width="75%" bgcolor="black">
<tr>
<td bgcolor="white" align="center">
<font size="+2"><b>Ad Showcase Management</b></font>
<p>
<a href="formSC.php">All Records</a> 
<?php
  $a = ord("A");
  for ($i = 0; $i < 26; $i++) {
    $ltr = chr($a + $i);
//    $result = mssql_query(sprintf("SELECT * FROM advertisers WHERE UPPER(SORT_NAME) LIKE '%s%%' LIMIT 1", $ltr));
//    if (mssql_fetch_row($result)) {
      printf("<a href=\"formSC.php?filter=alpha&criteria=%s\">%s</a> ", $ltr, $ltr);
//    } else {
//      echo $ltr . " ";
//    }
  }
?>
<br>
<?php  
  $a = ord("0");
  for ($i = 0; $i < 10; $i++) {
    $ltr = chr($a + $i);
//    $result = mssql_query(sprintf("SELECT * FROM advertisers WHERE UPPER(SORT_NAME) LIKE '%s%%' LIMIT 1", $ltr));
//    if (mssql_fetch_row($result)) {
      printf("<a href=\"manageSC.php?filter=alpha&criteria=%s\">%s</a> ", $ltr, $ltr);
//    } else {
//      echo $ltr . " ";
//    }
  }
?>

</td>
</tr>
</table>
<?php
  if ($_REQUEST["criteria"]) {
    $result = mssql_query(sprintf("SELECT * FROM advertisers WHERE UPPER(sort_name) LIKE '%s%%'", $_REQUEST["criteria"]));
  } else {
    $result = mssql_query("SELECT * FROM advertisers ORDER BY sort_name");
  }
  $found = 0;
?>
<table width="75%" align="center" bgcolor="black" cellspacing="1">
<tr>
<td width="75%"><font color="white"><b>Advertiser</b></font></td>
<td align="center"><font color="white"><b>Actions</b></font></td>
</tr>
<tr><td bgcolor="white">&nbsp;</td><td bgcolor="white" align="center"><font size="1"><a href="formSC.php">Add New</a></font></td></tr>
<?php
  while ($rec = mssql_fetch_array($result, MSSQL_ASSOC)) {
?>
<tr>
<td bgcolor="white"><?php echo $rec["advertiser_name"] ?></td>
<td bgcolor="white" align="center"><font size="1">
<a href="formSC.php?mode=edit&ID=<?php echo $rec["advertiser_id"] ?>">Edit</a>&nbsp;
<a href="formSC.php?mode=delete&ID=<?php echo $rec["advertiser_id"] ?>">Delete</a>&nbsp;
</font></td>
</tr>
<?php  
  }
  if (!$found) {
?>
<tr><td colspan="2" bgcolor="white"></td></tr>
<?php
  }
?>
</table>  
<?php
}
?>

Ideas?

Thanks,
Donna
 
No output at all? not even the html stuff that is not being output by PHP?

If so it points to some kind of error early on, however it would seem you have your display errors set to off.

When developing its best to set display errors to E_ALL.

If you have access to the php.ini you can change the directive there.

You can use ini_set('display_errors', 1); to set them to on at runtime, provided any error you would be getting is not fatal. Otherwise the function does not execute.




----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
I added
Code:
<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
require_once("includes/connection.php");
?>

but still nothing. Not even the html stuff when I check the source. Super weird.

Thanks,
Donna
 
That probably means you have a fatal error which prevents the actual ini_set and error_reporting from being executed. It also prevents the file form running and delivering anything back to the browser.

I would take it then one part at a time. See where it starts to choke.

BTW if i run it the first thing it tells me is it has an unexpected closing curly brace at the very end. So I would check that out first.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Hmm - I removed that extra brace and do get some errors now

Here's the revised code
Code:
<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
require_once("includes/connection.php");
?>
<table align="center" width="75%" bgcolor="black">
<tr>
<td bgcolor="white" align="center">
<font size="+2"><b>Ad Showcase Management</b></font>
<p>
<a href="formSC.php">All Records</a> 
<br>
</td>
</tr>
</table>
<?php
  if ($_REQUEST["criteria"]) {
    $result = mssql_query(sprintf("SELECT * FROM advertisers WHERE UPPER(sort_name) LIKE '%s%%'", $_REQUEST["criteria"]));
  } else {
    $result = mssql_query("SELECT * FROM advertisers ORDER BY sort_name");
  }
  $found = 0;
?>
<table width="75%" align="center" bgcolor="black" cellspacing="1">
<tr>
<td width="75%"><font color="white"><b>Advertiser</b></font></td>
<td align="center"><font color="white"><b>Actions</b></font></td>
</tr>
<tr><td bgcolor="white">&nbsp;</td><td bgcolor="white" align="center"><font size="1"><a href="formSC.php">Add New</a></font></td></tr>
<?php
  while ($rec = mssql_fetch_array($result, MSSQL_ASSOC)) {
?>
<tr>
<td bgcolor="white"><?php echo $rec["advertiser_name"] ?></td>
<td bgcolor="white" align="center"><font size="1">
<a href="formSC.php?mode=edit&ID=<?php echo $rec["advertiser_id"] ?>">Edit</a>&nbsp;
<a href="formSC.php?mode=delete&ID=<?php echo $rec["advertiser_id"] ?>">Delete</a>&nbsp;
</font></td>
</tr>
<?php  
  }
  if (!$found) {
?>
<tr><td colspan="2" bgcolor="white"></td></tr>
<?php
  }
?>
</table>

But the error must have something to do with criteria since I keep trying to remove the error lines but keep getting these errors
Code:
Notice: Undefined index: criteria in /Applications/MAMP/htdocs/cape_showcase/TMPj6uka6j4be.php on line 12

Fatal error: Call to undefined function mssql_query() in /Applications/MAMP/htdocs/cape_showcase/TMPj6uka6j4be.php on line 15

But I'm not sure what to put in it's place except the empty square braces.

Thanks,
Donna
 
Where exactly is "criteria" supposed to be coming from? A From, a link? what exactly?

to avoid those kinds of errors you should try to check for the existence of those variables using isset() or empty() before actually using them.

Code:
if(isset($_REQUEST['criteria'])){

As for the second error, it seems your installation of PHP does not have the mssql libraries installed correctly or at all.


----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
the criteria thing is just a notice. the element does not exist in the $_REQUEST array and you are asking php to check whether the element is true. it would be better to check for
Code:
if (!empty($_REQUEST['criteria']))

this would avoid the first error.

the second error exists because you have not enabled the mssql library or it is otherwise not being loaded at runtime. if it is not loaded/compiled in then you will not have access to the mssql_* functions.
 
Thanks, both.

As I mentioned, I was trying to modify from an existing form. I'll look into the criteria thing.

I also need to look at changing the mssql to mysql - I forgot the original had been moved to a different host who doesn't use mysql.

Thanks,
Donna
 
Okay - it works now. The MYSQL_ASSOC all had to be uppercase, but changed and now good.

The working is below in hopes it helps someone else

Code:
<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
require_once("includes/connection.php");
?>
<table align="center" width="75%" bgcolor="black">
<tr>
<td bgcolor="white" align="center">
<font size="+2"><b>Ad Showcase Management</b></font>
<p>
<a href="formSC.php">All Records</a> 
<br>
</td>
</tr>
</table>
<?php
  if (!empty($_REQUEST['criteria'])) {
    $result = mysql_query(sprintf("SELECT * FROM advertisers WHERE UPPER(sort_name) LIKE '%s%%'", $_REQUEST['criteria']));
  } else {
    $result = mysql_query("SELECT * FROM advertisers ORDER BY sort_name");
  }
  $found = 0;
?>
<table width="75%" align="center" bgcolor="black" cellspacing="1">
<tr>
<td width="75%"><font color="white"><b>Advertiser</b></font></td>
<td align="center"><font color="white"><b>Actions</b></font></td>
</tr>
<tr><td bgcolor="white">&nbsp;</td><td bgcolor="white" align="center"><font size="1"><a href="formSC.php">Add New</a></font></td></tr>
<?php
  while ($rec = mysql_fetch_array($result, MYSQL_ASSOC)) {
?>
<tr>
<td bgcolor="white"><?php echo $rec["advertiser_name"] ?></td>
<td bgcolor="white" align="center"><font size="1">
<a href="formSC.php?mode=edit&ID=<?php echo $rec["advertiser_id"] ?>">Edit</a>&nbsp;
<a href="formSC.php?mode=delete&ID=<?php echo $rec["advertiser_id"] ?>">Delete</a>&nbsp;
</font></td>
</tr>
<?php  
  }
  if (!$found) {
?>
<tr><td colspan="2" bgcolor="white"></td></tr>
<?php
  }
?>
</table>

Donna
 
Oh, I will change to add session and login, but at least I have output.

Donna
 
it's a good idea to avoid using $_REQUEST. you should know, as a designer, whether you want to address POST, GET or COOKIE variables and code for that particular use. otherwise the user could subvert your script or at least make it behave badly.
 
Okay - I'll look at that today. That part was part of what I'd found to modify.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top