Jump to content
eduard

Table?

Recommended Posts

what messages specifically do you see with that code? What do you think is not working?
Message: database connection initialized WITHOUT the code of: CREATING A TABLE!So, I think there must be an error in that code!

Share this post


Link to post
Share on other sites

Eduard, will you answer my last question?

Share this post


Link to post
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 answer is (few hours ago); I am now trying to create a table!):Database initializedTHE 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.)

Share this post


Link to post
Share on other sites

The problem is another time that I get different replies from different persons!My proposal is to stay with 1 person, preferably boen_robot to solve this problem!(of course if this is ok for him!)

Share this post


Link to post
Share on other sites
Message: database connection initialized WITHOUT the code of: CREATING A TABLE!So, I think there must be an error in that code!
you mean the one I've told you about repeatedly? I've mentioned at least twice about your mismatched curly braces in the table create section of the code.
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? {the table create code} Are you missing any semi-colons? Do all your curly braces and parenthesis match? Are you following the example as it is being shown?
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.
The problem is another time that I get different replies from different persons!My proposal is to stay with 1 person, preferably boen_robot to solve this problem!(of course if this is ok for him!)
We're all talking to you about the same code. There's no difference between what boen and I are referencing. It's all in the tutorials, and that's where your code is coming from. You just need to read and learn the code so you can try and figure out solutions to your problems. We've been going over the same few lines over and over again trying to get you to understand the most basic of concepts. It's not our advice that the problem, it's your comprehension. In all honesty, it's only gonna a get a lot more advanced from here on in. At the very least you need to be able to (try and) solve syntax problems on your own.But you can do whatever you want. Edited by thescientist

Share this post


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 eitherorDoes it? Try it!

Step 1(connection) and step 2(database) are ok! For step 3 (creating a table) I have to disappear step 2?, because I won´t manage to do step 3!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 e_l",$con)){echo "Database created";}else{echo "Error creating database: " .mysqlerror();} ?></body></html>Step 3:// 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(); } Edited by eduardchile

Share this post


Link to post
Share on other sites

