Jump to content

Table?


Recommended Posts

  • Replies 165
  • Created
  • Last Reply

Top Posters In This Topic

I am still not able to create a table (connection is ok!)!Code:<html><body><?php$con = mysql_connect;if (!$con){die ('Could not connect: ' . mysql_error());}// Create databaseif (mysql_query ("CREATE DATABASE my_db",$con)){echo "Database created";}else{echo "Error creating database: " . mysql_error();}// Create tablemysql_select_db("my_db", $con);$sql = "CREATE TABLE Persons"{FirstName varchar (15),LastName varchar (15),Age int}";// Execute queryif(mysql_query($sql,$con)){ echo 'table made'; //check phpMyAdmin to confirm}else{ echo 'error, table not made';};mysql_close($con);?></body></html>Who knows why?
Back to square one I see. One thing is that you are still using curly braces here:
// Create tablemysql_select_db("my_db", $con);$sql = "CREATE TABLE Persons"{FirstName varchar (15),LastName varchar (15),Age int}";

you're connect statement should look like this:

$con = mysql_connect(servername,username,password);

If you just removed it because of what I said about showing username and password when posting, then I guess you didn't read everything because I said you should keep some place holders so people don't assume that part of your code is wrong, i.e.

$con = mysql_connect("my_db","****","******");

but more to the point:1) every time you run the script, do you NOT see a connection error, if YES, go to 2 2) If you've verified that database exists in phpMyAdmin, you don't need to keep making it. If you can verify that the database has been made, then move onto step 33) add the code that I suggested to test for the creation of a table. Make sure to REMOVE THE CURLY BRACESas we have repeatedly been saying, only add the next step after you've verified with conditional statements or in phpMyAdmin that the previous step has been successful

Link to post
Share on other sites
Back to square one I see. One thing is that you are still using curly braces here:
// Create tablemysql_select_db("my_db", $con);$sql = "CREATE TABLE Persons"{FirstName varchar (15),LastName varchar (15),Age int}";

you're connect statement should look like this:

$con = mysql_connect(servername,username,password);

If you just removed it because of what I said about showing username and password when posting, then I guess you didn't read everything because I said you should keep some place holders so people don't assume that part of your code is wrong, i.e.

$con = mysql_connect("my_db","****","******");

but more to the point:1) every time you run the script, do you NOT see a connection error, if YES, go to 2 2) If you've verified that database exists in phpMyAdmin, you don't need to keep making it. If you can verify that the database has been made, then move onto step 33) add the code that I suggested to test for the creation of a table. Make sure to REMOVE THE CURLY BRACESas we have repeatedly been saying, only add the next step after you've verified with conditional statements or in phpMyAdmin that the previous step has been successful

My new code:<html><body><?php$con = mysql_connect("my_db","****","******");if (!$con){die ('Could not connect: ' . mysql_error());}// Create databaseif (mysql_query ("CREATE DATABASE my_db",$con)){echo "Database created";}else{echo "Error creating database: " . mysql_error();}// Create tablemysql_select_db("my_db", $con);$sql = "CREATE TABLE Persons"(FirstName varchar (15),LastName varchar (15),Age in) " ;// Execute queryif(mysql_query($sql,$con)){ echo 'table made'; //check phpMyAdmin to confirm}else{ echo 'error, table not made';};mysql_close($con);?></body></html>How do I verify my database in phpMyAdmin?
Link to post
Share on other sites

You probably want to use:$con = mysql_connect("localhost","****","******");instead of:$con = mysql_connect("my_db","****","******");

