4 Replies - 1591 Views - Last Post: 07 August 2009 - 06:19 AM Rate Topic: -----

#1 Djanvk   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 80
  • Joined: 14-December 08

Echo command will not show.

Post icon  Posted 06 August 2009 - 10:41 PM

The following code runs and does everything fine EXCEPT display that last echo command.
What is the problem with that last echo command? If I remove everything except that last echo command it shows the echo command.

Thanks for the help.


<?php
include("dbinfo.inc.php");
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="CREATE TABLE contacts (id int(6) NOT NULL auto_increment,first varchar(15) NOT NULL,last varchar(15) NOT NULL,phone varchar(20) NOT NULL,mobile varchar(20) NOT NULL,fax varchar(20) NOT NULL,email varchar(30) NOT NULL,web varchar(30) NOT NULL,PRIMARY KEY (id),UNIQUE id (id),KEY id_2 (id))";
mysql_query($query);
mysql_close(); 
echo "Database created";
?>



Is This A Good Question/Topic? 0
  • +

Replies To: Echo command will not show.

#2 sf0145   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 03-June 09

Re: Echo command will not show.

Posted 06 August 2009 - 10:48 PM

You are missing quotes on localhost in the mysql_connect function. It is a string not a variable!

The syntax error would stop the rest of the script from executing. Hope that helps...

This post has been edited by sf0145: 06 August 2009 - 10:49 PM

Was This Post Helpful? 0
  • +
  • -

#3 Djanvk   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 80
  • Joined: 14-December 08

Re: Echo command will not show.

Posted 06 August 2009 - 11:09 PM

Still will not show "Database Created" ..

I added the quotes.
Was This Post Helpful? 0
  • +
  • -

#4 sf0145   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 03-June 09

Re: Echo command will not show.

Posted 07 August 2009 - 01:36 AM

You need to have

$cxn = @mysql_connect($server, $username, $password) or die(mysql_error());
@mysql_select_db($dbname, $cxn);

I missed that the first time!

This post has been edited by sf0145: 07 August 2009 - 01:37 AM

Was This Post Helpful? 0
  • +
  • -

#5 RPGonzo   User is offline

  • // Note to self: hmphh .... I forgot
  • member icon

Reputation: 151
  • View blog
  • Posts: 954
  • Joined: 16-March 09

Re: Echo command will not show.

Posted 07 August 2009 - 06:19 AM

View Postsf0145, on 7 Aug, 2009 - 03:36 AM, said:

You need to have

$cxn = @mysql_connect($server, $username, $password) or die(mysql_error());
@mysql_select_db($dbname, $cxn);

I missed that the first time!



The OP did say everything was working fine except the echo ... so adding the connection string into the select_db wont make a difference if that part is working already, also mysql_select_db does not require the link to be specified but if no link is found will throw a error, becasue he opened the link before hand it runs though ... although im curious as to why your using the @ symbol ( which ignores errors that that request throws )

i would reformat the way you do your echo though ....

<?php
include("dbinfo.inc.php");
mysql_connect("localhost",$username,$password) or die("ERROR CONNECTIONG : " . mysql_error());
mysql_select_db($database) or die( "Unable to select database, " . mysql_error());
$query="CREATE TABLE contacts (id int(6) NOT NULL auto_increment,first varchar(15) NOT NULL,last varchar(15) NOT NULL,phone varchar(20) NOT NULL,mobile varchar(20) NOT NULL,fax varchar(20) NOT NULL,email varchar(30) NOT NULL,web varchar(30) NOT NULL,PRIMARY KEY (id),UNIQUE id (id),KEY id_2 (id))";
if (mysql_query($query)) {
	echo "Database created";
} else {
	echo "Error occurred!<br/>";
	mysql_error();
}
mysql_close();
?>



that way that message fires ONLY if the mysql_query returns true else it echos a error and shows you the mysql error also added some debugging for the connect and db select functions
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1