On Tue, 2010-10-19 at 11:18 -0700, Tommy Pham wrote:
> > -----Original Message-----
> > From: Steve Staples [mailto:sstap...@mnsi.net]
> > Sent: Tuesday, October 19, 2010 11:07 AM
> > To: Ethan Rosenberg
> > Cc: php-general@lists.php.net
> > Subject: RE: [PHP] Questions from a Newbie - Please Help
> > 
> > <thread has been trimmed to NOTHING>
> > 
> > i am pretty sure i read it on here already...  but your PHP code looks 
> > wrong.
> > 
> > 
> > ORIGNAL CODE:
> > /*
> >   *  Create Database test22
> >   */
> >   <html><body>
> > <?php
> > $cxn = mysqli_connect("$host",$user,$password);
> > echo    "Create database test22;"
> > echo    "Create table Names2
> > (
> >          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
> > );"
> > 
> > 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";
> > ?>
> > </body></html>
> > 
> > FIXED CODE:
> > 
> >   <html><body>
> > <?php
> > /*
> >   *  Create Database test22
> >   */
> > $cxn = mysqli_connect("$host",$user,$password);
> > echo    "Create database test22";
> > echo    "Create table Names2
> > (
> >          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
> > );";
> > 
> > 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";
> > ?>
> > </body></html>
> > 
> > END FIXX
> > 
> > firstly... you are missing your ending ; AFTER the " on most of your 
> > lines...
> > and i've seen this before, where it wont throw the error.
> > 
> > secondly, all this is doing, is echoing out lines to either the console, or 
> > the
> > web page... it is not running the queries at all.  So, if you're trying to 
> > execute
> > this from a shell script, then the line starting with $cxn that created the
> > connection to the database, is irrelevant.
> > 
> > If you are trying to just run from the website, and show what you WANT to
> > do, then you have to end your statements with the ; character.  You should
> > be able to copy and paste my "FIXED" code, and it should echo out
> > something... it is helps, before you make the $cnx call, put in
> > error_reporting(E_ALL);
> > 
> > lastly,  if you want to call the queries from php, then you will have to
> > remove the echo, and make them function calls to the database...
> > 
> > here is a VERY quick redo of your code to make the mysqli calls:
> > 
> > 
> >   <html><body>
> > <?php
> > /*
> >   *  Create Database test22
> >   */
> > $cxn = mysqli_connect("$host",$user,$password);
> > echo    "Create database test22";
> 
> The 2 statements below would fail ;)

ACUTALLY... the only reason they fail, is becuase i didn't realize that
I kept the other echo above, and it didn't create the database... that
should have been:
mysqli_query($cxn, "Create database test22");

and then inside, creating the table "Names2" needs to be "test22.Names2"
and the same for "visit2".

the other issue, is with the create Names2... where the primary key is
default=1000 (should be default 1000), and auto_increment... can't have
a default AND auto_increment.

other than those, this works fine...  providing he has the $user, $host,
$password declared as well.

I personally dont use this, i use the PEAR:MDB2 classes, so this was
just a quick php.net search... WHICH would have helped the OP on this
one.

http://ca.php.net/manual/en/mysqli.query.php

I hate to say it, since i was a noob once, but RTFM, or LRN2GOOGLE and
you will find it easier, and then once you can't understand it, ask.
but there was so much fail in the OP's code.  sorry.

I think the scary part, is that you're being forced to learn PHP to
develop in, and you can't figure out a simple echo statement?

Steve

> > mysqli_query($cxn, "Create table Names2
> > (
> >          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
> > );");
> > 
> > mysqli_query($cxn, "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";
> >     $result = mysqli_query($cxn, $sql);
> >     echo '<pre>';
> >     print_r($result);
> >     echo '</pre>';
> > ?>
> > </body></html>
> > 
> > 
> > GOOD LUCK!  and just to note, i dont guarantee that this code will work, i 
> > am
> > only taking what you had, and adding a little more to it, and I didn't test 
> > it
> > out...
> > 
> > 
> 
> 


-- 

Steve Staples
Web Application Developer
519.258.2333 x8414


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

Reply via email to