Follow us on Twitter!
Hacking isn't just Computers & Exploits. It's a Philosophy. - Mr_Cheese
Monday, April 21, 2014
Navigation
Home
HellBoundHackers Main:
HellBoundHackers Find:
HellBoundHackers Information:
Learn
Communicate
Submit
Shop
Challenges
HellBoundHackers Exploit:
HellBoundHackers Programming:
HellBoundHackers Think:
HellBoundHackers Track:
HellBoundHackers Patch:
HellBoundHackers Other:
HellBoundHackers Need Help?
Other
Members Online
Total Online: 27
Guests Online: 24
Members Online: 3

Registered Members: 82858
Newest Member: alexxkim
Latest Articles
View Thread

HellBound Hackers | Computer General | Programming

Author

PHP/MySQL install script


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 01-10-09 10:12
Hi everyone,

I just have a couple of questions on making an install script which basically creates a database for a website.

Basically I want to make a file (install.php) which will create the database and return if everything is okay.

I've coded what I thought it would be like. But apparently its not right.

This is what I've got so far (ps, Dont comment on my sloppy coding.)

Code

<?php

echo "
<html>
<body>
<form action='install.php' method='post' >
<center>
<h1>Would you like to install the current website?</h1>
<br />
<br />
<table>
<tr>
<td>
<input type='submit' name='yes' value='Yes!' />
</td>
<td>
<input type='submit' name='no' value='No' />
</td>
</tr>
</table>
</form>
</body>
</html>
";


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

   echo "<script type='text/javascript'> location.href='index.php'</script>";

}elseif(isset($_POST['yes'])){


$user = 'upload_user';
$pass = '';

$dbConnect = mysql_connect('localhost',$user,$pass);

if($dbConnect){

  echo "sorry could not connect to local host using :" . $user . " as the username" or die(mysql_error());

}else{


   $sqlQuery = "
   
   CREATE DATABASE `upload_users`;

   CREATE TABLE IF NOT EXISTS `comments` (
     `page` text NOT NULL,
     `comment` text NOT NULL,
     `new` text NOT NULL,
     `user` text NOT NULL,
     `ID` int(11) NOT NULL auto_increment,
     `to` text NOT NULL,
     PRIMARY KEY  (`ID`)
   ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
   ";

     if(mysql_query($sqlQuery)){

        echo "successful query - Creating Database `upload_users` and table `comments` <br />" or die(mysql_error());

     }


   $sqlQuery = "INSERT INTO `comments` (`page`, `comment`, `new`, `user`, `ID`, `to`) VALUES
('get=1&user=admin', ':)', '1', 'admin', 1, 'admin')";


   if(mysql_query($sqlQuery)){


      echo "successful query - Inserting data into `comments` table <br />" or die(mysql_error());

   }

   $sqlQuery = "CREATE TABLE IF NOT EXISTS `friends` (
  `friend` text NOT NULL,
  `friend2` text NOT NULL,
  `a1` text NOT NULL,
  `a2` text NOT NULL,
  `ID` int(11) NOT NULL auto_increment,
  PRIMARY KEY  (`ID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1" ;


   if(mysql_query($sqlQuery)){

      echo "successful query - Creating table `friends` <br />" or die(mysql_error());

   }

   
   $sqlQuery = "CREATE TABLE IF NOT EXISTS `images` (
  `path` text NOT NULL,
  `album` text NOT NULL,
  `owner` text NOT NULL,
  `ID` int(11) NOT NULL auto_increment,
  `des` text NOT NULL,
  PRIMARY KEY  (`ID`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;";


   if(mysql_query($sqlQuery)){


      echo "successful query - Creating table `images` <br />" or die(mysql_error());


   }


   $sqlQuery = "INSERT INTO `images` (`path`, `album`, `owner`, `ID`, `des`) VALUES
('quantum-solace-olga.jpg', '1', 'admin', 1, '');";

   if(mysql_query($sqlQuery)){


      echo "successful query - Inserting data into `images` table <br />" or die(mysql_error());

   }


   $sqlQuery = "CREATE TABLE IF NOT EXISTS `PM` (
  `to` text NOT NULL,
  `from` text NOT NULL,
  `date` text NOT NULL,
  `ID` int(11) NOT NULL auto_increment,
  `subject` text NOT NULL,
  `new` text NOT NULL,
  `mess` text NOT NULL,
  PRIMARY KEY  (`ID`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;";


   if(mysql_query($sqlQuery)){

      echo "successful query - created table `PM` <br />" or die(mysql_error());

   }


   $sqlQuery = "INSERT INTO `PM` (`to`, `from`, `date`, `ID`, `subject`, `new`, `mess`) VALUES
('admin', 'admin new page!', 'Thu, 16 Jul 09 12:00:47 +0100', 1, 'Test', '1', 'lol')";


   if(mysql_query($sqlQuery)){

      echo "Successful query - Inserted data into table `PM` <br />" or die(mysql_error());

   }


   $sqlQuery = "CREATE TABLE IF NOT EXISTS `profile` (
  `user` text NOT NULL,
  `main` text NOT NULL,
  `links` text NOT NULL,
  `h` text NOT NULL,
  `ID` int(11) NOT NULL auto_increment,
  `avatar` text NOT NULL,
  PRIMARY KEY  (`ID`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;";


   if(mysql_query($sqlQuery)){

      echo "Successful query - Created table `profile`" or die(mysql_error());

   }


   $sqlQuery = "INSERT INTO `profile` (`user`, `main`, `links`, `h`, `ID`, `avatar`) VALUES
('admin', 'First Account!', 'allow', 'admin new page!', 1, 'http://uploadimage.co.uk/upload/uploads/admin/quantum-solace-olga.jpg');";


   if(mysql_query($sqlQuery)){

      echo "Successful query - Inserted data into `profile` table" or die(mysql_error());

   }


   $sqlQuery = "CREATE TABLE IF NOT EXISTS `users` (
  `uname` text NOT NULL,
  `upassword` text NOT NULL,
  `avatar` text NOT NULL,
  `email` text NOT NULL,
  `ID` int(11) NOT NULL auto_increment,
  PRIMARY KEY  (`ID`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;";


   if(mysql_query($sqlQuery)){

      echo "successful query - Created table `users`" or die(mysql_error());

   }


   $sqlQuery = "INSERT INTO `users` (`uname`, `upassword`, `avatar`, `email`, `ID`) VALUES
('admin', '32a8216baa0bbcfbe47d35cbeb734643', '', 'youremail', 1);";


   if(mysql_query($sqlQuery)){

      echo "successful query - Inserted data into `users` table" or die(mysql_error());

   }
}
}

?>






Author

RE: PHP/MySQL install script

ynori7
Member



Posts: 1486
Location: #valhalla
Joined: 08.10.07
Rank:
God
Posted on 01-10-09 14:00
DarkMantis wrote:
I've coded what I thought it would be like. But apparently its not right.

That's really long, man. Don't expect people to trace all through that. Where does it die? If you don't know, start putting in echos in various places so you can see where it dies.


halls-of-valhalla.org/images/affiliateLogo.png voodoorage.halls-of-valhalla.org/images/smallLogo.png
i537.photobucket.com/albums/ff338/ynori77/archenemysig1.jpg
ynori7 http://halls-of-valhalla.org
Author

RE: PHP/MySQL install script


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 01-10-09 14:27
Yeah no worries, I just wanted to see if anyone could instantly see if I'm being stupid on this one, but it doesn't matter any more, I've sorted it out now, Thanks again.


Author

RE: PHP/MySQL install script


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 01-10-09 14:46
Next time you post code, please also post error messages you got, and what -you- think the problem could and/or couldn't be.

Also, if you fixed something, edit your first post to say so and also HOW you fixed it.

Good job on fixing it, btw.