[HELP]Adding Code From Website To Database

This is guide mostly for website tools and code, for example CMS or registration scripts.
There can also be tools.

Moderators: osRose dev team, ospRose dev team, osiRose dev team, Moderators

Re: [HELP]Adding Code From Website To Database

Postby Circa on Mon Dec 31, 2012 8:52 am

-out of no where Calder appears!-
Circa
Clown
Clown
 
Posts: 404
Joined: Sun Aug 23, 2009 5:52 am
Location: CA

Re: [HELP]Adding Code From Website To Database

Postby hoegarden31 on Mon Dec 31, 2012 11:38 am

PDO has more advantages like cross database, meaning it's the same interface for different relational databases. Prepared statements are faster than normal queries because they're optimized for repeat queries with different parameters, a query run once will not see the benefit.
Helps protect against SQL injections, without the need to escape your stuff with mysql_real_escape_string().
And for last, PDO has a cleaner IMO.

Maybe our opinions differ, but for me PDO is an improvement to normal mysql, and there should be a reason why zend framework uses PDO (i use it almost every day)
I'm the one and only. In heaven and on earth.
Image
hoegarden31
Rackie
Rackie
 
Posts: 150
Joined: Sun Nov 13, 2011 7:13 pm

Re: [HELP]Adding Code From Website To Database

Postby observe on Tue Jan 22, 2013 4:52 pm

rave wrote:Hi,

I Hope Someone Can Help Me Please?
I Would Like To Know If How Can I Code This Option

Website>Page That Put Values Like

Username:
Code:
Check box ( are you sure with your code? )
Submit

After Submit The Code I Put Will Be On My Navicat

Website>Page....>Code Added To Database

Anyone Can Help? I Tried The add_dpts.php But It Doesnt Work


  1. <form action="" method="post">
  2.     <label>Username:</label>
  3.     <input type="text" name="username">
  4.     <input type="submit" name="submit" value="submit">
  5. </form>


Than the PHP part comes
  1. <?PHP
  2. if(isset($_POST['submit'])){
  3.     $username = $_POST['username'];
  4.  
  5.     if(!$username){
  6.         die('Username cannot be empty');
  7.     } else {
  8.         $host = 'localhost'; // Database host (Default: localhost)
  9.         $user = 'root';        // Database username (Default: root)
  10.         $pass = '';              // Database Password (Own setup)
  11.         $db    = '';              // Database table
  12.  
  13.         mysql_connect($host,$user,$pass);
  14.         mysql_select_db($db);
  15.  
  16.         $sql = "SELECT * FROM accounts WHERE username='".$username."'";
  17.         $res = mysql_query($sql) or die(mysql_error());
  18.  
  19.         if(mysql_num_rows($res) > 0){
  20.             die('Username already in use!');
  21.         } else {
  22.             $sql = "INSERT INTO accounts (`username`) VALUEs ('".$username."')";
  23.             $res = mysql_query($sql) or die(mysql_error());
  24.  
  25.             if($res){
  26.                 die('Username successfully added to the database');
  27.             }
  28.         }
  29. }
  30. ?>


Keep in mind this is not a safe code this is just to show you how the information is safed into the database
observe
osRose dev
osRose dev
 
Posts: 194
Joined: Thu Sep 17, 2009 10:28 am
Location: The Netherlands

Re: [HELP]Adding Code From Website To Database

Postby rave on Sun Feb 03, 2013 1:35 am

observe wrote:
rave wrote:Hi,

I Hope Someone Can Help Me Please?
I Would Like To Know If How Can I Code This Option

Website>Page That Put Values Like

Username:
Code:
Check box ( are you sure with your code? )
Submit

After Submit The Code I Put Will Be On My Navicat

Website>Page....>Code Added To Database

Anyone Can Help? I Tried The add_dpts.php But It Doesnt Work


  1. <form action="" method="post">
  2.     <label>Username:</label>
  3.     <input type="text" name="username">
  4.     <input type="submit" name="submit" value="submit">
  5. </form>


Than the PHP part comes
  1. <?PHP
  2. if(isset($_POST['submit'])){
  3.     $username = $_POST['username'];
  4.  
  5.     if(!$username){
  6.         die('Username cannot be empty');
  7.     } else {
  8.         $host = 'localhost'; // Database host (Default: localhost)
  9.         $user = 'root';        // Database username (Default: root)
  10.         $pass = '';              // Database Password (Own setup)
  11.         $db    = '';              // Database table
  12.  
  13.         mysql_connect($host,$user,$pass);
  14.         mysql_select_db($db);
  15.  
  16.         $sql = "SELECT * FROM accounts WHERE username='".$username."'";
  17.         $res = mysql_query($sql) or die(mysql_error());
  18.  
  19.         if(mysql_num_rows($res) > 0){
  20.             die('Username already in use!');
  21.         } else {
  22.             $sql = "INSERT INTO accounts (`username`) VALUEs ('".$username."')";
  23.             $res = mysql_query($sql) or die(mysql_error());
  24.  
  25.             if($res){
  26.                 die('Username successfully added to the database');
  27.             }
  28.         }
  29. }
  30. ?>


Keep in mind this is not a safe code this is just to show you how the information is safed into the database



sorry late reply i already manage to this coding
thanks sir observe and others : )
rave
Clown
Clown
 
Posts: 459
Joined: Thu Dec 10, 2009 1:07 pm

Previous

Return to PHP / Web Guides, Scripts and tools.

Who is online

Users browsing this forum: No registered users and 7 guests