mysql - Connecting to a database using php script -
i have created form in html , action set php script. i'm pretty new php , wondering if me out it? need write script add info form database. need create database , table well. did lot of reading on net , i'm still unable it. script have. please tell me mistakes have made. thank help.
<?php $con=mysql_connect("example.com","peter","abc123","my_db"); $sql="create database user"; if (mysql_query($con,$sql)) { echo "database user created successfully"; } $sql="create table persons(pid int not null auto_increment, primary key(pid),firstname char(30),lastname char(30),age int, dateofbirth date, email char(30)"; if (mysql_query($con,$sql)) { echo "connected database"; } $sql="insert persons (firstname, lastname, age, dateofbirth, email) values ('$_post[firstname]','$_post[lastname]','$_post[age]','$_post[dateofbirth]','$_post[email]')"; if (mysql_query($con,$sql)) { echo "added database"; } mysql_close($con); ?>
i tried suggested answers , still not able it. can please provide code that? need obtain data form , insert database using php!
hi try code,
$con=mysql_connect("example.com","peter","abc123"); $sql="create database user"; if (mysql_query($sql)) { echo "database user created successfully"; }
Comments
Post a Comment