Jump to content

Table?


eduard

Recommended Posts

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?
I suggest you just slow down, read each post, and work through the suggestions given to you. Just take the time to read what people tell you. We've all been trying to tell you pretty much the same things.So it seems you've completed step one: connecting to MySQLSo step 2 is as scientist has already pointed out in his post above. But remember, add only the code we tell you to add. Don't try to jump ahead or you'll end up in the same situation as before.
Link to comment
Share on other sites

  • Replies 165
  • Created
  • Last Reply
I suggest you just slow down, read each post, and work through the suggestions given to you. Just take the time to read what people tell you. We've all been trying to tell you pretty much the same things.So it seems you've completed step one: connecting to MySQLSo step 2 is as scientist has already pointed out in his post above. But remember, add only the code we tell you to add. Don't try to jump ahead or you'll end up in the same situation as before.
Ok, database created!Next step, please?
Link to comment
Share on other sites

What does your reduced code look like now? The one which successfully connects to MySQL and creates the database.(I already know your initial broken code; Give us the new working reduced one)

Link to comment
Share on other sites

Ok, database created!Next step, please?
OK! Next step:Create the table. For this step you'll need to remove portions of your code as well as add some new stuff.First, remove the portion of your code that creates the database. The database already exists so you don't need to run that code again. In fact, you'll get an error if you do. If you're unsure about what to remove, post your working code, like boen_robot suggested and we'll show you which part to remove.Second, add the code to create a table:
// Create tableif (mysql_select_db("my_db", $con)) {   echo "database selected";} else {   echo "could not select database: ".mysql_error();}$sql = "CREATE TABLE Persons (FirstName varchar (15), LastName varchar (15), Age int)";// Execute queryif(mysql_query($sql,$con)) {   echo "table created";} else {   echo "error creating table: ".mysql_error();}

You should see the "table created" message. If not, tell us what you are seeing instead. You can also double check in phpMyAdmin that the table was created.

Link to comment
Share on other sites

OK! Next step:Create the table. For this step you'll need to remove portions of your code as well as add some new stuff.First, remove the portion of your code that creates the database. The database already exists so you don't need to run that code again. In fact, you'll get an error if you do. If you're unsure about what to remove, post your working code, like boen_robot suggested and we'll show you which part to remove.Second, add the code to create a table:
// Create tableif (mysql_select_db("my_db", $con)) {   echo "database selected";} else {   echo "could not select database: ".mysql_error();}$sql = "CREATE TABLE Persons (FirstName varchar (15), LastName varchar (15), Age int)";// Execute queryif(mysql_query($sql,$con)) {   echo "table created";} else {   echo "error creating table: ".mysql_error();}

You should see the "table created" message. If not, tell us what you are seeing instead. You can also double check in phpMyAdmin that the table was created.

Ok, thanks!My (new code):<html><body><?php$con = mysql_connect("localhost","root","root");if ($con){ echo 'database connection initialized....'; }else { die ('Could not connect: ' . mysql_error()); }if (mysql_query("CREATE DATABASE mi_bd",$con)) {echo "Database created"; }else { echo "Error creating database: " . mysql_error(); }mysql_close($con);?></body></html>
Link to comment
Share on other sites

mi_db? Wasn't it my_db? Do not use Google Translate when copy and pasting code!!! Small things like that make a difference!Anyhow... you ran this code, and as output, you got

database connection initialized....Database created
or
database connection initialized....Error creating database: Can't create database 'my_db'; database exists
correct?If (and ONLY if) correct, replace ALL of your code with:
<html><body><?php$con = mysql_connect("localhost","root","root");if ($con){ echo 'database connection initialized....'; }else { die ('Could not connect: ' . mysql_error()); }if (mysql_select_db("mi_db", $con)) {   echo "database selected";} else {   echo "could not select database: ".mysql_error();}mysql_close($con);?></body></html>

From this, as output you should get

database connection initialized....database selected
do you get that as output?
Link to comment
Share on other sites

I suggest you just slow down, read each post, and work through the suggestions given to you. Just take the time to read what people tell you. We've all been trying to tell you pretty much the same things.So it seems you've completed step one: connecting to MySQLSo step 2 is as scientist has already pointed out in his post above. But remember, add only the code we tell you to add. Don't try to jump ahead or you'll end up in the same situation as before.
Thanks for your suggestion!
Link to comment
Share on other sites

just so you know, after a database/table is created, you don't have to keep that code in there.
I don´t understand! ....(code in there)
Link to comment
Share on other sites

mi_db? Wasn't it my_db? Do not use Google Translate when copy and pasting code!!! Small things like that make a difference!Anyhow... you ran this code, and as output, you gotorcorrect?If (and ONLY if) correct, replace ALL of your code with:
<html><body><?php$con = mysql_connect("localhost","root","root");if ($con){ echo 'database connection initialized....'; }else { die ('Could not connect: ' . mysql_error()); }if (mysql_select_db("mi_db", $con)) {   echo "database selected";} else {   echo "could not select database: ".mysql_error();}mysql_close($con);?></body></html>

From this, as output you should getdo you get that as output?

I have until now: database created; I´ll follow your advice!mi_db means in spanish mi base de datos, in english: my database
Link to comment
Share on other sites

mi_db means in spanish mi base de datos, in english: my database
Yes, I guessed that. But the computer can't. Remember the last time you were frustrated with an issue? When we told you many times to check the path, and in the end, the problem was because of the Spanish translation...The computer is really dumb, and you MUST keep that in mind. "my_db" and "mi_db" are two different things for the computer, just as "Applications" and "Applicaciones" are two different things. The computer isn't smart enough to treat one like the other.
Link to comment
Share on other sites

OK! Next step:Create the table. For this step you'll need to remove portions of your code as well as add some new stuff.First, remove the portion of your code that creates the database. The database already exists so you don't need to run that code again. In fact, you'll get an error if you do. If you're unsure about what to remove, post your working code, like boen_robot suggested and we'll show you which part to remove.Second, add the code to create a table:
// Create tableif (mysql_select_db("my_db", $con)) {   echo "database selected";} else {   echo "could not select database: ".mysql_error();}$sql = "CREATE TABLE Persons (FirstName varchar (15), LastName varchar (15), Age int)";// Execute queryif(mysql_query($sql,$con)) {   echo "table created";} else {   echo "error creating table: ".mysql_error();}

You should see the "table created" message. If not, tell us what you are seeing instead. You can also double check in phpMyAdmin that the table was created.

Now it goes wrong! I see nothing (no messages!)Code:<html><body><?php$con = mysql_connect("localhost","root","root");if ($con){ echo 'database connection initialized....'; }else { die ('Could not connect: ' . mysql_error()); }if (mysql_query("CREATE DATABASE my_db",$con)) {echo "Database created"; }else { echo "Error creating database: " . mysql_error(); } // Create tableif (mysql_select_db, ("my_db", $con)) { echo "database selected"; }else { echo "could not select database: " .mysql_error(); }$sql = "CREATE TABLE Persons (FirstName varchar (15), LastName varchar (15), Age int)";// Execute queryif (mysql_query($sql,$con)) { echo "table created"; }else "error creating table: ".mysql_error(); } mysql_close($con);?></body></html>
Link to comment
Share on other sites

Now it goes wrong! I see nothing (no messages!)Code:<html><body><?php$con = mysql_connect("localhost","root","root");if ($con){ echo 'database connection initialized....'; }else { die ('Could not connect: ' . mysql_error()); }if (mysql_query("CREATE DATABASE my_db",$con)) {echo "Database created"; }else { echo "Error creating database: " . mysql_error(); } // Create tableif (mysql_select_db, ("my_db", $con)) { echo "database selected"; }else { echo "could not select database: " .mysql_error(); }$sql = "CREATE TABLE Persons (FirstName varchar (15), LastName varchar (15), Age int)";// Execute queryif (mysql_query($sql,$con)) { echo "table created"; }else "error creating table: ".mysql_error(); } mysql_close($con);?></body></html>
this is where we start reinforcing in you the habits of debugging your code. You had it working at one point. Then you added something and now it doesn't work. That means something you added doesn't work. What part did you add? Are you missing any semi-colons? Do all your curly braces and parenthesis match? Are you following the example as it is being shown? Usually when the page just shows blank, it's because of a syntax error like on of the one's I just mentioned. These are the things you need to start checking for when this stuff happens. You don't have a lot of code. Figuring out the problem area shouldn't be too hard.as far as what I said about not needing to keep your database and table code, well it means exactly like what I said. If you successfully create a database or a table, then it's been made. You don't have to make it again. It's just there. Do you think it just disappears because the code stops running? That's the purpose of creating a database in the first place, to have a place to store and retrieve data. That's why we keep telling you to look in phpMyAdmin, because then you will actually see what you're doing show up.
Link to comment
Share on other sites

this is where we start reinforcing in you the habits of debugging your code. You had it working at one point. Then you added something and now it doesn't work. That means something you added doesn't work. What part did you add? Are you missing any semi-colons? Do all your curly braces and parenthesis match? Are you following the example as it is being shown? Usually when the page just shows blank, it's because of a syntax error like on of the one's I just mentioned. These are the things you need to start checking for when this stuff happens. You don't have a lot of code. Figuring out the problem area shouldn't be too hard.as far as what I said about not needing to keep your database and table code, well it means exactly like what I said. If you successfully create a database or a table, then it's been made. You don't have to make it again. It's just there. Do you think it just disappears because the code stops running? That's the purpose of creating a database in the first place, to have a place to store and retrieve data. That's why we keep telling you to look in phpMyAdmin, because then you will actually see what you're doing show up.
The problem with phpAdmin is that I can´t log in and I don´t know until now why?And the second point you mentioned (creating a database) I think that´s the problem; I am going to find out now!
Link to comment
Share on other sites

The problem with phpAdmin is that I can´t log in and I don´t know until now why?And the second point you mentioned (creating a database) I think that´s the problem; I am going to find out now!
so..google some answers for yourself about phpMyAdmin. It would make since though that the login that you are using to connect to MySQL should be the same login to access phpMyAdmin. That's what I would I try first.about creating the database, it shouldn't break your code, but as everyone has already mentioned, you would probably see a warning error. If the database has been made, then you should try connecting to it. If that's successful (by having a message show up if you have a successful connection), then you know it worked. But please read what I said about syntax errors. The majority of cases where NOTHING appears on the page is usually due to syntax errors. I gave you some debugging strategies, so you should be able to figure it out.edit: If you read my debugging tips about matching opening and closing curly braces, you would have found your syntax error in this code. Not surprisingly, it was the last thing that you just added. You could have verified it by doing something like this to confirm.
<?php$con = mysql_connect("localhost","root","root");if ($con){echo 'database connection initialized....';}else{die ('Could not connect: ' . mysql_error());}//this is now redundent.  take it out. should be confirmed in the table select if/else//if (mysql_query("CREATE DATABASE my_db",$con))//{//echo "Database created";//}//else//{//echo "Error creating database: " . mysql_error();//}// Create tableif (mysql_select_db, ("my_db", $con)){echo "database selected";}else{echo "could not select database: " .mysql_error();}//$sql = "CREATE TABLE Persons (FirstName varchar (15), LastName varchar (15), Age int)";// Execute query//if (mysql_query($sql,$con))//{//echo "table created";//}//else "error creating table: ".mysql_error();//} mysql_close($con);?>

make SURE you are selecting a database BEFORE you try the next step. I think there is an error in there, so you NEED to fix this code before you can move on.

Link to comment
Share on other sites

Connection is okCreating a database is okThe problem is creating a table:Code:<html><body><?php$con = mysql_connect("localhost","root","root");if ($con){ echo 'database connection initialized....'; }else { die ('Could not connect: ' . mysql_error()); } // Create tableif (mysql_select_db, ("my_db", $con)) { echo "database selected"; }else { echo "could not select database: " .mysql_error(); }$sql = "CREATE TABLE Persons (FirstName varchar (15), LastName varchar (15), Age int)";// Execute queryif (mysql_query($sql,$con)) { echo "table created"; }else "error creating table: ".mysql_error(); } mysql_close($con);?></body></html>

Link to comment
Share on other sites

"my_db" or "mi_db"?What worked before?What do you get as output from that? Reduce it back to something where you successfully get something as output.

Link to comment
Share on other sites

Let's step back then... what's the output you get out of this:

<?php$con = mysql_connect("localhost","root", "root");if (!$con){die ('Could not connect: ' . mysql_error());}if (mysql_query("CREATE DATABASE my_db",$con)){echo "Database created";}else{echo "Error creating database: " . mysql_error();}?>

THE OUTPUT! WHAT is it?(there's a difference between what you think is happening and what is actually happening. The output will tell us the truth.)

Link to comment
Share on other sites

Connection is okCreating a database is okThe problem is creating a table:Code:<html><body><?php$con = mysql_connect("localhost","root","root");if ($con){ echo 'database connection initialized....'; }else { die ('Could not connect: ' . mysql_error()); } // Create tableif (mysql_select_db, ("my_db", $con)) { echo "database selected"; }else { echo "could not select database: " .mysql_error(); }$sql = "CREATE TABLE Persons (FirstName varchar (15), LastName varchar (15), Age int)";// Execute queryif (mysql_query($sql,$con)) { echo "table created"; }else "error creating table: ".mysql_error(); } mysql_close($con);?></body></html>
Do you mean they are successful because you saw the messages? If so, then I've already told you that you had mismatched curly braces in the code section that you are using to create the table. This is why it's so frustrating helping you. We even tell you where to look for your problems and you don't try it.
Link to comment
Share on other sites

Do you mean they are successful because you saw the messages? If so, then I've already told you that you had mismatched curly braces in the code section that you are using to create the table. This is why it's so frustrating helping you. We even tell you where to look for your problems and you don't try it.
Sorry, I got this code of a moderator of the forum!
Link to comment
Share on other sites

Do you mean they are successful because you saw the messages? If so, then I've already told you that you had mismatched curly braces in the code section that you are using to create the table. This is why it's so frustrating helping you. We even tell you where to look for your problems and you don't try it.
<html><body><?php$con = mysql_connect("localhost","root","root");if ($con) { echo 'database connection initialized....'; }else { die ('Could not connect: ' . mysql_error()); }// Create tableif (mysql_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 created"; }else "error creating table: ".mysql_error(); } ?></body></html>P. s. I saw the messages, but still it doesn´t work!
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.


×
×
  • Create New...