Jump to content

Table?


Recommended Posts

I still can´t create a table! And I never got an answer to the question: my "my-db" must be a php file?Code:<html><body><?php$con = mysql_connect("localhost","eduard");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 querymysql_query($sql,$con);mysql_close($con);?></body></html>

Edited by eduardchile
Link to post
Share on other sites
  • Replies 165
  • Created
  • Last Reply

Top Posters In This Topic

I don't know what your "my-db" is, but if you're talking about the database, no, a database is not a PHP file.You're not checking for errors when you try to create the table, you should check if the query failed and print an error message if it did.mysql_query($sql,$con) or exit(mysql_error());

Link to post
Share on other sites

good lord, do you even read anything we tell you? At all? Even just a little bit?First off, you're not using root as the username. Unless you specifically changed it in the configuration file, then this will not work. It should be quite simple. Can you even just get it to display a connection successful message? Drop the table code and just work at just getting step one to work.Also, we've had a whole thread discussing the relationship between PHP and SQL. The main point being other than PHP allowing you to connect to a database, there IS NO intrinsic relationship.And lastly, I'm not sure how long you plan on doing this, but keep your topics distinct! This IS STILL THE SAME ISSUE! You are hogging up all the space in this forum by asking the same question repeatedly, and thus cluttering up the forum with your threads while other users are actually trying to follow the rules. Its cluttering up the database and detracting from other users who are posting legitimate topics of unique distinction. You may not realize it but this is borderline selfish behavior. Moderators and members alike have brought this issue up before, not just myself. So follow the rules, and just bump your own threads. It's not like we're not trying to help, but give us a reason. Right now there might as well be a brick wall on the other end, and you're only doing yourself a disservice by not listening to our repeated pleas to engage in proper forum etiquette.phew.

Link to post
Share on other sites

Try to do this one step at a time...

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

What does this output? It needs to output

