PHP - Backing Up Mysql Database Help
I'm trying to create a page that allows people to backup their database on a web page but I'm having trouble with the ending of it.
<?php require("../include/config.php"); $tables = array(); $qTables = mysql_query("SHOW TABLES"); while($row = mysql_fetch_row($qTables)) { $tables[] = $row[0]; } foreach($tables as $tab1) { $return.= "DROP TABLE IF EXISTS `".$tab1."`;"; $row2 = mysql_fetch_row(mysql_query("SHOW CREATE TABLE `" . $tab1 . "`")); $return.= "\n\n".$row2[1].";\n\n"; $result = mysql_query("SELECT * FROM ".$tab1) or die(mysql_error()); $num_fields = mysql_num_fields($result); $return.= "INSERT INTO `".$tab1."`"; $col = mysql_query('SELECT * FROM '.$tab1); $a = 0; $return.= " ("; while ($a < mysql_num_fields($col)) { $meta = mysql_fetch_field($col, $a); $return.= "`" . "$meta->name"; $a++; if ($a < mysql_num_fields($col)) { $return.= "`,"; } else { $return.= "`"; } } $return.= ")"; $return.=" VALUES\n("; for ($i = 0; $i < $num_fields; $i++){ while($row = mysql_fetch_row($result)){ for($j=0; $j<$num_fields; $j++){ if (isset($row[$j])) { $return.= "'".$row[$j]."'" ; } else { $return.= "''"; } if ($j < ($num_fields-1)) { $return.= ","; } if (j < ($num_fields-1)){ $return.= "),\n("; } else { $return.= ");\n"; } } } } } $handle = fopen("db-backup-".time()."-".(md5(implode(",",$tables))).".sql","w+"); fwrite($handle,$return); ?> At this part: if (j < ($num_fields-1)){ $return.= "),\n("; } else { $return.= ");\n"; } If it has finished going through all of the values it will put ); at the end and if it hasn't it will put ), and then continue with the next one. The problem I'm having is it's only doing the ), Can someone help me please? Similar TutorialsNot sure if this is the correct subsection, I CTRL + F'd the first page and didn't see FTP
I'm interested in backing up data, I'm building a social media type website and I need to back up data. I don't have a lot of money at the moment so I would like to back up to my own computer/external hard drive... doesn't seem smart I guess but it is a solution for now
I currently use linux / have apache on my local machine but on my hosting service provider they use Apache as well
Their backup options seem "word for dumb" and I can't have that, imagine how much data would be lost if it didn't back up within minutes rather than 10 days or some stupid figure like that...
I mean... maybe I'm missing something, how else would it be done?
I expect the site to have life pretty much at every passing moment of time and if the site goes down for even 5 minutes... how many megabytes of data or more did I just lose?
Anyway, my laptop/external hard drive seems dumb but it is relative to my situation as I am currently testing out my ventures with a shared VPS (as in 3 different domains pointing to that website) and the space I have is 90 GB, between my external hard drive and laptop I have more than that.
I suppose I should "trust" in the professionalism of my service provider but the fact that their back up system is literally like every 10 days and I have to pay $150 to retrieve my data... I don't even understand the pricing on that... what is the difference if they backed up terabytes as opposed to petabytes, is it still the same $150.00?
Anyway, I'd appreciate any help, or I'll just search elsewhere later on when this topic becomes relevant again
(hmm I don't present myself well I realize that)
Does anybody know any good aplication that is free, to back up a website? i need to back it up every day. Or does someone have the php script for the same purpose? thanks! At the moment I am creating a search function for my website. The approach I have in mind is a pseudo-PHP database. To give an example: A HTML form will submit the results to a PHP file. HTML FORM - Colour: Black PHP RESULT PAGE - if ($_POST['color'] == 'Black') {readfile("./products/black/*.html");} HTML FORM - Price: <$50 PHP RESULT PAGE - if ($_POST['Price'] == '<$50') {readfile("./products/less50/*.html");} The problem here is if there is an item that is black and costs less than $50, then its going to be listed twice. There is probably some code I can write to ommit the listing of duplicate entries, but it is probably going to be messy, so I am wondering if its better to use a centralized MySQL database, rather than a pseudo-PHP database? I've never used MySQL and don't know much about it and this is my first real attempt at using PHP. How would I go about doing the following: I have a csv like this Quote "Division","Section","Group","Product Code","Description","Description + Secondary Description" "Division 1","Section 1","Group 1","BMSLPL25","Test Name","Test Description" "Division 1","Section 1","Group 2","BMSLPL26","Test Name 2","Test Description 2" "Division 2","Section 2","Group 2","BMSLPL27","Test Name 3","Test Description 3" I have a database structured like this Quote Divisions --- id name parent_id Groups --- id name division_id Products --- id code description secondary_description Section is a sub division. What is the best way to get the information from CSV into this database? Should I have another table and store the CSV data as is and then query that to make the other tables. Any help much appreciated. Hi, I wonder if you could help me try to find what i'm looking for, i have a problem with bogus users on my site. I created a register page where the details are sent to the database, this is fine but someone is registering with the username: 1 and password: 1 multiple times. I have about 50 of these now and i would like to know what to actually search for (how to word it) to find out how to stop this? What would be the name of the script? i've looked for fake username script, multiple username/password prevention script, i'm just not getting it, sorry. If any of you have any ideas i'd like to hear from you, many thanks in advance for that. If you need anymore to go on please ask, once again thank you. I've tried reading through some of the threads but couldnt understand some of them. I've made a newsfeed script which works how i want it to. Now i want to add the function to delete a row from the database from an "admin panel" on the website. So far i have this: <?php include("includes.php"); doConnect(); $get_news = "SELECT id, title, text, DATE_FORMAT(datetime, '%e %b %Y at %T') AS datetime FROM newsfeed ORDER BY datetime DESC"; $result= mysqli_query($mysqli, $get_news) or die(mysqli_error($mysqli)); while ($row = mysqli_fetch_array($result)) { echo '<strong><font size="3">'. $row['title'] .' </font></strong><br/><font size="3">'. $row['text'] .'</font><br/><font size="2">'. $row['datetime'] .'</font><br/><br/><a href="delnews.php?del_id=' .$row['id']. '"> <strong>DELETE</strong></a>';} ?> then my delnews.php is: <?php include("includes.php"); doConnect(); $query = "DELETE FROM newsfeed WHERE id = "$_POST['id']""; $result = mysql_query($query); echo "The data has been deleted."; ?> I believe the problem is $_POST['id']. i've tried different things in there but none work. It displays the echo line but doesnt actually delete anything. I am new to php so this may be a stupid mistake, but try and play nice! Thanks Hi guys, I need your help. I am checking on a database as I want to see if I have the same value in the url and in the database. Code: [Select] <?php session_start(); define('DB_HOST', 'localhost'); define('DB_USER', 'mydbuser'); define('DB_PASSWORD', 'mydbpass'); define('DB_DATABASE', 'mydbtable'); $errmsg_arr = array(); $errflag = false; $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } function clean($var){ return mysql_real_escape_string(strip_tags($var)); } $username = clean($_GET['user']); $password = clean($_GET['pass']); $test = clean($_GET['test']); $public = clean($_GET['public']); if (isset($_GET['user']) && (isset($_GET['pass']))) { if($username == '' || $password == '') { $errmsg_arr[] = 'username or password are missing'; $errflag = true; } } elseif (isset($_GET['user']) || (isset($_GET['test'])) || (isset($_GET['public']))) { if($username == '' || $test == '' || $public == '') { $errmsg_arr[] = 'user or others are missing'; $errflag = true; } } if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; echo implode('<br />',$errmsg_arr); } else { $qry="SELECT * FROM members WHERE username='$username' AND passwd='$password'"; $result=mysql_query($qry) or die('Error:<br />' . $qry . '<br />' . mysql_error()); if ($username && $password) { if(mysql_num_rows($result) > 0) { $qrytable1="SELECT images, id, test, links, Public FROM user_list WHERE username='$username'"; $result1=mysql_query($qrytable1) or die('Error:<br />' . $qry . '<br />' . mysql_error()); while ($row = mysql_fetch_array($result1)) { echo "<p id='test'>"; echo $row['test'] . "</p>"; echo '<p id="images"> <a href="images.php?test=test&id='.$row['id'].'">Images</a></td> | <a href="http://' . $row["links"] . '">Link</a> </td> | <a href="delete.php?test=test&id='.$row['id'].'">Delete</a> </td> | <span id="test">'.$row['Public'].'</td>'; } } else { echo "user not found"; } } elseif($username && $test && $public) { $qry="SELECT * FROM members WHERE username='$username'"; $result1=mysql_query($qry) or die('Error:<br />' . $qry . '<br />' . mysql_error()); if(mysql_num_rows($result1) > 0) { $qrytable1="SELECT Public FROM user_list WHERE username='$username' && test='$test'"; $result2=mysql_query($qrytable1) or die('Error:<br />' . $qry . '<br />' . mysql_error()); if(mysql_num_rows($result2) > 0) { $row = mysql_fetch_row($result2); mysql_query("UPDATE user_list SET Public=('$_GET[public]') WHERE username='$username' AND test='$test'"); echo "update!"; } else { echo "already updated!"; } } else { echo "user not found"; } } } ?> This is the function I use to check the value in the database: Code: [Select] if (mysql_affected_rows($result2) > 0) { mysql_query("UPDATE user_list SET Public=('$_GET[public]') WHERE username='$username' AND test='$test'"); echo "you have update it!"; } else if (mysql_affected_rows($result2) < 0) { echo "it is not on the database"; } else { echo "you have already updated!"; } When i input the different value in a url bar while the records are not the same as the value in the url and in the database, i can't get passed and I am keep getting "you have already updated!!" when the value in a database are different than I have input in a url. Do you know how i can get pass it when I have input the different value in the url while it is not the same in the database? Any advice would be much appreicated. Thanks, Mark Hey guys, I'm working a project that requires sessions be stored within the database, as the project I'm working on is on a shared host. But I'm having a problem with getting the data of a session in the database, the other fields like session_id, session_updated, session_created are working fine. I think I've got a bug in my code, but I just can't detect it (frustrating). Database connection class db extends mysqli { private $host; private $user; private $pass; private $db; function __construct( $host='localhost', $user='user', $pass='pass', $db='website' ) { $this -> host = $host; $this -> user = $user; $this -> pass = $pass; $this -> db = $db; parent::connect( $host, $user, $pass, $db ); if( mysqli_connect_error( ) ) { die( 'Connection error ('.mysqli_connect_errno( ).'): '.mysqli_connect_error( ) ); } } function __destruct( ) { $this -> close( ); } } Session handler class sessionHandler { private $database; private $dirName; private $sessTable; private $fieldArray; function sessionHandler() { // save directory name of current script $this -> database = new db; $this -> dirName = dirname(__file__); $this -> sessTable = 'sessions'; } function open( $save_path, $session_name ) { return TRUE; } function close() { //close the session. if ( !empty( $this -> fieldarray ) ) { // perform garbage collection $result = $this->gc( ini_get ( 'session.gc_maxlifetime' ) ); return $result; } return TRUE; } function read( $session_id ) { $sql = " SELECT * FROM sessions WHERE session_id=( '$session_id' ) LIMIT 1 "; $result = $this -> database -> query( $sql ); if( $result -> num_rows > 0 ) { $data = $result -> fetch_array( MYSQLI_ASSOC ); $this -> fieldArray = $data; $result -> close(); return $data; } return ""; } function write( $session_id, $session_data ) { //write session data to the database. if ( !empty( $this -> fieldArray ) ) { if ( $this -> fieldArray['session_id'] != $session_id ) { // user is starting a new session with previous data $this -> fieldArray = array(); } } $this -> fieldArray['session_id'] = $session_id; $this -> fieldArray['session_data'] = $session_data; $this -> fieldArray['session_updated'] = time(); $this -> fieldArray['session_created'] = time(); $session_id = $this -> database -> escape_string( $session_id ); $session_data = $this -> database -> escape_string( $session_data ); $session_updated = time(); $session_created = time(); $sql = " INSERT INTO sessions ( session_id, session_data, session_updated, session_created ) VALUES ( '$session_id', '$session_data', '$session_updated', '$session_created' ) "; if( $this -> database -> query( $sql ) !== TRUE ) { return FALSE; } return TRUE; } function destroy( $session_id ) { $sql = " DELETE FROM sessions WHERE session_id=('$session_id') "; if( $this -> database -> query( $sql ) !== TRUE ) { return FALSE; } return TRUE; } function gc( $max_lifetime ) { return TRUE; } function __destruct() { //ensure session data is written out before classes are destroyed //(see http://bugs.php.net/bug.php?id=33772 for details) @session_write_close(); } } The call $session_class = new sessionHandler; session_set_save_handler( array( &$session_class, 'open' ), array( &$session_class, 'close' ), array( &$session_class, 'read' ), array( &$session_class, 'write' ), array( &$session_class, 'destroy' ), array( &$session_class, 'gc' ) ); if( !session_start() ) { exit(); } Any help at all would be appreciated. Kind Regards Mike I know this is a very simple and probably stupid question - but what is a patch? i've tried searching online for an explanation but I just find articles on the 'best practice' and it doesn't break it down into what it actually is!
I've just been looking into new hosting and they offer a managed service, which includes database patching.
Could someone please enlighten me?
Edited by paddyfields, 10 June 2014 - 04:49 AM. I'm having problems updating my database, I have 4 fields i want to change. I checked all the { on the page, that's not the problem, I tried to echo information from the database and it displayed my information so that's not the problem, i tried yelling at my computer, that didn't work, i tried to input data into the database with the insert function it worked but is not practical in my situation. I'm probably going to face palm when i find out whats wrong, help please btw, the $_SESSION['usr'] was set in another page and works. Code: [Select] <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Edit Info</title> <link rel="stylesheet" type="text/css" href="demo.css" media="screen" /> </head> <body> <div id="main"> <div class="container"> <font size="5" face="sans-serif">Change Settings <?php echo "{$_SESSION['usr']}"; ?></font> <form action="" method="POST"> <table cellpadding="3" cellspacinf="4" border="0"> <tr> <td>Name</td> <td><input type="text" name="name" /></td> </tr> <tr> <td>Age</td> <td><input type="text" name="age" /></td> </tr> <tr> <td>Gender</td> <td><input type="text" name="mf" /></td> </tr> <tr> <td>Location</td> <td><input type="text" name="loc" /></td> </tr> <tr> <td><input type="submit" name="submit" value="submit" /></td> </tr> </table> </form> <?php if ($_POST['submit']){ define('INCLUDE_CHECK',true); require 'connect.php'; $usr = $_SESSION['usr']; $sql = mysql_query("UPDATE members SET name='{$_POST['name']}', age='{$_POST['age']}, mf='{$_POST['mf']}', loc='{$_POST['loc']}' WHERE usr='{$_SESSION['usr']}'"); if($sql){ echo 'Changes Saved!'; }else{ echo 'Error'; } } ?> </div> </div> </body> </html> Okay, I have been following this tutorial: http://www.freewebmasterhelp.com/tutorials/phpmysql/1 to achieve exactly what I wanted to get done. I also followed the way to have it formatted in tables and added extra columns that I needed, included an "Options" column which houses three links, including "edit" and "delete" Now, I have everything working fine but I am stumped on how to get the "edit" and "delete" links to work for each individual entry that is listed. I have to have these features so the entries can be edited and deleted without having to physically go into the MySQL database to do it. The tutorial explains how to do it in Step 6, but I am confused. I'm not quite sure where to place the code for the links, which are generated automatically every time a new entry is inputted into the database. Anybody available to help me out? Thanks! Hello playERZ' So, I have a dinky contact form that validates and uses: Code: [Select] <form name="infoget" action="<?=$_SERVER['PHP_SELF']?>" method="post"> to validate the form via an external validate.php, then generate the email. Finally: // Send the mail using PHPs mail() function mail($to, $subject, $body); header("Location:customize_search.php"); So, this takes the user to a more advanced form after they 'send' the first form. 1 - Is it possible to have the second form autofill with the POSTed data and NOT use MySQL or database whatever? 2 - If so, how?? There is a "PHP ajax cascading dropdown using MySql" at codestips.com/php-ajax-cascading-dropdown-using-mysql/ I want to use this technique but with a XML or array file instead of mysql database, but my knowledge about mysql is very low. How I can modify this code to catch the categories and products from an array, instead of mysql database? Code: [Select] $connect=mysql_connect($server, $db_user, $db_pass) or die ("Mysql connecting error"); echo '<table align="center"><tr><td><center><form method="post" action="">Category:<select name="category" onChange="CategoryGrab('."'".'ajaxcalling.php?idCat='."'".'+this.value);">'; $result = mysql_db_query($database, "SELECT * FROM Categories"); $nr=0; while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $nr++; echo "<option value=".'"'.$row['ID'].'" >'.$row['Name']."</option>"; } echo '</select>'."\n"; echo '<div id="details">Details:<select name="details" width="100" >'; $result = mysql_db_query($database, "SELECT * FROM CategoriesDetails WHERE CategoryID=1"); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "<option value=".$row['ID'].">".$row['Name']."</option>"; } echo '</select></div>'; echo '</form></td></tr></table>'; mysql_close($connect); ajaxcalling.php is Code: [Select] include("config.php"); $ID=$_REQUEST['idCat']; $connect=mysql_connect($server, $db_user, $db_pass); echo 'Details:<select name="details" width="100">'; $result = mysql_db_query($database, "SELECT * FROM CategoriesDetails WHERE CategoryID=".$ID); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "<option value=".$row['ID'].">".$row['Name']."</option>"; } echo '</select>'; mysql_close($connect); Hello guys. Trying to connect php with mysql database and then display results on the screen. This is my code: Code: [Select] <?php $dbhost = "localhost"; $dbuser = "username1"; $dbpass = "password1"; $db = "username1_myDB"; $connection = mysql_connect($dbhost, $dbuser, $dbpass) or die ("Could not connect"); mysql_select_db($connection, $db); $show = "SELECT Name, Description FROM people"; $result = mysql_query($show); while($show = mysql_fetch_array($result)){ $field01 = $show[Name]; $field02 = $show[Description]; echo "id: $field01<br>"; echo "description: $field02<p>"; } ?> However im getting this: Warning: mysql_select_db() expects parameter 1 to be string, resource given in /home/pain33/public_html/index.php on line 20 Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/pain33/public_html/index.php on line 26 Any ideas how to fix this? Thank you. Hi there, I have been creating a website which shows products of the companys (www.theadventurestartshere.org) and I have been trying to make some filters for the products using URL Parameters and recordsheet filters... Can someone advise me on the easiest way to do this? As I have created a method to do it with, (check website) but it has to be entered manually and I was hoping there is an easier way? Please Note I like to use drop down boxes for the filters but if there is a way to do the checkbox style you see on say Amazon then that would be brilliant... I use Dreamweaver CS5, and the newest versions of PHP and MySql Many Thanks, Paul Hello all, first post here so i hope i'm doing this right and am putting this into the right place. Im in the process of integrating a blog into my website, mostly it's set up however i'm currently working on the code to update the posts (theres only 2 parts a title and a comments[which is in actual fact the post content itself]). The code succsefully completes without any errors but for some reason it does not actually update the mysql database.. the code i'm using is as follows: Code: [Select] <?php require_once('header.php'); include "../blog/blogconfig.php"; if(isset($_POST['submit'])){ $update="UPDATE eq_blogarticle SET title='".$_POST['title']."',comments='".$_POST['comment']."' WHERE artid='$aid'"; if(!mysql_query($update)){ echo mysql_error(); }else{ header("location:blog.php?action=listmsgs"); exit; } } ?> <?php // get value of aid that sent from address bar by blog.php?action=listmsgs $aid=$_GET['aid']; // Retrieve data from database $sql="SELECT * FROM eq_blogarticle WHERE artid='$aid'"; $result=mysql_query($sql); $row=mysql_fetch_array($result); ?> <form name="form2" method="post" action="update.php"> <script type="text/javascript">var SITE_URL="<?php echo SITE_URL;?>";</script> <script type="text/javascript" src="<?php echo SITE_URL;?>/includes/js/nicEdit.js"></script> <script type="text/javascript"> //<![CDATA[ bkLib.onDomLoaded(function() { nicEditors.allTextAreas() }); //]]> </script> <body> <table width="100%" border="0" cellspacing="1"> <tr> <td colspan="2" class="temptitle">Equidisc Blog</td> </tr> <tr> <td width="74%" valign="top"> <table> Edit Blog Post <br> <br> Title: <br> <input name="title" type="text" class="input" id="title" value="<? echo $row['title']; ?>"> <br> <br> <span class="style1 style2 style3">Blog Post:</span> <br> <br> <textarea name="comments" cols="55" rows="12" class="input" id="comments"><? echo stripslashes($row['comments']); ?></textarea> <br> <br> <input name="aid" type="hidden" id="aid" value="<? echo $row['artid']; ?>"> <input type="submit" name="submit" value="Submit"> </form> </table> </td> <td width="26%" valign="top"><table width="100%" border="0" cellspacing="1"> <tr> <td colspan="2"><img src="../blog/images/fb.gif" width="16" height="16" /> <strong>Blog Menu</strong></td> </tr> <tr> <td><a href="blog.php">Home</a></td> </tr> <tr> <td><a href="blog.php?action=newblogpost">New Post </a></td> </tr> <tr> <td><a href="blog.php?action=listmsgs">Manage Posts </a></td> </tr> </table></td> </tr> </table> </body> <?php require_once('footer.php'); ?> Explanation: header/footer.php obvious ../blog/blogconfig.php holds my mysql connection settings and connects to the sql, this is the same config as is used for creating the new posts which i have no issues with so i dont think the issue lays there. If i run the query on phpmyadmin with dummy data it works fine and updates the entry.. Any help would be very much appreciated as i'm at the end of my tether with this!. Thanks in advance. Jo Ok, I got someone to help me fix this but he had no idea what the error was... I have 2 tables, one called points and the other called members. In members i have got: id name In points i have got: id memberid promo I have the following code: Code: [Select] <?php $con = mysql_connect("localhost","slay2day_User","slay2day"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("slay2day_database",$con); $sqlquery="SELECT Sum(points.promo) AS score, members.name, members.id = points.memberid Order By members.name ASC"; $result=mysql_query($sqlquery,$con); while ($row = mysql_fetch_array($result)) { //get data $id = $row['id']; $name = $row['name']; $score = $row['score']; echo "<b>Name:</b> $name<br />"; echo "<b>Points: </b> $score<br />" ; echo "<b>Rank: </b>"; if ($name == 'Kcroto1'): echo 'The Awesome Leader'; else: if ($points >= '50'): echo 'General'; elseif ($points >= '20'): echo 'Captain!'; elseif ($points >= '10'): echo 'lieutenant'; elseif ($points >= '5'): echo 'Sergeant'; elseif ($points >= '2'): echo 'Corporal'; else: echo 'Recruit'; endif; endif; echo '<br /><br />'; } ?> I am getting the following error when i do the query in mysql: Code: [Select] #1109 - Unknown table 'points' in field list And when i open the webpage i get the following error: Code: [Select] Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/slay2day/public_html/points/members.php on line 18 Please Help me? I'm trying to use php code that is stored in the sql database, but It doesn't seem to be executing the code. when I see the page source, its there but the server is not executing the command how do I accomplish this. Here is a simple code snippet to show what I am trying to do. $result = mysql_query("select * from data"); $row = mysql_fetch_array($result); echo $row['code']; In the code field in data table this is whats there. <?php echo "testing."; ?> Can you upload videos to a mysql database? If so how would you go about doing it? |