RE: Questions from a Newbie - Please Help

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


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



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux