BoltZ Posted November 1, 2008 Share Posted November 1, 2008 I have this code <?php /** * BBoardX 1.0 BETA * Copyright © 2008 BBoardX, All Rights Reserved * * Website: http://www.bboardx.com * License: http://www.bboardx.com/license * */ $myFile = "connect.php"; $fh = fopen($myFile, 'w') or die("can't open file"); $stringData = "<?php\n $db = mysql_connect({$_POST['req_db_host']},{$_POST['username']},{$_POST['password']}) or die('Could not connect');\n $admin_email={$_POST['admin_email']};\n $admin_password={$_POST['admin_password']};\n if(!$db)\n die('no db');\n if(!mysql_select_db({$_POST['database']},$db))\n die('No database selected.');\n if(get_magic_quotes_gpc())\n {\n $_GET = array_map('stripslashes', $_GET);\n $_POST = array_map('stripslashes', $_POST);\n $_COOKIE=array_map('stripslashes', $_COOKIE);\n }\n $_GET = array_map('mysql_real_escape_string', $_GET);\n $_POST = array_map('mysql_real_escape_string', $_POST);\n $_COOKIE = array_map('mysql_real_escape_string', $_COOKIE);\n ?>"; fwrite($fh, $stringData); fclose($fh); Header ('Location runsql.php'); ?> and not one forum has been able to answer me why the code does not write to the connect.php file. Cmon guys be the first to answer why it wont work Quote Link to comment https://forums.phpfreaks.com/topic/131014-php-code-wont-write-to-file/ Share on other sites More sharing options...
.josh Posted November 1, 2008 Share Posted November 1, 2008 First thing I notice is this: ?>"; should be this: ";?> edit: or actually, no ?> at all. Just "; Quote Link to comment https://forums.phpfreaks.com/topic/131014-php-code-wont-write-to-file/#findComment-680160 Share on other sites More sharing options...
.josh Posted November 1, 2008 Share Posted November 1, 2008 okay I lied, I actually looked at the rest of the code. I believe your error is actually here: Header ('Location runsql.php'); forgot the : after Location. Quote Link to comment https://forums.phpfreaks.com/topic/131014-php-code-wont-write-to-file/#findComment-680164 Share on other sites More sharing options...
.josh Posted November 1, 2008 Share Posted November 1, 2008 Although...connect.php was being written to just fine for me. If it's not writing at all for you, check your file's permissions (CHMOD) make sure it has correct permissions. I did notice that the globals were not being written or else just being written as "Array" is that what you're talking about? It's because you are using double quotes instead of single in your string assignment to $stringData, so it's parsing them as variables. (sorry for triple post...I see that you're in the thread so editing posts makes it confusing) Quote Link to comment https://forums.phpfreaks.com/topic/131014-php-code-wont-write-to-file/#findComment-680169 Share on other sites More sharing options...
BoltZ Posted November 1, 2008 Author Share Posted November 1, 2008 Lol i was staring at your first post for like 4 minutes and checking my code and i was like wtf is he talking about that part is being written to the file...what...huh...lol Ok well ill check the settings and in the mean time can you show me what u mean with the " and the ' like switching them? btw nice catch on the missing location lol Quote Link to comment https://forums.phpfreaks.com/topic/131014-php-code-wont-write-to-file/#findComment-680173 Share on other sites More sharing options...
BoltZ Posted November 1, 2008 Author Share Posted November 1, 2008 well ima about to go and drive to some bingo stuff. I changed all the files in the directory to 0755. It still doesn't work. Ill post my entire code here so you can try it index.php <?php /** * RemoteBB 1.0 BETA * Copyright © 2008 RemoteBB, All Rights Reserved * * Website: http://www.RemoteBB.com * License: http://www.RemoteBB.com/license * */ session_start(); if(!isset($_SESSION['current_step'])) $_SESSION['current_step'] = 1; //lets check to see if step in in the url using isset. If it isnt, default step to one $step = isset($_GET['step']) ? $_GET['step'] : 1; if($step <= $_SESSION['current_step']){ switch($step){ case 1: $_SESSION['current_step'] == 2; ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" > <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>RemoteBB Installation Wizard</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta name="description" content="" /> <link rel="icon" type="image/gif" href="../favicon.ico" /> <?php if (strpos($_SERVER['HTTP_USER_AGENT'], 'Firefox') !== FALSE) { echo '<link rel="stylesheet" type="text/css" href="stylesheet.css" />'; } else if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE) { echo '<link rel="stylesheet" type="text/css" href="iestyle.css" />'; } else{ echo '<link rel="stylesheet" type="text/css" href="stylesheet.css" />'; } ?> </head><body> <div class="bluestrip">RemoteBB Installation Wizard</div> <table><tr><td> <div class="rightside"><div class="top"> <h1>Installation Wizard</h1><div class="logo" style="display:inline"><img src="images/logo.gif" alt="banner" style="width:60%; margin-top:25px;" /></div></div></div> <div class="content"><p>Welcome to the first step to installing your very own RemoteBB Forums! When you are done with this easy setup, you will have a RemoteBB style forum on your website. </p><br /> <p>When you are finished entering in your values please click the Finish Installation button<br /><br /></p> <div class="note"><p> <i>Note</i>: When entering your host configuration, if you are not sure about the values please ask your web host for the details. Remember to enter all fields marked with a * as they are required fields. Please note that this installation does not upgrade a forum version<br /></p></div><p><br /></p> <form action="runsql.php" method="post"> <div><div><div><div><fieldset> <legend>Select your database type</legend> <div><label><strong>Database type</strong> <br /><select name="req_db_type"> <option value="mysqli">MySQL Improved</option> <option value="mysql">MySQL Standard</option> </select> <br /></label> </div></fieldset></div><div><fieldset> <legend>Enter your database server hostname</legend> <div> <p>The address of the database server For most cases leave this at localhost.</p> <label><strong>Database server hostname</strong><br /><input type="text" name="req_db_host" value="localhost" size="50" maxlength="100" /><br /></label> </div> </fieldset> </div><div> <fieldset><legend>Enter then name of your database</legend> <div> <p>The name of the database that RemoteBB will be installed into. The database must exist.</p> <label for="req_db_name"><strong>Database name</strong><br /><input id="req_db_name" type="text" name="database" size="30" maxlength="50" /><br /></label> </div> </fieldset> </div> <div> <fieldset> <legend>Enter your database username and password</legend> <div> <p>Enter the username and password with which you connect to the database.</p> <label><strong>Database username</strong><br /><input type="text" name="username" size="30" maxlength="50" /><br /></label> <label><strong>Database password</strong><br /><input type="text" name="password" size="30" maxlength="50" /><br /></label> </div> </fieldset> </div> <div> <fieldset> <legend>Enter database table prefix</legend> <div> <p>If you like you can specify a table prefix. This way you can run multiple copies of RemoteBB in the same database (example: bb_).</p> <label><strong>Table prefix</strong><br /><input id="db_prefix" type="text" name="db_prefix" size="20" maxlength="30" /><br /></label></div> </fieldset> </div><div><div> <h3>Administration setup</h3> <p>Please enter the requested information in order to setup an administrator for your RemoteBB installation</p><br /> </div><fieldset><legend>Enter Administrators username</legend><div> <p>The username of the forum administrator. You can later create more administrators and moderators. Usernames can be between 3 and 25 characters long.</p> <label><strong>Administrator username</strong><br /><input type="text" name="admin" size="25" maxlength="25" /><br /></label></div> </fieldset></div> <div> <fieldset> <legend>Enter and confirm Administrator password</legend> <div> <p>Passwords can be between 4 and 16 characters long. Passwords are case sensitive.</p> <label><strong>Password</strong><br /><input id="req_password1" type="text" name="admin_password" size="16" maxlength="16" /><br /></label> <label><strong>Confirm password</strong><br /><input type="text" name="admin_password1" size="16" maxlength="16" /><br /></label> <div></div></div></fieldset></div> <div><fieldset> <legend>Enter Administrator's e-mail</legend> <div> <p>The e-mail address of the forum administrator.</p> <label for="req_email"><strong>Administrator's e-mail</strong><br /><input id="req_email" type="text" name="admin_email" size="50" maxlength="50" /><br /></label> </div></fieldset> </div></div></div></div> <div class="button"> <div class="input"> <input type="submit" value="Finish Installation" alt="Submit button" name="step1" /> </div> </form><br /><br /></div></div></td></tr></table></body></html> <?php break; case 2: ?> ###################### #FINISH INSTALLATION # ###################### <?php break; } } ?> <?php //step 1.php //your process logic, saving data etc. $errors = false; //chage this if the user does not pass your step 1 requirements if(!$errors){ //rewrite the session current step var $next_step = 2; if($_SESSION['current_step'] < $next_step) $_SESSION['current_step'] = $next_step; //your link should look like index.php?step={$next_step} } ?> install.php <?php /** * BBoardX 1.0 BETA * Copyright © 2008 BBoardX, All Rights Reserved * * Website: http://www.bboardx.com * License: http://www.bboardx.com/license * */ $myFile = "connect.php"; $fh = fopen($myFile, 'w') or die("can't open file"); $stringData = "<?php\n $db = mysql_connect({$_POST['req_db_host']},{$_POST['username']},{$_POST['password']}) or die('Could not connect');\n $admin_email={$_POST['admin_email']};\n $admin_password={$_POST['admin_password']};\n if(!$db)\n die('no db');\n if(!mysql_select_db({$_POST['database']},$db))\n die('No database selected.');\n if(get_magic_quotes_gpc())\n {\n $_GET = array_map('stripslashes', $_GET);\n $_POST = array_map('stripslashes', $_POST);\n $_COOKIE=array_map('stripslashes', $_COOKIE);\n }\n $_GET = array_map('mysql_real_escape_string', $_GET);\n $_POST = array_map('mysql_real_escape_string', $_POST);\n $_COOKIE = array_map('mysql_real_escape_string', $_COOKIE);\n ?>"; fwrite($fh, $stringData); fclose($fh); Header ('Location: runsql.php'); ?> runsql.php <?php /** * RemoteBB 1.0 BETA * Copyright © 2008 RemoteBB, All Rights Reserved * * Website: http://www.RemoteBB.com * License: http://www.RemoteBB.com/license * */ session_start(); if(!isset($_SESSION['current_step'])) $_SESSION['current_step'] = 1; else if(isset($_SESSION['current_step']) == 1) $_SESSION['current_step'] = 2; else if(isset($_SESSION['current_step']) == 2) $_SESSION['current_step'] = 3; Header('Location: index.php?step=' . $_SESSION['current_step']); ?> then of course connect.php if you want the images just click the link in my signature and thats the page for all this stuff thanks , bb in like 3 hours Quote Link to comment https://forums.phpfreaks.com/topic/131014-php-code-wont-write-to-file/#findComment-680187 Share on other sites More sharing options...
BoltZ Posted November 2, 2008 Author Share Posted November 2, 2008 no ideas? Quote Link to comment https://forums.phpfreaks.com/topic/131014-php-code-wont-write-to-file/#findComment-680301 Share on other sites More sharing options...
BoltZ Posted November 2, 2008 Author Share Posted November 2, 2008 HAAHAHAHAHHAHAHAH EZEZEZEZEZEZ FIGURED ITTTTT i had <form action="runsql.php" method="post> and in that file it didnt redirect to install.php where the fwrite function was in so it never got referenced and it works now EZEZEZEEZEZEZEZEZ [/happyness] yay i feel smart now cuz i thought like a programmer. i was like ok everyone says its correct so lets go through all the files in the process in order. ok index.php, that goes to runsql.php, ....OMG ITS NOT REFERENCING INSTALL.PHP =D Quote Link to comment https://forums.phpfreaks.com/topic/131014-php-code-wont-write-to-file/#findComment-680313 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.