Jump to content

[SOLVED] How do you write to a specefic area off a file please.


redarrow

Recommended Posts

advance thank you.

 

I have created a install file and the user has to specify there database info,

now, Instead off the user adding the database info again to the con fig file,

 

I need to no how to write the users database info to a specific area where the con fig file wants the database info.

example

 

how do i get the correct database info to the database.php file in it correct order.

<?php
$fp = fopen('database.php', 'w');
$r[]=fwrite($fp, 'localhost');
$r[]=fwrite($fp, 'username');
$r[]=fwrite($fp, 'password');
$r[]=fwrite($fp, 'database_name');
fclose($fp);
?>

 

 

database.php

<?php
$db=mysql_connect("$r[0]","$r[1]","$r[2]");
$res=mysql_select_db("$r[3]",$db);
?>

 

Solved it by creating the whole database statement dynamically.

<?php
$fp = fopen('database.php', 'w');
$r[]=fwrite($fp, '<?php $db=mysql_connect(\''.$connection_type.'\',');
$r[]=fwrite($fp, "'$connection_username',");
$r[]=fwrite($fp, "'$connection_password');");
$r[]=fwrite($fp, "\$bd_res=mysql_select('forum_test',\$db)or die ('Database error'.mysql_error()); ?>");
fclose($fp);

?>

forgot a bit lol

 

<?php
$fp = fopen('database.php', 'w');
$r[]=fwrite($fp, '<?php $db=mysql_connect(\''.$connection_type.'\',');
$r[]=fwrite($fp, "'$connection_username',");
$r[]=fwrite($fp, "'$connection_password');");
$r[]=fwrite($fp, "\$bd_res=mysql_select_bd('forum_test',\$db)or die ('Database error'.mysql_error()); ?>");
fclose($fp);
?>

try the whole code your self if you want ...

 

must create a page called database.php aswell

 

it all works but does not show on here correctly wonder why.

 

 

<?php

$connection_username=$_POST['connection_username'];
$connection_type=$_POST['connection_type'];
$connection_password=$_POST['connection_password'];

if(isset($_POST['submit'])){

$db_name=mysql_connect("$connection_type","$connection_username","$connection_password");

if(!$db_name){

echo" Sorry connnection problam!";

exit;
}

$sql1="CREATE DATABASE forum_test";
$res1=mysql_query($sql1)or die ("Create database error".mysql_error());

$sql2="USE forum_test";
$res2=mysql_query($sql2)or die("Use database error".mysql_error());

$sql3="
create table forum_users(
user_id int auto_increment primary key,
username varchar(50) not null,
password int(70) not null,
email varchar(80) not null,
valadated_digit int(4) not null,
valadated int(2) not null,
secret_number int(4) not null,
ip_address int(20) not null,
timestamp int(50) not null
);
";
$res3=mysql_query($sql3)or die ("Create database forum users error".mysql_error());

$sql4="
create table forum_jobs(
forum_jobs_id int not null auto_increment primary key,
user_id int(10) not null,
job_admin varchar(3) not null,
job_user varchar(3) not null,
job_mod varchar(3) not null,
timestamp int(50) not null
);
";
$res4=mysql_query($sql4)or die ("Create database forum jobs error".mysql_error());

$sql5="
create table forum_login_attemps(
login_id int auto_increment primary key,
ip_address int(20) not null,
attemps int(3) not null,
note varchar(20) default 'login attempt' not null,
timestamp int(50) not null
);
";
$res5=mysql_query($sql5)or die ("Create database forum login attempt error".mysql_error());



$sql6="
create table forums_created(
forum_id int auto_increment primary key,
forum_name text not null,
timestamp int(50) not null
);
";
$res6=mysql_query($sql6)or die ("Create database forums error".mysql_error());

$sql7="
create table forums_user_info(
forums_user_info_id int auto_increment primary key,
user_id int(10) not null,
forum_name text not null,
timestamp int(50) not null
);
";
$res7=mysql_query($sql7)or die ("Create database forum users info error".mysql_error());


$sql8="
create table forum_topics(
topic_id int auto_increment primary key,
user_id int(10) not null,
topic_name text not null,
topic text not null,
solved varchar(3) not null,
topic_locked varchar(3) not null,
report_topic varchar(3) not null,
timestamp int(50) not null
);
";
$res8=mysql_query($sql8)or die ("Create database forum topics error".mysql_error());

$sql9="
create table forum_topic_reply(
topic_reply_id int auto_increment primary key,
topic_id int(10) not null,
user_id int(10) not null,
topic_reply text not null,
report_reply varchar(3) not null,
timestamp int(50) not null
);
";
$res9=mysql_query($sql9)or die ("Create database forum topic reply error".mysql_error());

$sql10="
create table forum_topic_stats(
forum_topic_stats_id int auto_increment primary key,
topic_id int(10) not null,
user_id int(10) not null,
topic_stats int(10) not null,
timestamp int(50) not null
);
";
$res10=mysql_query($sql10)or die ("Create database forum topic stats error".mysql_error());

$sql11="
create table user_messages_receive(
user_messages_receved_id int auto_increment primary key,
user_message_reply_id int(10) not null,
user_id int(10) not null,
forum_name text not null,
user_message text not null,
read_reply varchar(3) not null,
sent_reply varchar(3) not null,
message_blocked varchar(3) not null,
report_message varchar(3) not null,
timstamp int(50) not null
);
";
$res11=mysql_query($sql11)or die ("Create database forum messages recevied error".mysql_error());#

$sql12="
create table user_messages_sent(
user_message_reply_id int auto_increment primary key,
user_message_receved_id int(10) not null,
userid int(10) not null,
topic_name text not null,
user_reply text not null,
read_reply varchar(3) not null,
replyed varchar(3)  not null,
report_message varchar(3) not null,
timestamp int(50) not null
);
";

$res12=mysql_query($sql12)or die ("Create database forum messages sent error".mysql_error());


if($res1 && $res2 && $res3 && $res4 && $res4 && $res5 && $res6 && $res7 && $res8 && $res9 && $res10 && $res11 && $res12){

$fp = fopen('database.php', 'w');
$r[]=fwrite($fp, '<?php $db=mysql_connect(\''.$connection_type.'\',');
$r[]=fwrite($fp, "'$connection_username',");
$r[]=fwrite($fp, "'$connection_password');");
$r[]=fwrite($fp, "\$bd_res=mysql_select_bd('forum_test',\$db)or die ('Database error'.mysql_error()); ?>");
fclose($fp);


echo " Database installed, please delete the file name install.php";

exit;
}
}
?>

<center><h3>Please provide database information below!</h3></center>
<center>
<form method="POST" action="<?php $_SERVER['PHP_SELF']; ?>">
<br><br>
Please provide valid database connection type
<br> 
Example: localhost or ip 192.0.0.0
<br><br>
<input type="text" name="connection_type">
<br><br>
Please provide valid database username
<br> <br>
<input type="text" name="connection_username">
<br><br>
Please provide valid database password
<br> <br>
<input type="password" name="connection_password">
<br> <br> 
<input type="submit" name="submit" value="Create forum database!">
</form> 
</center>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.