Pennsylvania Firearm Owners Association
Page 1 of 2 12 LastLast
Results 1 to 10 of 19
  1. #1
    Join Date
    Mar 2008
    Location
    Lansdowne, Pennsylvania
    (Delaware County)
    Age
    37
    Posts
    5,994
    Rep Power
    3189408

    Default Looking for php help

    I'm trying to find someone who could lend a few minutes to help me connect my DB to a php form so I can login and enter data into my DB my buddy wrote for me...

    problem is, I don't know any php and he had to run.

    If you don't mind lending a hand, PM me...

    Thanks,
    Andrew
    Peace, Prosperity, and Liberty

  2. #2
    Join Date
    May 2008
    Location
    Too close to the "Dirty"., Pennsylvania
    Posts
    333
    Rep Power
    110

    Default Re: Looking for php help

    Maybe post the error you are getting, will spark memories for some.

    tom
    Everyday, Love your Wife. She might love you back twice that day. :D

  3. #3
    Join Date
    Mar 2008
    Location
    Lansdowne, Pennsylvania
    (Delaware County)
    Age
    37
    Posts
    5,994
    Rep Power
    3189408

    Default Re: Looking for php help

    Quote Originally Posted by Mr_Tom View Post
    Maybe post the error you are getting, will spark memories for some.

    tom
    I don't know how to code it...idk any php.
    Peace, Prosperity, and Liberty

  4. #4
    Join Date
    Jan 2008
    Location
    noneville, Massachusetts
    Posts
    3,368
    Rep Power
    8948

    Default Re: Looking for php help

    email me what he gave you and I can show you what to adjust: josh dot love at verizon dot net.

    I haven't done php in some time now but iirc, it's like this.

    the way you connect to a mysql db though is
    mysql_connect()

    what most folks will do though is in the code they'll create variables for the db host, db username, db password and database name.
    so something like this (note I did not put any error reporting in it)

    Code:
    <?php
    $dbhost = '';
    $dbuser = '';
    $dbpassword = '';
    $dbname = '';
    
    mysql_connect($dbhost, $dbuser, $dbpassword);
    mysql_select_db($dbname);
    
    ...whatever code....
    
    mysql_close($dbhost);
    ?>
    Usually a good programmer will have a "config.php" file that is accessed by all the other scripts using an include. So if you can just fill in the blanks of the dbhost (ip or url), user/pass (self explanatory) and dbname (what you named your database in mysql) you should be good to go. If there is only one php script he gave you the stuff you need to edit is between the '' marks towards the top of the script.
    Last edited by Kaos; December 3rd, 2008 at 06:18 AM.

  5. #5
    Join Date
    Dec 2007
    Location
    Behind You, Watching, Always Watching
    Age
    66
    Posts
    5,410
    Rep Power
    0

    Default Re: Looking for php help

    Assuming you are using a MySQL database:


    PHP Code:
    $db_link mysql_connect($db_host$db_username$db_password);

    mysql_select_db($db_name$db_link);

    To select data from the db:

    $row mysql_query("SELECT something, something_else FROM table"$db_link);

    then get your data as such:

    $something $row['something'];
    $something_else $row['something_else'];

    To insert into a database from a form (provided the form is using the post method):

    mysql_query("INSERT INTO table_name VALUES({$_POST['field_one']}{$_POST[field_two']})", $db_link); 
    Of course you didn't mention if you new SQL either

  6. #6
    Join Date
    Dec 2007
    Location
    Behind You, Watching, Always Watching
    Age
    66
    Posts
    5,410
    Rep Power
    0

    Default Re: Looking for php help

    Quote Originally Posted by Kaos View Post
    Usually a good programmer will have a "config.php" file that is accessed by all the other scripts using an include.
    NO, what a GOOD programmer does is have one object that handles all the db work and anywhere it's needed they include that object.

    PHP Code:
        class database_functions    {

            var 
    $dbLink null;
            var 
    $dbResult null;

            
    /* connects to db */
            
    function getConnection($host$user$pass$dbName)     {

                
    $this->dbLink mysql_connect($host$user$pass) OR die('Cant connect to db');
                
    mysql_select_db($dbName$this->dbLink) OR die('cant select database');
                }

            
    /* for use in non looping situtations */
            
    function getQueryResults($query$fetchType)    {
                
    $dbResult mysql_query($query$this->dbLink);
                
    $row mysql_fetch_array($dbResultMYSQL_BOTH);
                return 
    $row;
                }

            function 
    getRowCount($query)     {
                
    $dbResult mysql_query($query$this->dbLink);
                return 
    mysql_num_rows($dbResult);
                }
            
            function 
    getResults($query)     {
                
    $this->dbResult mysql_query($query$this->dbLink);
                }

            function 
    getMultiRows($fetchType)     {
                return 
    mysql_fetch_array($this->dbResultMYSQL_BOTH);
                }

            function 
    updateDatabase($query)     {
                return 
    mysql_query($query$this->dbLink);
                }

            function 
    closeConnection()    {
                
    mysql_close($this->dbLink);
                }

            } 

  7. #7
    Join Date
    Mar 2008
    Location
    Lansdowne, Pennsylvania
    (Delaware County)
    Age
    37
    Posts
    5,994
    Rep Power
    3189408

    Default Re: Looking for php help

    Quote Originally Posted by dc dalton View Post
    Assuming you are using a MySQL database:


    PHP Code:
    $db_link mysql_connect($db_host$db_username$db_password);

    mysql_select_db($db_name$db_link);

    To select data from the db:

    $row mysql_query("SELECT something, something_else FROM table"$db_link);

    then get your data as such:

    $something $row['something'];
    $something_else $row['something_else'];

    To insert into a database from a form (provided the form is using the post method):

    mysql_query("INSERT INTO table_name VALUES({$_POST['field_one']}{$_POST[field_two']})", $db_link); 
    Of course you didn't mention if you new SQL either

    I am using mysql and I don't know it, but I know how to get the db name, username/password, etc...I'll try that out.

    I entered in the info for my DB, and saved it as form.php and uploaded it to my server.

    I'm getting this error on line 6:

    Parse error: syntax error, unexpected T_STRING in /homepages/40/d237348395/htdocs/uglycars/reloading/form.php on line 6

    I'm also not sure what to enter here:
    $db_link
    the url to the form?

    Thanks DC and Kaos for lending a hand...
    Last edited by andrewjs18; December 3rd, 2008 at 01:23 PM.
    Peace, Prosperity, and Liberty

  8. #8
    Join Date
    Dec 2007
    Location
    Behind You, Watching, Always Watching
    Age
    66
    Posts
    5,410
    Rep Power
    0

    Default Re: Looking for php help

    Quote Originally Posted by andrewjs18 View Post
    I am using mysql and I don't know it, but I know how to get the db name, username/password, etc...I'll try that out.
    well inserting or pulling data from a database requires knowledge of the SQL language so you may be in for a rough time.

  9. #9
    Join Date
    Jan 2008
    Location
    noneville, Massachusetts
    Posts
    3,368
    Rep Power
    8948

    Default Re: Looking for php help

    Quote Originally Posted by dc dalton View Post
    NO, what a GOOD programmer does is have one object that handles all the db work and anywhere it's needed they include that object.

    PHP Code:
        class database_functions    {

            var 
    $dbLink null;
            var 
    $dbResult null;

            
    /* connects to db */
            
    function getConnection($host$user$pass$dbName)     {

                
    $this->dbLink mysql_connect($host$user$pass) OR die('Cant connect to db');
                
    mysql_select_db($dbName$this->dbLink) OR die('cant select database');
                }

            
    /* for use in non looping situtations */
            
    function getQueryResults($query$fetchType)    {
                
    $dbResult mysql_query($query$this->dbLink);
                
    $row mysql_fetch_array($dbResultMYSQL_BOTH);
                return 
    $row;
                }

            function 
    getRowCount($query)     {
                
    $dbResult mysql_query($query$this->dbLink);
                return 
    mysql_num_rows($dbResult);
                }
            
            function 
    getResults($query)     {
                
    $this->dbResult mysql_query($query$this->dbLink);
                }

            function 
    getMultiRows($fetchType)     {
                return 
    mysql_fetch_array($this->dbResultMYSQL_BOTH);
                }

            function 
    updateDatabase($query)     {
                return 
    mysql_query($query$this->dbLink);
                }

            function 
    closeConnection()    {
                
    mysql_close($this->dbLink);
                }

            } 
    I've just found it easier to keep the config in it's own separate file, but I come from the mindset of php apps in the open source realm, where you need to simplify it for the user as much as possible.

    If it's only you under the hood and only you managing and configuring things that having your own classes and functions for this stuff makes perfect sense.

  10. #10
    Join Date
    Mar 2008
    Location
    Lansdowne, Pennsylvania
    (Delaware County)
    Age
    37
    Posts
    5,994
    Rep Power
    3189408

    Default Re: Looking for php help

    Quote Originally Posted by dc dalton View Post
    well inserting or pulling data from a database requires knowledge of the SQL language so you may be in for a rough time.
    The DB is already written by a friend of mine:
    Code:
    -- Database: `db267125153`
    -- 
    CREATE DATABASE `db267125153` DEFAULT CHARACTER SET latin1 COLLATE latin1_german2_ci;
    USE db267125153;
    
    -- --------------------------------------------------------
    
    -- 
    -- Table structure for table `Guns`
    -- 
    
    CREATE TABLE `Guns` (
      `ID` int(5) NOT NULL auto_increment,
      `Ammo_Caliber` varchar(10) collate latin1_german2_ci NOT NULL,
      `Bullet` varchar(20) collate latin1_german2_ci NOT NULL,
      `Powder` varchar(20) collate latin1_german2_ci NOT NULL,
      `Primer` varchar(20) collate latin1_german2_ci NOT NULL,
      `OAL` varchar(20) collate latin1_german2_ci NOT NULL,
      `Data_Distance` varchar(20) collate latin1_german2_ci NOT NULL,
      `Grouping` varchar(20) collate latin1_german2_ci NOT NULL,
      `Bench` varchar(20) collate latin1_german2_ci NOT NULL,
      PRIMARY KEY  (`ID`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_german2_ci AUTO_INCREMENT=1 ;
    
    -- 
    -- Dumping data for table `Guns`
    -- 
    
    
    -- --------------------------------------------------------
    
    -- 
    -- Table structure for table `Users`
    -- 
    
    CREATE TABLE `Users` (
      `ID` int(3) NOT NULL auto_increment,
      `User_Name` varchar(20) collate latin1_german2_ci NOT NULL,
      `Password` varchar(20) collate latin1_german2_ci NOT NULL,
      PRIMARY KEY  (`ID`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_german2_ci AUTO_INCREMENT=1 ;
    
    -- 
    -- Dumping data for table `Users`
    --
    He didn't have time to do the php form last night because his wife was working and he had to watch his son.

    That's all he wrote..no php or anything. I don't know any php to write the rest of the code, this is why I asked if anyone could help me with the php.
    Last edited by andrewjs18; December 3rd, 2008 at 02:03 PM.
    Peace, Prosperity, and Liberty

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •