I would like to save to database but not file. please help me and show me how i can change from file to databasetables.

****users*****
<?php

function saveUsers($onlineusers_file){
$file_save=fopen("onlineusers_".$_POST…
flock($file_save,LOCK_EX);
for($line=0;$line<count($onlineusers_f…
fputs($file_save,$onlineusers_file[$li…
};
flock($file_save,LOCK_UN);
fclose($file_save);
}


$onlineusers_file=file("onlineusers_".…
if (isset($_POST['user'],$_POST['oper'])){
$user=$_POST['user'];
$oper=$_POST['oper'];
$userexist=in_array($user,$onlineusers…
if ($userexist)$userindex=array_search($use…

if($oper=="signin" && $userexist==false){
$onlineusers_file[]=$user;
saveUsers($onlineusers_file);
echo "signin";
exit();
}

if($oper=="signin" && $userexist==true){
echo "userexist";
exit();
}

if($oper=="signout" && $userexist==true){
array_splice($onlineusers_file,$userin…
saveUsers($onlineusers_file);
echo "signout";
exit();
}

if($oper=="signout" && $userexist==false){
echo "usernotfound";
exit();
}
}
$olu=join("<br>",$onlineusers_file);
echo $olu;

?>

*****send*******
<?php
$message=strip_tags($_POST['message'])…
$message=stripslashes($message);
$user=$_POST['user'];
$touser=$_POST['touser'];

$room="room_".$_POST['room'].".txt";

$room_file=file($room,FILE_IGNORE_NEW_…

$room_file[]=time()."<!@!>".$user."<!@…
if (count($room_file)>20)$room_file=array_s…
$file_save=fopen($room,"w+");
flock($file_save,LOCK_EX);
for($line=0;$line<count($room_file);$l…
fputs($file_save,$room_file[$line]."\n…
};
flock($file_save,LOCK_UN);
fclose($file_save);
echo "sentok";
exit();
?>

*******receive*********
<?php
$lastreceived=$_POST['lastreceived'];
$user=$_POST['user'];

$room="room_".$_POST['room'].".txt";
$room_file=file($room,FILE_IGNORE_NEW_…
$pattern = '/:(\w+):/';
$replacement = "<img src='./emotions/$1.png' />";
$hasMessage=false;
for($line=0;$line<count($room_file);$l…
$messageArr=explode("<!@!>",$room_fil…
if(count($messageArr)>1){
$touser=$messageArr[2];
if(in_array($user,explode(",",$messa… || $user==$messageArr[1] || $touser==""){
if($messageArr[0]>$lastreceived){
echo $messageArr[1].": ".preg_replace($pattern,$replacement,$me…
$hasMessage=true;
}
}
}
}
echo ($hasMessage)?"<SRVTM>".$messageArr[0]:"…
?>

First you need to find out if your host supports mysql then you need to set up a database and a connect it to your directory. Connection page looks like this

<? $mysql_server = "localhost";
$mysql_user = "Denis";
$mysql_password = "daniweb";
$mysql_database = "daniweb";

$connection = mysql_connect("$mysql_server","$mysql_user","$mysql_password") or die ("Connection error");

$db = mysql_select_db("$mysql_database") or die ("Connection error");
?>

then you need to create tables to save your data. It looks like this

CREATE TABLE daniweb(
  id int(11) NOT NULL auto_increment,
  name varchar(20) NOT NULL default '',
  email text NOT NULL,
  etc int(11) NOT NULL default '0',
  data varchar(50) NOT NULL default '',
  etc char(1) NOT NULL default '1',
  PRIMARY KEY  (id)
) ENGINE=MyISAM AUTO_INCREMENT=13421 DEFAULT CHARSET=latin1;

now you will be able to save your data inside the tables and update it whenever.

at the connect to database and creating tables, that i know. but the only thing that i cant understand with my script is how to change from textfile to mysql. tyr give me an example by using my script, lets say, from the function --saveUsers($onlineusers_file){

on users.php.

or should i say how to querry i dont know which terms to use exactly

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.