Database connection estabilished.
Does it? Try it!!!
Link to post
Share on other sites
good lord, do you even read anything we tell you? At all? Even just a little bit?First off, you're not using root as the username. Unless you specifically changed it in the configuration file, then this will not work. It should be quite simple. Can you even just get it to display a connection successful message? Drop the table code and just work at just getting step one to work.Also, we've had a whole thread discussing the relationship between PHP and SQL. The main point being other than PHP allowing you to connect to a database, there IS NO intrinsic relationship.And lastly, I'm not sure how long you plan on doing this, but keep your topics distinct! This IS STILL THE SAME ISSUE! You are hogging up all the space in this forum by asking the same question repeatedly, and thus cluttering up the forum with your threads while other users are actually trying to follow the rules. Its cluttering up the database and detracting from other users who are posting legitimate topics of unique distinction. You may not realize it but this is borderline selfish behavior. Moderators and members alike have brought this issue up before, not just myself. So follow the rules, and just bump your own threads. It's not like we're not trying to help, but give us a reason. Right now there might as well be a brick wall on the other end, and you're only doing yourself a disservice by not listening to our repeated pleas to engage in proper forum etiquette.phew.
Sorry, but step 1 (connection is working some days, I removed "localhost" and "eduard" and I know since 6 hours that there is no relatinship BUT I still haven´t a table!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 querymysql_query($sql,$con);mysql_close($con);?></body></html>P. s. if you close the thread, how can I react??? Edited by eduardchile
Link to post
Share on other sites

just for future references sake, you should still leave some place holder for those values, or else people will think your getting the connection part wrong. just replace the characters with * instead. People will understand the intent.Do you know you're not making a table because you are relying on a feedback message from your script? Or are you verifying in phpMyAdmin? One obvious mistake in the code is that you are using curly braces instead of parenthesis. You can just follow the convention from the DB connect part to show a message.

// 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';};

edit: no one said anything about closing a thread, but you're making it harder for other people to get their threads seen, you spreading out the same questions over multiple topics, making it harder for people to help you and keep information centralized, and you're making more work for the mods because they will end up merging your threads together because of the similarities. I don't think it's asking to much to keep your own threads organized and updated. You said yourself you find it confusing to keep track of posts and replies. How does making multiple threads about the same subject do anything to alleviate that burden on yourself?

Edited by thescientist
Link to post
Share on other sites
Try to do this one step at a time...
<?php$con = mysql_connect("localhost","root", "");if (!$con){die ('Could not connect: ' . mysql_error());}echo "Database connection estabilished.";?>

What does this output? It needs to outputDoes it? Try it!!!

Connection is not my question (I have connection) BUT I haven´t yet a table!
Link to post
Share on other sites
There is no error!
So you added the code I told you to add, ran the page, and didn't see an error. If that's true, then it created the table. With the code I told you to add, if it failed creating the table then you would have seen an error. So congratulations, you made a table. If you refresh the page you should see an error due to the fact that the table already exists, you can't create it again.
Link to post
Share on other sites

and as I've pointed out (again and again... :)) you can verify in phpMyAdmin....edit: just for sticks giggles, what does your code look like now?

Edited by thescientist
Link to post
Share on other sites

One... f**king... step... at a time...The reason is never the place you have a problem with itself - the reason is always something before or during the thing that's supposed to make it.OK... if my previous example above is working, try this:

<?php$con = mysql_connect("localhost","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();}?>

What does that output? It should output either

Database created
or
Error creating database: Can't create database 'my_db'; database exists
Does it? Try it!
Link to post
Share on other sites
just for future references sake, you should still leave some place holder for those values, or else people will think your getting the connection part wrong. just replace the characters with * instead. People will understand the intent.Do you know you're not making a table because you are relying on a feedback message from your script? Or are you verifying in phpMyAdmin? One obvious mistake in the code is that you are using curly braces instead of parenthesis. You can just follow the convention from the DB connect part to show a message.
// 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';};

edit: no one said anything about closing a thread, but you're making it harder for other people to get their threads seen, you spreading out the same questions over multiple topics, making it harder for people to help you and keep information centralized, and you're making more work for the mods because they will end up merging your threads together because of the similarities. I don't think it's asking to much to keep your own threads organized and updated. You said yourself you find it confusing to keep track of posts and replies. How does making multiple threads about the same subject do anything to alleviate that burden on yourself?

I don´t understand your first part (connection)! and what does a red ? before a thread mean? I thought topic is closed (by you), but it seems it isn´t Therefore it´sn´t necessary for me indeed to post the same thread twice!
Link to post
Share on other sites
what does a red ? before a thread mean? I thought topic is closed (by you), but it seems it isn´t Therefore it´sn´t necessary for me indeed to post the same thread twice!
I have never seen a red question mark before a thread.... :) Are you by chance referring to the red breifcase icon? That just means that the topic is "popular" (ie, it has 14 or more replies in it)
Link to post
Share on other sites
and what does a red ? before a thread mean? I thought topic is closed (by you), but it seems it isn´t Therefore it´sn´t necessary for me indeed to post the same thread twice!
Two things:1. thescientist is not a moderator. He's just a frustrated forum member (like all of us).2.f_closed.gif - icon for topic that is closed.f_hot_no_dot.gif - icon for "hot" (in other words - "popular") topic in which you have posted.[edit]BTW, I think that'a "red folder", not a "red briefcase"[/edit]
Link to post
Share on other sites

There will also be a t_closed.gif image in place of the "add reply" button at the beginning and end of the thread when you are reading a closed thread.

Edited by boen_robot
And just for the record, ShadowMage is also not a moderator, and the topic is still open.
Link to post
Share on other sites
I don´t understand your first part (connection)! and what does a red ? before a thread mean? I thought topic is closed (by you), but it seems it isn´t Therefore it´sn´t necessary for me indeed to post the same thread twice!
Sigh... the point is that THIS thread is a repeat of OTHER threads you have made about this kind of topic, and some of those threads are duplicates or very very similar to OTHER topics you have made. (heck the titles are pretty much identical....) Which is why the moderators have closed some of your other threads. (with a red x next to it)What about "connection" don't you understand? I'm not sure what you mean. My code snippet was just a way to add feedback messaging to the create process, like JSG suggested, and what was also being done for the database creation. It was meant to tell you if the table was created or not. If you don't understand something, please provide specifics on the issue and the part you don't get. Edited by thescientist
Link to post
Share on other sites
I have never seen a red question mark before a thread.... :) Are you by chance referring to the red breifcase icon? That just means that the topic is "popular" (ie, it has 14 or more replies in it)
Thanks! (? or icon!)
Link to post
Share on other sites
Two things:1. thescientist is not a moderator. He's just a frustrated forum member (like all of us).2.f_closed.gif - icon for topic that is closed.f_hot_no_dot.gif - icon for "hot" (in other words - "popular") topic in which you have posted.
Ok, thanks!
Link to post
Share on other sites
There will also be a t_closed.gif image in place of the "add reply" button at the beginning and end of the thread when you are reading a closed thread.
Ok, thanks!
Link to post
Share on other sites

also, when you are in a subform (like the PHP forum) if you scroll down to the bottom of the page you will see legend for all the forums icon's and what they mean.

Edited by thescientist
Link to post
Share on other sites

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?

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...