how to connect to mysql in php

12 views
Skip to first unread message

Ghulam Mustafa Bajwa

unread,
Sep 4, 2013, 6:04:56 AM9/4/13
to xamp...@googlegroups.com
im a new one and want to insert data to into database through user input  so any help will warmly regarded

Anish Kumar

unread,
Sep 4, 2013, 6:45:51 AM9/4/13
to xamp...@googlegroups.com
Dear Ghulam,

First you have to make data base connection and then you use insert query for insert data in data base:---

For make Database Connection use below code:-

<?php
$host = 'hostname';   (for ex-localhost)
$username = 'username';  (for ex- root)
$password = 'password';   
$dbName = 'Db name';


mysql_connect($host, $username ,$password) or
            die(mysql_error());
mysql_select_db($dbName) or
            die(mysql_error());


and after it you have to use insert query:-

INSERT INTO `tablename` (`field1`, `field2`, `field2`, `field3`, `field4`) VALUES
(field1value, 'field2value', 'field3value', 'field4value');


NOTE:- YOU CAN USE ANY INSERT QUERY OUT OF THREE
Regards,
Lal Babu



On Wed, Sep 4, 2013 at 3:34 PM, Ghulam Mustafa Bajwa <arto...@gmail.com> wrote:
im a new one and want to insert data to into database through user input  so any help will warmly regarded

--
Ask New Question from : https://groups.google.com/forum/?fromgroups#!newtopic/xamppdev
 
Create filter of mails from this group http://www.wikihow.com/Create-a-Filter-in-Gmail
---
You received this message because you are subscribed to the Google Groups "PHP Developers' Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to xamppdev+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/xamppdev/36b5f62e-c77e-4ba7-a817-ee8dc582c583%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Ghulam Mustafa Bajwa

unread,
Sep 5, 2013, 1:10:45 AM9/5/13
to xamp...@googlegroups.com
So much Thanks Lal Babu. and it work fine and save me from grate hardle

Kwame A.

unread,
Sep 5, 2013, 12:31:07 PM9/5/13
to xamp...@googlegroups.com
You would also need to filter user input(text, emails, etc). Using PDO helps a lot as it build to automatically escape strings, you can also use filter_var function to filter inputs. You would be wasting time if data is directly inserted into database without any form of validation. Google this out as mysql with php is easy to grab. Visit this link below http://www.tizag.com/mysqlTutorial/ everything is sitting in there for you. Enjoy your time.


Reply all
Reply to author
Forward
0 new messages