On Sun, Oct 17, 2010 at 01:00:44AM -0400, Ethan Rosenberg wrote:

> Dear List -
> Here are some questions, which I am sure are trivial, but I am a
> newbie, and cannot find the answers online....
> I cannot get the following to work.  In my Firefox [Iceweasel]
> browser, I enter the following URL: [w/ the http]
>  localhost/CreateNew.php All I get is a blank browser screen.
> The code  contained in the file CreateNew.php is:
> /*
>  *  Create Database test22
>  */
>  <html><body>
> <?php
> $cxn = mysqli_connect("$host",$user,$password);
> echo    "Create database test22;"
> echo    "Create table Names2

There's no need to quote $host above. Why your echo statements aren't
showing up possibly indicates the script is aborting before it gets to

In situations like this, check the error logs if possible. If not, break
the problem down into even smaller chunks. Do your connect with MySQL
and then test to see if the connection actually worked. According to the
docs, mysqli_connect() should return an object representing the
connection. So check that first:

if (!is_object($cxn))
        echo "Not connected!";
        echo "Yep, it connected!";

> (
>         RecordNum Int(11) Primary Key Not null default=10000 auto_increment,
>         FirstName varchar(10),
>         LastName varchar(10),
>         Height  decimal(4,1),
>         Weight0 decimal(4,1),
>         BMI decimal(3,1)
>         Date0 date
> );"

As has been mentioned, you're simply echoing these to the page, not
sending them to MySQL. That won't work. You have to feed your SQL
statements to the mysqli_query() function. See the docs.

Also, let me strongly advise you against using upper-and-lower-case
field names in your tables. Others will undoubtedly disagree, but I find
this a maintenance nightmare in the long run. Note that in some SQL
variants (maybe in MySQL as well; I don't recall), you must quote the
field names in queries to preserve their case and make the queries work.

> echo"   Create table Visit2
> (
>         Indx Int(7) Primary Key Not null auto_increment,
>         Weight decimal(4,1) not null,
>         StudyDate date not null,
>         RecordNum Int(11)
> );"
>         $sql= "SHOW DATABASES";

As mentioned elsewhere, this statement won't work in a web context. It
only works from the MySQL console interface. There are other ways to
achieve this in a programming context, but they involve querying the
MySQL meta-tables. 

Also, to those recommending PHPMyAdmin, it ignores the OP's question,
and doesn't help him/her learn anything. It is completely possible to do
what he wants programmatically, and often is done that way while
installing various frameworks, etc. *You're* welcome to use PHPMyAdmin,
but let the OP do it his/her way, and help them along if you can.


Paul M. Foster

PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to