Johns3n Posted January 8, 2010 Share Posted January 8, 2010 Hey all at PHP freaks! First off! Thanks for solving my previous problem very quickly and swiftly! Sure helped me alot! Now i'm once again in a position where i need the help of people who are alot more talented with PHP than me! (I only took it up, half a year ago, before that it was strictly HTML, CSS) I have created a little CMS blog system which works perfectly! Save for one little file! The installer file i have created! When i try to run it on a server, it just does nothing for me! Which means there is a mistake somewhere xD But I have spent like 1 hour looking over it and couldn't find it! Therefor i was hoping that one of you, could donate a little time to look over my installer code, and maybe see the problem? as i am afraid that i stared myself blind Here is the code: <?php //This gets all the data from the form $hostname=$_POST['hostname']; $databasename=$_POST['databasename']; $db_username=$_POST['db_username']; $db_password=$_POST['db_password']; $prefix=$_POST['prefix']; $username=$_POST['username']; $password=$_POST['password']; $realname=$_POST['realname']; $con = mysql_connect("" . $hostname . "","" . $db_username . "","" . $db_password . ""); if (!$con) { die('Ohh no! Could not connect: ' . mysql_error() 'Are you sure that you wrote the correct data in the installer?'); } // Selects the Database mysql_select_db("" . $databasename . "", $con); // Create tables $posts = "CREATE TABLE '".$prefix."'posts ( id int(3) not null auto_increment, title varchar(250), content text, date varchar(250), author varchar(250) )"; $users = "CREATE TABLE '".$prefix."'users ( id int(3) not null auto_increment, username varchar(250), password varchar(250), realname varchar(250) )"; // Execute query to create tables mysql_query($posts,$users,$con); // Writes the admin user into the database mysql_query("INSERT INTO '".$prefix."'users VALUES ('$id', '$username', '$password', '$realname')"); // Close the mySQL connection mysql_close($con); // Write the config.php file $filename = 'config.php'; $configs = "<?php // Connection string $con = mysql_connect('" . $hostname . "','" . $db_username . "','" . $db_password . "'); // If no connection is made generate a error warning if (!$con) { die('Ohh no! Could not connect: ' . mysql_error() 'Please check the Connection String, in the insertpost.php file!'); } // Selects the Database mysql_select_db('" . $databasename . "', $con); $db_prefix = " . $prefix . " ?> \n"; // Make sure that config.php is writeable if (is_writable($filename)) { // Open config.php if (!$handle = fopen($filename, 'a')) { echo "Cannot open file ($filename)"; exit; } // Write content to config.php if (fwrite($handle, $configs) === FALSE) { echo "Cannot write to file ($filename)"; exit; } // If it works! Yeah for us! echo "Success! You have now installed Lörk! Happy Bloggin!"; fclose($handle); } else { // If not! That sucks echo "The file $filename is not writable"; } ?> Again! Thank you alot for your time to gelp out a huge noob at PHP! Quote Link to comment https://forums.phpfreaks.com/topic/187726-problem-with-installer-php-file/ Share on other sites More sharing options...
JAY6390 Posted January 8, 2010 Share Posted January 8, 2010 I've spotted a few things immediately firstly $con = mysql_connect("" . $hostname . "","" . $db_username . "","" . $db_password . ""); doesn't need any of the "" or the . in it. This is fine $con = mysql_connect($hostname,$db_username,$db_password); Secondly you have '".$prefix."'users in your queries to create the tables. this will make something like CREATE TABLE 'prefix'users which won't work Thirdly you have this line mysql_query($posts,$users,$con); mysql_query doesn't accept more than one query at a time, you have two plus the connection hanlde. It only accepts two parameters (http://www.php.net/mysql_query) I stopped there as I think that gives you enough to work on for now Quote Link to comment https://forums.phpfreaks.com/topic/187726-problem-with-installer-php-file/#findComment-991095 Share on other sites More sharing options...
Johns3n Posted January 8, 2010 Author Share Posted January 8, 2010 Thanks for the swift answer mate I took a look at the things you pointed out and tried to apply them to where else i might see a similar problem, i tried running the script once again, but it still fails on me, so there for i turn to you again! The new and updated code: <?php //This gets all the data from the form $hostname=$_POST['hostname']; $databasename=$_POST['databasename']; $db_username=$_POST['db_username']; $db_password=$_POST['db_password']; $prefix=$_POST['prefix']; $username=$_POST['username']; $password=$_POST['password']; $realname=$_POST['realname']; $con = mysql_connect($hostname,$db_username,$db_password); if (!$con) { die('Ohh no! Could not connect: ' . mysql_error() 'Are you sure that you wrote the correct data in the installer?'); } // Selects the Database mysql_select_db($databasename,$con); // Create tables $posts = "CREATE TABLE "$prefix"posts ( id int(3) not null auto_increment, title varchar(250), content text, date varchar(250), author varchar(250) )"; // Execute query to create tables mysql_query($posts,$con); $users = "CREATE TABLE "$prefix"users ( id int(3) not null auto_increment, username varchar(250), password varchar(250), realname varchar(250) )"; // Execute query to create tables mysql_query($users,$con); // Writes the admin user into the database mysql_query("INSERT INTO ".$prefix."users VALUES ('$id', '$username', '$password', '$realname')"); // Close the mySQL connection mysql_close($con); // Write the config.php file $filename = 'config.php'; $configs = "<?php // Connection string $con = mysql_connect("$hostname","$db_username","$db_password"); // If no connection is made generate a error warning if (!$con) { die('Ohh no! Could not connect: ' . mysql_error() 'Please check the Connection String, in the insertpost.php file!'); } // Selects the Database mysql_select_db("$databasename", $con); $db_prefix = "$prefix" ?> \n"; // Make sure that config.php is writeable if (is_writable($filename)) { // Open config.php if (!$handle = fopen($filename, 'a')) { echo "Cannot open file ($filename)"; exit; } // Write content to config.php if (fwrite($handle, $configs) === FALSE) { echo "Cannot write to file ($filename)"; exit; } // If it works! Yeah for us! echo "Success! You have now installed Lörk! Happy Bloggin!"; fclose($handle); } else { // If not! That sucks echo "The file $filename is not writable"; } ?> again! Thanks alot for your time! as im starting to turn grey haired here! ^^ Quote Link to comment https://forums.phpfreaks.com/topic/187726-problem-with-installer-php-file/#findComment-991112 Share on other sites More sharing options...
JAY6390 Posted January 8, 2010 Share Posted January 8, 2010 I'm guessing you don't have error reporting on at the top of your script put error_reporting(E_ALL); and run it again. See what errors you get Here's one you should get it about "CREATE TABLE "$prefix"users There should be . either side of $prefix to concatenate it Quote Link to comment https://forums.phpfreaks.com/topic/187726-problem-with-installer-php-file/#findComment-991114 Share on other sites More sharing options...
Johns3n Posted January 8, 2010 Author Share Posted January 8, 2010 Didn't know where such a thing as a error reporting! thanks for pointing that out to me! Maybe that could have saved myself a headache! ^^ il try and get back if i can't work it out by then! Thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/187726-problem-with-installer-php-file/#findComment-991118 Share on other sites More sharing options...
JAY6390 Posted January 8, 2010 Share Posted January 8, 2010 haha how you've managed this long without knowing about it I dont know. What setup are you using? is this on a local host through WAMP, XAMPP or something or a remote server? Quote Link to comment https://forums.phpfreaks.com/topic/187726-problem-with-installer-php-file/#findComment-991119 Share on other sites More sharing options...
Johns3n Posted January 8, 2010 Author Share Posted January 8, 2010 Can't seem to get error reporting to work, still just shows a blank page when i run it Im using my brothers mySQL database and ftp server to test it out.. I've included the whole file now, since what i read about error reporting it only shows the error if the error code snippet is above it: <!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> <meta name="Robots" content="NONE" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link href="cms.css" rel="stylesheet" type="text/css" media="all" /> <title>Lörk CMS - Installing!</title> </head> <body> <?php error_reporting(E_ALL); //This gets all the data from the form $hostname=$_POST['hostname']; $databasename=$_POST['databasename']; $db_username=$_POST['db_username']; $db_password=$_POST['db_password']; $prefix=$_POST['prefix']; $username=$_POST['username']; $password=$_POST['password']; $realname=$_POST['realname']; $con = mysql_connect($hostname,$db_username,$db_password); if (!$con) { die('Ohh no! Could not connect: ' . mysql_error() 'Are you sure that you wrote the correct data in the installer?'); } // Selects the Database mysql_select_db($databasename,$con); // Create tables $posts = "CREATE TABLE ". $prefix ."posts ( id int(3) not null auto_increment, title varchar(250), content text, date varchar(250), author varchar(250) )"; // Execute query to create tables mysql_query($posts,$con); $users = "CREATE TABLE ". $prefix ."users ( id int(3) not null auto_increment, username varchar(250), password varchar(250), realname varchar(250) )"; // Execute query to create tables mysql_query($users,$con); // Writes the admin user into the database mysql_query("INSERT INTO ".$prefix."users VALUES ('$id', '$username', '$password', '$realname')"); // Close the mySQL connection mysql_close($con); // Write the config.php file $filename = 'config.php'; $configs = "<?php // Connection string $con = mysql_connect("$hostname","$db_username","$db_password"); // If no connection is made generate a error warning if (!$con) { die('Ohh no! Could not connect: ' . mysql_error() 'Please check the Connection String, in the insertpost.php file!'); } // Selects the Database mysql_select_db("$databasename", $con); $db_prefix = "$prefix" ?> \n"; // Make sure that config.php is writeable if (is_writable($filename)) { // Open config.php if (!$handle = fopen($filename, 'a')) { echo "Cannot open file ($filename)"; exit; } // Write content to config.php if (fwrite($handle, $configs) === FALSE) { echo "Cannot write to file ($filename)"; exit; } // If it works! Yeah for us! echo "Success! You have now installed Lörk! Happy Bloggin!"; fclose($handle); } else { // If not! That sucks echo "The file $filename is not writable"; } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/187726-problem-with-installer-php-file/#findComment-991134 Share on other sites More sharing options...
wildteen88 Posted January 8, 2010 Share Posted January 8, 2010 This is probably your problem $configs = "<?php // Connection string $con = mysql_connect("$hostname","$db_username","$db_password"); // If no connection is made generate a error warning if (!$con) { die('Ohh no! Could not connect: ' . mysql_error() 'Please check the Connection String, in the insertpost.php file!'); } // Selects the Database mysql_select_db("$databasename", $con); $db_prefix = "$prefix" ?> \n"; You'd be better of using HEREDOC syntax. $configs = <<<PHPCODE <?php // Connection string \$con = mysql_connect("$hostname","$db_username","$db_password"); // If no connection is made generate a error warning if (!\$con) { die('Ohh no! Could not connect: ' . mysql_error() 'Please check the Connection String, in the insertpost.php file!'); } // Selects the Database mysql_select_db("$databasename", \$con); \$db_prefix = "$prefix" ?> PHPCODE; Quote Link to comment https://forums.phpfreaks.com/topic/187726-problem-with-installer-php-file/#findComment-991182 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.