Jump to content

Table?


eduard

Recommended Posts

  • Replies 165
  • Created
  • Last Reply

I can´t find the error!<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("products", $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>

Link to comment
Share on other sites

Are you saying you can't find the error_reporting and display_errors settings in php.ini?What happens when you run that code, what do you see in the browser?
No, not about that (MAMP)!In my code above!
Link to comment
Share on other sites

You don't need settings for error_reporting and display_errors in your code, those settings are inside php.ini and need to be set before you start trying to debug your code. Those settings set how errors get handled. Right now, they are probably being ignored or going to an error log. We're trying to get you to change the settings so that error messages get sent to the browser. Then when you run your code that has errors, you will see the error messages right in the browser. You need to make those changes to php.ini and restart the server before trying to debug your code.

Link to comment
Share on other sites

You don't need settings for error_reporting and display_errors in your code, those settings are inside php.ini and need to be set before you start trying to debug your code. Those settings set how errors get handled. Right now, they are probably being ignored or going to an error log. We're trying to get you to change the settings so that error messages get sent to the browser. Then when you run your code that has errors, you will see the error messages right in the browser. You need to make those changes to php.ini and restart the server before trying to debug your code.
That´s again the problem! I got this from boen_robot and it worked (connect and select)So by your reply I get again cconfused!
Link to comment
Share on other sites

If you cannot access or find the php.ini file you can try doing the following (emphasis on the cannot!):Create a new php file (name it something.php) with the exact following contents:

<?php  @ini_set('display_errors', 1);  @ini_set('error_reporting', E_ALL);  include 'yourfile.php';?>

Replace the yourfile.php with the name of the file your are trying to fix right now. Save everything and use something.php when you run want to run your php script that everyone has been helping you with.

Link to comment
Share on other sites

What´s wrong with this code? It doesn´t make sense to refer to the tutorial, because in the example they create a database and I´ve already created one (products) (p. s. this is a test!)<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("products", $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>

Link to comment
Share on other sites

did you fix the error reporting on? i think you should not skip the steps what all suggesting you already...enabling error reporting will show you the errors if your script has any problem. so if you do that first you dont have to be confused where your code is wrong. you can determine by yourself and determining the error will help others also to help you.so do that first. skipping step will not help and will make it more harder

Link to comment
Share on other sites

did you fix the error reporting on? i think you should not skip the steps what all suggesting you already...enabling error reporting will show you the errors if your script has any problem. so if you do that first you dont have to be confused where your code is wrong. you can determine by yourself and determining the error will help others also to help you.so do that first. skipping step will not help and will make it more harder
Ok, thanks!
Link to comment
Share on other sites

FIXED! However, I don´t understand it!Parse error: syntax error, unexpected T_LNUMBER in /Applications/MAMP/htdocs/test/cr t.php on line 61 <html>2 <body>3 4 <?php5 6 //establish mysql_connect7 $con = mysql_connect("localhost","root","root");8 if ($con)9 {10 echo 'database connection initialized....';11 }12 else13 {14 die('Could not connect: ' . mysql_error());15 };16 17 18 //select database19 if (mysql_select_db("products", $con))20 {21 echo 'Database selected....';22 }else {23 die('Could not select database: ' . mysql_error());24 };25 26 //make table create query27 $sql = "CREATE TABLE Persons28 (29 FirstName varchar(15)30 LastName varchar(15)31 Age int32 )";33 34 // Execute query35 if(mysql_query($sql,$con));36 {37 echo 'Table created';38 };39 else40 {41 die('Could not create table: ' . mysql_error());42 }43 44 ?>45 46 </body>47 </html>

Link to comment
Share on other sites

The error message says there's a number where it's not expecting one, but I don't see why. The only numbers in that code are in the SQL query. Line 6 is a comment. Remove all of the HTML tags, so that line 1 is the <?php line, and check it again.Wait.. those numbers you pasted on the left side, are those actually in the code or did you include those to show us the line numbers? The lines in the code should not start with a line number.

Link to comment
Share on other sites

The error message says there's a number where it's not expecting one, but I don't see why. The only numbers in that code are in the SQL query. Line 6 is a comment. Remove all of the HTML tags, so that line 1 is the <?php line, and check it again.Wait.. those numbers you pasted on the left side, are those actually in the code or did you include those to show us the line numbers? The lines in the code should not start with a line number.
The code (WITHOUT LINE NUMBERS!) is my code! The line numbers were only to show you the error message of the webserver (see above!!!) I don´t know how to start my line numbers at <?php!
Link to comment
Share on other sites

what do you mean? Just delete everything before <?php so it's the first line of the page, and delete everything after ?>

Link to comment
Share on other sites

what do you mean? Just delete everything before <?php so it's the first line of the page, and delete everything after ?>
Ok, but to test it I have to add <html> again?
Link to comment
Share on other sites

no. you don't. that doesn't matter. for testing, all we care about is the output of the PHP code. when you need to start implementing it within the context of a webpage, that's when you would want to add that. but for now, all we care about is the output of the code.

Link to comment
Share on other sites

Ok, but to test it I have to add <html> again?
No. You don't have to add <html> again. That's the point - remove them and test your code again.Must we really end our suggestions explicitly with "...and try it again after you follow these instructions."?
Link to comment
Share on other sites

No. You don't have to add <html> again. That's the point - remove them and test your code again.Must we really end our suggestions explicitly with "...and try it again after you follow these instructions."?
This is the error message of MAMP and I don´t understand it!Parse error: syntax error, unexpected T_ELSE in /Applications/MAMP/htdocs/test/cr t.php on line 36
Link to comment
Share on other sites

Basically that means that PHP is seeing an else keyword before it should be. Usually that means that the previous line is missing a semi-colon. Also, don't put semi-colons after a curly brace:

else {   die('Could not create table: ' . mysql_error());};//should be:else {   die('Could not create table: ' . mysql_error());}

Link to comment
Share on other sites

you have semicolons in end of else staement. remove them.

Link to comment
Share on other sites

That means there is an else statement on line 36 that it's not expecting. That usually means you're missing a semicolon at the end of a line before that. It could also indicate there's a problem with brackets.

Link to comment
Share on other sites

This doesn´t work!One says ´remove semi coloms´! The other says ´add them´!What should I do to create (finally) a table)?

Link to comment
Share on other sites

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

should be:

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

(quote slightly reformatted to show what he had in mind)
Link to comment
Share on other sites

Archived

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


×
×
  • Create New...