How do I verify my database in phpMyAdmin?
If you go to http://localhost/phpmyadmin/ you should see on the left side a list of databases (EDIT: Assuming the layout is the same as it is in WAMP). If yours is there, it's been created. Edited by ShadowMage
Link to post
Share on other sites
You probably want to use:$con = mysql_connect("localhost","****","******");instead of:$con = mysql_connect("my_db","****","******");If you go to http://localhost/phpmyadmin/ you should see on the left side a list of databases (EDIT: Assuming the layout is the same as it is in WAMP). If yours is there, it's been created.
sorry, that should have been localhost. (but eduard should have seen that error if he's been doing his reading...)and he should know about phpMyAdmin, it's already been discussed in another thread.eduard, is too much to actually get the specifics of what happens when you run your code? Could you at least tell us if you get any messages? That's been the whole point of these exercises is that you can get the feedback right on the page. Like I've said, you may get messages saying things have already been made, so that's good to report as well. Edited by thescientist
Link to post
Share on other sites
sorry, that should have been localhost. (but eduard should have seen that error if he's been doing his reading...)and he should know about phpMyAdmin, it's already been discussed in another thread.eduard, is too much to actually get the specifics of what happens when you run your code? Could you at least tell us if you get any messages? That's been the whole point of these exercises is that you can get the feedback right on the page. Like I've said, you may get messages saying things have already been made, so that's good to report as well.
Of course?; I saw ´my_db´, but I am not an expert!
Link to post
Share on other sites
sorry, that should have been localhost. (but eduard should have seen that error if he's been doing his reading...)and he should know about phpMyAdmin, it's already been discussed in another thread.eduard, is too much to actually get the specifics of what happens when you run your code? Could you at least tell us if you get any messages? That's been the whole point of these exercises is that you can get the feedback right on the page. Like I've said, you may get messages saying things have already been made, so that's good to report as well.
I don´t see anything (No message!)
Link to post
Share on other sites
I don´t see anything (No message!)
So do you see anything in phpMyAdmin? Is the database there?If not, you might be better to just scrap your existing script and start over, like boen suggested quite a few posts back. Edited by ShadowMage
Link to post
Share on other sites

If I don´t see the message: ´Database created´ nor ´Error creating database´, there isn´t a database?I think there is connection between my php file and MySQL, but there isn´t a database!P. s. I am too tired to download and install phpMyAdmin!

Edited by eduardchile
Link to post
Share on other sites
If I don´t see the message: ´Database created´ nor ´Error creating database´, there isn´t a database?I think there is connection between my php file and MySQL, but there isn´t a database!P. s. I am too tired to download and install phpMyAdmin!
it comes with (W/M/L)AMP!didn't you bother trying it when we told you about it in your other thread? remember...
http://localhost:8888/phpMyAdmin

but yeah, let's start this whole thing over. Let's start small. Let's establish a connection with the database, and see if we can get that going. so as we've been suggesting, lets take it in steps. First thing...db connection.

<?php$con = mysql_connect("localhost","root","root");if ($con){  echo 'database connection initialized....';}else{  die ('Could not connect: ' . mysql_error());};?>

if that's good, then we can proceed with the next step. At this point, we are just making that you have are using the correct login credentials. This step must be established as working before you can do anything else. If it's not, you must figure the correct username and password to be using. From what I remember, the default username/password is root and root. These can (and should) be changed, but for now just stick with it. If you have problems, this Google search should help you out.http://www.google.com/#sclient=psy&hl=...87e3794f75b2bfa

Edited by thescientist
Link to post
Share on other sites
it comes with (W/M/L)AMP!didn't you bother trying it when we told you about it in your other thread? remember...
http://localhost:8888/phpMyAdmin

but yeah, let's start this whole thing over. Let's start small. Let's establish a connection with the database, and see if we can get that going. so as we've been suggesting, lets take it in steps. First thing...db connection.

<?php$con = mysql_connect("localhost","root","root");if ($con){  echo 'database connection initialized....';}else{  die ('Could not connect: ' . mysql_error());};?>

if that's good, then we can proceed with the next step. At this point, we are just making that you have are using the correct login credentials. This step must be established as working before you can do anything else. If it's not, you must figure the correct username and password to be using. From what I remember, the default username/password is root and root. These can (and should) be changed, but for now just stick with it. If you have problems, this Google search should help you out.http://www.google.com/#sclient=psy&hl=...87e3794f75b2bfa

As I wrote 2 hours ago: their is connection!Next step please?
Link to post
Share on other sites

I don´t get it:(http://www.webdevelopersnotes.com/tutorials/sql/mysql_training_course_creating_tables.php3)document (employees data) (saved in MAMP):Manish Sharma, 28, India, manish@simplygraphix.comJohn Doe, 32, Australia, j.dow@nowhere.comJohn Wayne, 48, U.S.A,jw@oldwesterns.comAlexander, 19, Greece, alex@conqueror.com(file (saved in MAMP) db employees.php)<html><body><?php$con = mysql_connect("localhost","eduard","-z.x,c");if (!$con){ die ('Could not connect: ' . mysql_error());}// Create databaseif (mysql_query ("CREATE DATABASE create",$con)){ echo "Database created";}else{ echo "Error creating database: " . mysql_error();}// Create tablemysql_select_db("employees data -u manish -p", $con);$sql = CREATE TABLE employees data (emp_id int unsigned not null auto_increment primary key,f_name varchar(15),l_name varchar(15),age intemail varchar(60));// Execute querymysql_query($sql,$con));mysql_close($con);?></body></html>P. s. I read there is a difference for Apple computers!

Link to post
Share on other sites
As I wrote 2 hours ago: their is connection!Next step please?
So you've verified this by seeing the 'connection initialized' message? That's what we want to know before we go on to step two because this is the step that we believe you are getting wrong.. I'm curious, how did you know that you were connected before before we added the success message? Just because you didn't see an error message, doesn't mean you didn't have a syntax error that would cause the page to not run. The worst thing you can do is assume that it is working, that's why I added the success message. also, we are you still showing us your password? And did you actually change the username and password yourself?edit: Just follow the steps one by one! Stop trying to get ahead of yourself. Being impatient isn't going to get you there any faster. If you knew what you were doing we wouldn't be going this slow, but you'll never learn by throwing all this code into a pile without knowing why the code does what it does! Anyway.... Edited by thescientist
Link to post
Share on other sites
So you've verified this by seeing the 'connection initialized' message? That's what we want to know before we go on to step two because this is the step that we believe you are getting wrong.. I'm curious, how did you know that you were connected before before we added the success message? Just because you didn't see an error message, doesn't mean you didn't have a syntax error that would cause the page to not run. The worst thing you can do is assume that it is working, that's why I added the success message. also, we are you still showing us your password? And did you actually change the username and password yourself?edit: Just follow the steps one by one! Stop trying to get ahead of yourself. Being impatient isn't going to get you there any faster. If you knew what you were doing we wouldn't be going this slow, but you'll never learn by throwing all this code into a pile without knowing why the code does what it does! Anyway....
You are right! I didn´t get a message, so I ASSUMED I was connected!I am going to have breakfast now and after that I´ll study it again!
Link to post
Share on other sites
You are right! I didn´t get a message, so I ASSUMED I was connected!I am going to have breakfast now and after that I´ll study it again!
You know what they say about assumptions... :)Anyway, like scientist and I said, it's probably a good idea for you to just start over. Start a completely new script. Take it one step at a time, and if/when you have problems tell us exactly what the problem is including errors and messages you get.So, that said, the first step scientist already outlined for you:
<?php$con = mysql_connect("localhost","root","root");if ($con){  echo 'database connection initialized....';}else{  die ('Could not connect: ' . mysql_error());};?>

I think boen_robot mentioned that the default password might be blank so you might need to try it both ways. Ie, try:$con = mysql_connect("localhost","root","root");and if that doesn't work then try:$con = mysql_connect("localhost","root","");Make sure that this is the only thing in your script at this point. Once we establish that you have a connection, we can move on. After you run this code, tell us what you see. In order to move on you need to recieve the "database connection initialized" message.

Link to post
Share on other sites

Thanks! This is always the problem! I get many different replies from many persons! So I get confused, frustrated, angry, etc.!What do you suggest to avoid these?

Link to post
Share on other sites

we've only been saying the same thing: start over and only try to connect to the DB. That means actually connecting to the server, which requires the correct code and using the correct login details. You've been trying to do to much and not listening to us when we tell you to debug, or to take it one step at a time, or verify your steps as you go, etc, etc. You said you had connected but without any confirmation, and assumed you could jump 2 -3 steps ahead. You need to become more patient and learn everything at a slower pace, but that's nothing we can help you with.

Edited by thescientist
Link to post
Share on other sites
we've only been saying the same thing: start over and only try to connect to the DB. That means actually connecting to the server, which requires the correct code and using the correct login details. You've been trying to do to much and not listening to us when we tell you to debug, or to take it one step at a time, or verify your steps as you go, etc, etc. You said you had connected but without any confirmation, and assumed you could jump 2 -3 steps ahead. You need to become more patient and learn everything at a slower pace, but that's nothing we can help you with.
But I also received many replies (from forum members?) who said other things!P. s. 1 the database is connected now as ShadowImage said (I got the message: database iniitialized). P. s. 2 I´ll tell you after my database is on the internet why I´m so stressed!Therefore the next step please? Edited by eduardchile
Link to post
Share on other sites
But I also received many replies (from forum members?) who said other things!P. s. 1 the database is connected now as ShadowImage said (I got the message: database iniitialized). P. s. 2 I´ll tell you after my database is on the internet why I´m so stressed!Therefore the next step please?
perfect. that's what we've been waiting for this whole time. So now that you have a connection, you should be able to figure out the next step. It is to create a database (which you already have code, tutorials, and examples for). So try that out, and return with your code if you have questions (but it should only contain the connect code and the create code). Make sure you put the code in an if/else statement so you can get success or failure feedback. At any point if something doesn't appear on the screen, then you most likely have a syntax error. If you succeed in creating a database, and see a message, then open phpMyAdmin and you should see the database you create listed on the left hand side. Edited by thescientist
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...