pratkal Posted April 5, 2011 Author Share Posted April 5, 2011 finally was able to run the code and create a table this is the code that works in end <?phpinclude '../config.php';$con = mysql_connect("$dbhost","$dbuser","$dbpass");if (!$con) { die('Could not connect: ' . mysql_error()); }else { echo "Table in database created please click continue to go to next step "; }// Create tablemysql_select_db("goaddwor_mydb");$sql = "CREATE TABLE admin(id INT NOT NULL AUTO_INCREMENT,PRIMARY KEY(id),username varchar(100) NOT NULL,password varchar(100)NOT NULL,fname varchar(100) NOT NULL,lname varchar(100) NOT NULL,email varchar(100) NOT NULL)";// Execute querymysql_query($sql,$con) or exit(mysql_error());mysql_close($con);?> thanks all for helpjust 1 quick question how to create multiple table with my code Link to comment Share on other sites More sharing options...
birbal Posted April 5, 2011 Share Posted April 5, 2011 as you did.prepare your sql commands and executing it using mysql_query() as many times. but remember that in one database two same tables name cant exist. Link to comment Share on other sites More sharing options...
pratkal Posted April 5, 2011 Author Share Posted April 5, 2011 should i name then something else for ex$sql2 = "create table user(id INT NOT NULL AUTO_INCREMENT,PRIMARY KEY(id),username varchar(100) NOT NULL,password varchar(100)NOT NULL,fname varchar(100) NOT NULL,lname varchar(100) NOT NULL,email varchar(100) NOT NULL)";mysql_query($sql,$sql2,$con) or exit(mysql_error());in other word i can name it w/e i like $sql is just a name Link to comment Share on other sites More sharing options...
birbal Posted April 5, 2011 Share Posted April 5, 2011 you can name it as you like but with maintaining the identifier naming rules.you can not use mysql_query() this way mysql_query($sql1,$sql2,$sql3) for more details you can check mysql_query()if you use same variable for different sql it will overwrite the previous one everytime. so when you pass the $sql to mysql_query() the last assigned value to $sql will be executed. Link to comment Share on other sites More sharing options...
pratkal Posted April 5, 2011 Author Share Posted April 5, 2011 so i have to give unique query each time i want to create a table or run any query Link to comment Share on other sites More sharing options...
birbal Posted April 5, 2011 Share Posted April 5, 2011 its not obviouse but you can do that also.same variable different sql $sql='some sql 1';mysql_query($sql); //it will execute the some sql 1$sql='some sql 2';mysql_query($sql) //it will execute some sql 2 different variable different sql $sql1='some sql 1';mysql_query($sql); //it will execute the some sql 1$sql2='some sql 2';mysql_query($sql) //it will execute some sql 2 $sql='some sql 1';$sql='some sql 2';mysql_query($sql) //it will execute some sql 2 $sql='some sql 1';mysql_query($sql); //it will execute the some sql 1mysql_query($sql) //it will execute some sql 1 AGAIN Link to comment Share on other sites More sharing options...
pratkal Posted April 5, 2011 Author Share Posted April 5, 2011 thanks was helpful Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.