Results 1 to 10 of 19
Thread: Looking for php help
-
December 3rd, 2008, 12:29 AM #1
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,
AndrewPeace, Prosperity, and Liberty
-
December 3rd, 2008, 01:18 AM #2
Re: Looking for php help
Maybe post the error you are getting, will spark memories for some.
tomEveryday, Love your Wife. She might love you back twice that day. :D
-
December 3rd, 2008, 01:31 AM #3
-
December 3rd, 2008, 05:56 AM #4
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); ?>
Last edited by Kaos; December 3rd, 2008 at 06:18 AM.
-
December 3rd, 2008, 09:52 AM #5Banned
- Join Date
- Dec 2007
- Location
-
Behind You, Watching, Always Watching
- Age
- 66
- Posts
- 5,410
- Rep Power
- 0
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);
-
December 3rd, 2008, 09:55 AM #6Banned
- Join Date
- Dec 2007
- Location
-
Behind You, Watching, Always Watching
- Age
- 66
- Posts
- 5,410
- Rep Power
- 0
Re: Looking for php help
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($dbResult, MYSQL_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->dbResult, MYSQL_BOTH);
}
function updateDatabase($query) {
return mysql_query($query, $this->dbLink);
}
function closeConnection() {
mysql_close($this->dbLink);
}
}
-
December 3rd, 2008, 01:18 PM #7
Re: Looking for php help
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
-
December 3rd, 2008, 01:20 PM #8Banned
- Join Date
- Dec 2007
- Location
-
Behind You, Watching, Always Watching
- Age
- 66
- Posts
- 5,410
- Rep Power
- 0
-
December 3rd, 2008, 01:21 PM #9
Re: Looking for php help
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.
-
December 3rd, 2008, 01:42 PM #10
Re: Looking for php help
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` --
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
Bookmarks