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

PHP Crashes?

Status
Not open for further replies.

youradds

Programmer
Jun 27, 2001
817
GB
I've got a REALLY weird thing! For some reason, when executing this code PHP CRASHES! I'm on Win 98 with PHP 4.0.6 (upgrading soon). It says the error was a 'stack' problem. Mean anything to anyone? :-|

The code is;

Code:
<?php

// see if they passed an ID number along...

if ($action == &quot;install&quot;) { do_install(); } else { show_setup(); }

/* ######################################## */
/*                 DIVIDER                  */
/* ######################################## */

function show_setup() {

echo <<<TEMPLATE

<html>

<head>
<meta http-equiv=&quot;Content-Language&quot; content=&quot;en-gb&quot;>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=windows-1252&quot;>
<title>Install</title>
</head>

<body>

<font FACE=&quot;Arial&quot; size=&quot;2&quot;><b>
<p align=&quot;center&quot;>Install Script</p>
</b>
<p align=&quot;center&quot;>This script will set up the tables and some sample data in
your desired MySQL database. Please complete the form below and click on
'Continue'. </p>
<form method=&quot;POST&quot;>
  <p align=&quot;center&quot;>SQL Host :
  <input type=&quot;text&quot; size=&quot;20&quot; name=&quot;sql_host&quot; value=&quot;localhost&quot;></p>
  <p align=&quot;center&quot;>SQL Database :
  <input type=&quot;text&quot; size=&quot;20&quot; name=&quot;sql_database&quot;></p>
  <p align=&quot;center&quot;>SQL Username :
  <input type=&quot;text&quot; size=&quot;20&quot; name=&quot;sql_username&quot;></p>
  <p align=&quot;center&quot;>SQL Password :&nbsp;
  <input type=&quot;text&quot; size=&quot;20&quot; name=&quot;sql_password&quot;></p>
  <p align=&quot;center&quot;><input type=&quot;submit&quot; value=&quot;Continue&quot; name=&quot;B1&quot;></p>
  <input type=&quot;hidden&quot; name=&quot;action&quot; value=&quot;install&quot;>
</form>
</font>

</body>

</html>


TEMPLATE;

}


/* ######################################## */
/*                 DIVIDER                  */
/* ######################################## */


function do_install() {

global $sql_host, $sql_username, $sql_password, $sql_database;

// connect to mySQL and if not pass back an error
  $connection = mysql_connect($sql_host, $sql_username, $sql_password);  $error = mysql_error();
       if (!$connection) { sql_error_report(&quot;Unable to connect with your login info for MySQL. Reason: $error&quot;, $connection); }
       if ($debug) { echo &quot;Host connection established....<BR>&quot;; } //a little something for debugging

// now we need to connect the database
  $db = mysql_select_db($sql_database, $connection); $error = mysql_error();
      if (!$db) { sql_error_report(&quot;Unable to connect to database. Reason: $error&quot;, $connection); }
      if ($debug) { echo &quot;Database connection established....<BR>&quot;; } // a little debugging info if needed...

// run the query to update the 'sales' column...
  $query = <<<QUERY

  DROP TABLE IF EXISTS Ace_Mailing;
CREATE TABLE Ace_Mailing (
  SetID int(11) NOT NULL auto_increment,
  PersonName text NOT NULL,
  PersonEmail text NOT NULL,
  SendHTML text NOT NULL,
  UNIQUE KEY SetID (SetID)
) TYPE=MyISAM;

#
# Dumping data for table `Ace_Mailing`
#

INSERT INTO Ace_Mailing VALUES (1,'Test Person','webmaster@test.com.inc','html');
INSERT INTO Ace_Mailing VALUES (2,'Test Person Again','webmaster@somewhere.com.inc','html');

QUERY;

$result = mysql_query($query); $error = mysql_error();
if (!$result) { error(&quot;Unable to execute query to setup database tables! Reason: $error&quot;, $connection); }

mysql_close($connection); // exit the connection so we dont clog up MySQL

echo &quot;MySQL Data seems to have been installed successfully. Now edit settings.inc.php (or do it via the admin panel) and set up the MySQL info there. Then you can login at admin.php with admin/1234.&quot;;


} // end function for redirect page.

/* ######################################## */
/*                 DIVIDER                  */
/* ######################################## */


// hopefully catch those nasty errors!
function error($error) {

$template_read = @file(&quot;errortemplate.htm&quot;);

     if (!$template_read) { error(&quot;Unable to read tempalte file. Please double check it is there.&quot;); }

          foreach ($template_read as $line) {

          // do some preg_matches to replace the tags...
          $return = ereg_replace(&quot;::ERROR::&quot;,    &quot;$error&quot;, $line);

          echo $return;

    } // end the foreach

 exit;

}

/* ######################################## */
/*                 DIVIDER                  */
/* ######################################## */

// error sub in case we get problems with SQL queries etc.
function sql_error_report($error, $connection) {

  echo $error;
  mysql_close($connection); // exit the connection so we dont clog up MySQL
  exit; // exit from the script...we can't do anything now...

 }

?>

Thanks for any help you can offer.

Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top