pixeltrace Posted March 11, 2007 Share Posted March 11, 2007 guys, i need help how do i create tables and rows using php? thanks! Quote Link to comment https://forums.phpfreaks.com/topic/42209-creating-tables-help/ Share on other sites More sharing options...
Barand Posted March 11, 2007 Share Posted March 11, 2007 Here's an example <?php /** * create a database connection and select a database */ $host = 'localhost'; $username = ''; $password = ''; $dbname = 'test'; $conn = mysql_connect ($host, $username, $password) or die(mysql_error()); mysql_select_db ($dbname, $conn) or die(mysql_error()); /** * create user table */ $sql = "CREATE TABLE user ( username VARCHAR(10) NOT NULL PRIMARY KEY, password VARCHAR(10), email VARCHAR(60) )"; mysql_query ($sql) or die(mysql_error()); /** * now add a record */ $sql = "INSERT INTO user (username, password, email) VALUES ('Barand', 'secret', 'barand@domain.com')"; mysql_query ($sql) or die(mysql_error()); ?> For more info: http://dev.mysql.com/doc/refman/4.1/en/index.html http://www.php.net/manual/en/ref.mysql.php Quote Link to comment https://forums.phpfreaks.com/topic/42209-creating-tables-help/#findComment-204750 Share on other sites More sharing options...
pixeltrace Posted March 11, 2007 Author Share Posted March 11, 2007 thanks! Quote Link to comment https://forums.phpfreaks.com/topic/42209-creating-tables-help/#findComment-204754 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.