I'm really having a hard time understanding what's so hard to understand. You ALWAYS need to establish a connection if you want to establish a connection with an (in this case) SQL server. (which you've got). If you need to make a database, include the code. Once it's been made, you don't need to keep making it. Like I've said a stupid amount of times, if you see the database in phpMyAdmin, then it's there, and there for good until you delete it. The same principle applies to making a table. Once you make it, it's there. As for your code, the curly brace mistake I pointed out is still there. Why don't you just look in the tutorials? IT'S RIGHT THERE. All you have to do is copy paste it, with the connect code.

<?php//establish mysql_connect$con = mysql_connect("localhost","root","root");if ($con){  echo 'database connection initialized....';}else{  die ('Could not connect: ' . mysql_error());};//select databasemysql_select_db("my_db", $con);//make table create query$sql = "CREATE TABLE Persons(FirstName varchar(15),LastName varchar(15),Age int)";// Execute querymysql_query($sql,$con);

and you can just add debugging statements by modifying the execute part like this:

// Execute queryif(mysql_query($sql,$con)){  echo 'success - table created';}else{  echo 'failure - table not created';};

Edited by thescientist

Share this post


Link to post
Share on other sites
The problem is another time that I get different replies from different persons!My proposal is to stay with 1 person, preferably boen_robot to solve this problem!(of course if this is ok for him!)
The thing is you don't answer my questions in the way you're supposed to, and others (thescientist in particular, though ShadowMage too) give you what I would've told you anyway AFTER you answer me. They're trying to give it all to you (the very answer you want from the start), whereas I'm trying to spoon feed you, because it's clear you don't get it.We're all talking about the same things. You can answer all of us, try multiple approaches. There is more than one "correct" way to do things.Now... for my question... I keep asking you for the OUTPUT. Not your code. The output. The thing you see in the browser when you run the code. "Step 1 is working" is not what I want you to tell me. I need you to tell me if whatever code I'm giving you gives whatever output I'm telling you it should have, and if not - what does it output?

Share this post


Link to post
Share on other sites
I'm really having a hard time understanding what's so hard to understand. You ALWAYS need to establish a connection if you want to establish a connection with an (in this case) SQL server. (which you've got). If you need to make a database, include the code. Once it's been made, you don't need to keep making it. Like I've said a stupid amount of times, if you see the database in phpMyAdmin, then it's there, and there for good until you delete it. The same principle applies to making a table. Once you make it, it's there. As for your code, the curly brace mistake I pointed out is still there. Why don't you just look in the tutorials? IT'S RIGHT THERE. All you have to do is copy paste it, with the connect code.
<?php//establish mysql_connect$con = mysql_connect("localhost","root","root");if ($con){  echo 'database connection initialized....';}else{  die ('Could not connect: ' . mysql_error());};//select databasemysql_select_db("my_db", $con);//make table create query$sql = "CREATE TABLE Persons(FirstName varchar(15),LastName varchar(15),Age int)";// Execute querymysql_query($sql,$con);

and you can just add debugging statements by modifying the execute part like this:

// Execute queryif(mysql_query($sql,$con)){  echo 'success - table created';}else{  echo 'failure - table not created';};

The curly brashes I changed immediately some hours ago, unfortunately without a positive result!

Share this post


Link to post
Share on other sites
The thing is you don't answer my questions in the way you're supposed to, and others (thescientist in particular, though ShadowMage too) give you what I would've told you anyway AFTER you answer me. They're trying to give it all to you (the very answer you want from the start), whereas I'm trying to spoon feed you, because it's clear you don't get it.We're all talking about the same things. You can answer all of us, try multiple approaches. There is more than one "correct" way to do things.Now... for my question... I keep asking you for the OUTPUT. Not your code. The output. The thing you see in the browser when you run the code. "Step 1 is working" is not what I want you to tell me. I need you to tell me if whatever code I'm giving you gives whatever output I'm telling you it should have, and if not - what does it output?
But connection initialized and database created (output) means ok, isn´t it?

Share this post


Link to post
Share on other sites
But connection initialized and database created (output) means ok, isn´t it?
Considering how many times you've assumed something to be working when it's not, I don't want to take any chances - the code either outputs something which you should tell us, or it doesn't. No ambiguities if you keep asnwering with the output.OK, so... what about this:
<?php//establish mysql_connect$con = mysql_connect("localhost","root","root");if ($con){  echo 'database connection initialized....';}else{  die ('Could not connect: ' . mysql_error());};//select databaseif (mysql_select_db("my_db", $con)) {  echo 'Database selected....';}else {  die ('Could not select database: ' . mysql_error());}?>

what does that output?

Share this post


Link to post
Share on other sites
Considering how many times you've assumed something to be working when it's not, I don't want to take any chances - the code either outputs something which you should tell us, or it doesn't. No ambiguities if you keep asnwering with the output.OK, so... what about this:
<?php//establish mysql_connect$con = mysql_connect("localhost","root","root");if ($con){  echo 'database connection initialized....';}else{  die ('Could not connect: ' . mysql_error());};//select databaseif (mysql_select_db("my_db", $con)) {  echo 'Database selected....';}else {  die ('Could not select database: ' . mysql_error());}?>

what does that output?

Output:database connection initialized Database selected

Share this post


Link to post
Share on other sites

OK. Then you're now ready to actually try and create the table.What does this output?

<?php//establish mysql_connect$con = mysql_connect("localhost","root","root");if ($con){  echo 'database connection initialized....';}else{  die('Could not connect: ' . mysql_error());};//select databaseif (mysql_select_db("my_db", $con)) {  echo 'Database selected....';}else {  die('Could not select database: ' . mysql_error());}//make table create query$sql = "CREATE TABLE Persons(FirstName varchar(15),LastName varchar(15),Age int)";// Execute queryif(mysql_query($sql,$con)){  echo 'Table created';}else{  die('Could not create table: ' . mysql_error());};?>

Share this post


Link to post
Share on other sites
OK. Then you're now ready to actually try and create the table.What does this output?
<?php//establish mysql_connect$con = mysql_connect("localhost","root","root");if ($con){  echo 'database connection initialized....';}else{  die('Could not connect: ' . mysql_error());};//select databaseif (mysql_select_db("my_db", $con)) {  echo 'Database selected....';}else {  die('Could not select database: ' . mysql_error());}//make table create query$sql = "CREATE TABLE Persons(FirstName varchar(15),LastName varchar(15),Age int)";// Execute queryif(mysql_query($sql,$con)){  echo 'Table created';}else{  die('Could not create table: ' . mysql_error());};?>

No output!:Code:<html><body><?php//establish mysql_connect$con = mysql_connect("localhost","root","root");if (!$con) { echo 'database connection initialized....'; }else { die ('Could not connect: ' . mysql_error()); };//select databaseif (mysql_select_db("my_db", $con)) { echo 'Database selected....'; }else { die ('Could not select database: ' . mysql_error()); } //make table create query$sql = "CREATE TABLE Persons { FirstName varchar (15), LastName varchar (15), Age int }";// Execute queryif (mysql_query($sql,$con)); { echo 'Table created'; }else {die('Could not create table: ' . mysql_error(); }; mysql_close($con); ?></body></html>

Share this post


Link to post
Share on other sites

You're supposed to copy & paste the code I'm giving you, not manually typing your code to be like it.Replace

die('Could not create table: ' . mysql_error();

with

die('Could not create table: ' . mysql_error());

as per my code.See what does that output.

Share this post


Link to post
Share on other sites
You're supposed to copy & paste the code I'm giving you, not manually typing your code to be like it.Replace
die('Could not create table: ' . mysql_error();

with

die('Could not create table: ' . mysql_error());

as per my code.See what does that output.

No output with the corrections I hand made!How do I simply copy and paste your code into my document?Code:<html><body><?php//establish mysql_connect$con = mysql_connect("localhost","root","root");if (!$con) { echo 'database connection initialized....'; }else { die ('Could not connect: ' . mysql_error()); };//select databaseif (mysql_select_db("my_db", $con)) { echo 'Database selected....'; }else { die ('Could not select database: ' . mysql_error()); } //make table create query$sql = "CREATE TABLE Persons { FirstName varchar (15), LastName varchar (15), Age int }";// Execute queryif (mysql_query($sql,$con)); { echo 'Table created'; }else {die('Could not create table: ' . mysql_error()); };?></body></html>

Share this post


Link to post
Share on other sites

Are you joking or something? You haven't copy & pasted anything?!?!1. Mark (a.k.a. highlight) the text. To do so - Move your mouse right before the start of the text you want to copy, hold down the left mouse button. While you're still holding it down, move your mouse to the point right after the text you want to copy. Release the left mouse button.2. You'll notice the text between the start and end of your mouse holding part has a different background now (blue perhaps). Click the right mouse button on some of that blue part.3. A menu appears next to your mouse's cursor. Select the button that says "Copy".4. Go to your text editor.5. Right click on the place at which you want the selected text to appear.6. A menu appears next to your mouse's cursor. Select the button that says "Paste".Make sure you learn how to do this. It's a skill any "power user" of computers must have.As for your error, replace

if (mysql_query($sql,$con));

with

if (mysql_query($sql,$con))

(no seriously... just look at the code I've given you...)

Share this post


Link to post
Share on other sites

The problem is that I have no output if I add the code (create a table) to my previous ones (connection initialized and selecting a database). So I think that the code of the 1 and 2 step must be different shall I have connection and see a table!Code:<html><body><?php//establish mysql_connect$con = mysql_connect("localhost","root","root");if ($con) { echo 'database connection initialized....'; }else { die ('Could not connect: ' . mysql_error()); };//select databaseif (mysql_select_db("my_db", $con)) { echo 'Database selected....'; }else { die ('Could not select database: ' . mysql_error()); } //make table create query $sql = "CREATE TABLE Persons (FirstName varchar(15),LastName varchar(15),Age int )"; // Execute queryif(mysql_query($sql,$con)) { echo 'Table created' }else { die('Could not create table: ' . mysql_error()); }; ?></body></html>

Share this post


Link to post
Share on other sites
Are you joking or something? You haven't copy & pasted anything?!?!1. Mark (a.k.a. highlight) the text. To do so - Move your mouse right before the start of the text you want to copy, hold down the left mouse button. While you're still holding it down, move your mouse to the point right after the text you want to copy. Release the left mouse button.2. You'll notice the text between the start and end of your mouse holding part has a different background now (blue perhaps). Click the right mouse button on some of that blue part.3. A menu appears next to your mouse's cursor. Select the button that says "Copy".4. Go to your text editor.5. Right click on the place at which you want the selected text to appear.6. A menu appears next to your mouse's cursor. Select the button that says "Paste".Make sure you learn how to do this. It's a skill any "power user" of computers must have.As for your error, replace
if (mysql_query($sql,$con));

with

if (mysql_query($sql,$con))

(no seriously... just look at the code I've given you...)

Of course I have copied and paste, but I only know the ´select all´function not the way you mentioned and for a Mac is almost always different from Windows!

Share this post


Link to post
Share on other sites

the highlight "trick" works the same both ways, actually.

Edited by thescientist

Share this post


Link to post
Share on other sites

Replace

die('Could not create table: ' . mysql_error()); };

with

die('Could not create table: ' . mysql_error()); }

(note the missing ";")[edit]Yes, and what thescientist said. Do that too.[/edit]

Share this post


Link to post
Share on other sites
The problem is that I have no output if I add the code (create a table) to my previous ones (connection initialized and selecting a database). So I think that the code of the 1 and 2 step must be different shall I have connection and see a table!Code:<html><body><?php//establish mysql_connect$con = mysql_connect("localhost","root","root");if ($con) { echo 'database connection initialized....'; }else { die ('Could not connect: ' . mysql_error()); };//select databaseif (mysql_select_db("my_db", $con)) { echo 'Database selected....'; }else { die ('Could not select database: ' . mysql_error()); } //make table create query $sql = "CREATE TABLE Persons (FirstName varchar(15),LastName varchar(15),Age int )"; // Execute queryif(mysql_query($sql,$con)) { echo 'Table created' }else { die('Could not create table: ' . mysql_error()); }; ?></body></html>
well, whether you're typing it or copy and pasting it, you're still getting it wrong..., somehow. You're missing a semicolon here:
echo 'Table created'

and as boen pointed out, here too:

//select databaseif (mysql_select_db("my_db", $con))	{	echo 'Database selected....';	}else	{	die ('Could not select database: ' . mysql_error());	}

Edited by thescientist

Share this post


Link to post
Share on other sites
well, whether you're typing it or copy and pasting it, you're still getting it wrong..., somehow. You're missing a semicolon here:
echo 'Table created'

and as boen pointed out, here too:

//select databaseif (mysql_select_db("my_db", $con))	{	echo 'Database selected....';	}else	{	die ('Could not select database: ' . mysql_error());	}

Ok, thanks for your comments!

Share this post


Link to post
Share on other sites

Ok, output: table created.But I want to see the table on my screen!

Share this post


Link to post
Share on other sites

That's what phpMyAdmin is for. Go to it from:

http://localhost:8888/phpmyadmin/

and type "root" as both username and password, same as with the mysql_connect() function.

Share this post


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