By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,101 Members | 1,340 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,101 IT Pros & Developers. It's quick & easy.

Trouble in accessing the database

P: 15
hi!
I'm completely new to PHP and MySQL and I am using WAMP 5.This is something I extracted from a web tutorial. Although it is to create a table called students in a database named College it does not create one.
Can someone pls show me where I have gone wrong in the following codings?
Expand|Select|Wrap|Line Numbers
  1. <?
  2. $username="root";
  3. $password="";
  4. $database="College";
  5.  
  6. $name=$_POST['name'];
  7. $dob=$_POST['dob'];
  8.  
  9.  
  10. mysql_connect(localhost,$username,$password);
  11. @mysql_select_db($database) or die( "Unable to select database");
  12.  
  13.  
  14. if (mysql_is_table('localhost', $username, $password, $database, 'Students')) { 
  15.     $query="CREATE TABLE Students (index int(6) NOT NULL auto_increment,Name varchar(20) NOT NULL,DoB varchar(15) NOT NULL)"; 
  16. } else { 
  17.     $query = "INSERT INTO Students VALUES ('','$name','$dob')"; 
  18.  
  19. mysql_query($query);
  20.  
  21. mysql_close();
  22. ?>
[Please use CODE tags when posting source code. Thanks! --pbmods]
May 25 '07 #1
Share this Question
Share on Google+
7 Replies


Motoma
Expert 2.5K+
P: 3,235
Do you get back any error messages?

hi!
I'm completely new to PHP and MySQL and I am using WAMP 5.This is something I extracted from a web tutorial. Although it is to create a table called students in a database named College it does not create one.
Can someone pls show me where I have gone wrong in the following codings?

<?
$username="root";
$password="";
$database="College";

$name=$_POST['name'];
$dob=$_POST['dob'];


mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");


if (mysql_is_table('localhost', $username, $password, $database, 'Students')) {
$query="CREATE TABLE Students (index int(6) NOT NULL auto_increment,Name varchar(20) NOT NULL,DoB varchar(15) NOT NULL)";
} else {
$query = "INSERT INTO Students VALUES ('','$name','$dob')";
}

mysql_query($query);

mysql_close();
?>
May 25 '07 #2

P: 15
Do you get back any error messages?
Hi!,
I could fix it. Thanx!
Now I have some more problems.
1) Is there a way like u enter the name of the table that u need to create in the dbase to a textbox and when u submit it, a table with that name is created in the dbase?

2)U create an HTML form with a table and in one column of it, u have text boxes to enter data.After entering data to those text boxes when u submit it data must be added to a particular table in the db?
May 27 '07 #3

Motoma
Expert 2.5K+
P: 3,235
Hi!,
I could fix it. Thanx!
Now I have some more problems.
1) Is there a way like u enter the name of the table that u need to create in the dbase to a textbox and when u submit it, a table with that name is created in the dbase?

2)U create an HTML form with a table and in one column of it, u have text boxes to enter data.After entering data to those text boxes when u submit it data must be added to a particular table in the db?
Take a look at this article written by yours truly.
May 29 '07 #4

pbmods
Expert 5K+
P: 5,821
1) Is there a way like u enter the name of the table that u need to create in the dbase to a textbox and when u submit it, a table with that name is created in the dbase?

2)U create an HTML form with a table and in one column of it, u have text boxes to enter data.After entering data to those text boxes when u submit it data must be added to a particular table in the db?
You mean like phpMyAdmin?
May 29 '07 #5

ak1dnar
Expert 100+
P: 1,584
Now I have some more problems.
1) Is there a way like u enter the name of the table that u need to create in the dbase to a textbox and when u submit it, a table with that name is created in the dbase?

2)U create an HTML form with a table and in one column of it, u have text boxes to enter data.After entering data to those text boxes when u submit it data must be added to a particular table in the db?
If it not phpmyadmin, and it is your own script.
try to send the values from a form to the $result then you can make it.
Try over here
May 29 '07 #6

P: 15
Well,This is another problem I am having.
I am doing a web application using PHP/MySQL and Dreamweaver.I ve created a database and some tables in it.But when I pass data to a table through a form(using POST method), the actual data does not go to the table.Say I entered the data 5 times.Then it indicates that 5 rows are there,but it does not show the actual data that I entered....Ny guesses y it happens..Somehow I feel like the problem is in the connection of database(I m not sure though)..I will be really glad if someone can help me.
Jun 18 '07 #7

Motoma
Expert 2.5K+
P: 3,235
Well,This is another problem I am having.
I am doing a web application using PHP/MySQL and Dreamweaver.I ve created a database and some tables in it.But when I pass data to a table through a form(using POST method), the actual data does not go to the table.Say I entered the data 5 times.Then it indicates that 5 rows are there,but it does not show the actual data that I entered....Ny guesses y it happens..Somehow I feel like the problem is in the connection of database(I m not sure though)..I will be really glad if someone can help me.
Perhaps you could post the relevant code, and list any error messages you are getting.
Jun 18 '07 #8

Post your reply

Sign in to post your reply or Sign up for a free account.