RE: [PHP] Questions from a Newbie - Please Help

2010-10-19 Thread Ethan Rosenberg

Dear List -

I've checked the php.ini file [again] and cannot find any errors.

I wrote a PHP script to open a non-existent data base, and receive no error.

At this point, I am out of options.

Let's all look at the code, and tell me 1]where the error is and 
2]any corrections or additions to the ini file.


For personal reasons, which I cannot explain in a public forum, I am 
under extreme pressure to learn PHP ASAP.


Thank you.

Ethan
+++

At 08:31 AM 10/19/2010, Tommy Pham wrote:

 -Original Message-
 From: Ethan Rosenberg [mailto:eth...@earthlink.net]
 Sent: Tuesday, October 19, 2010 12:05 AM
 To: php-general@lists.php.net
 Subject: Re: [PHP] Questions from a Newbie

 Tamara -

 Thanks.

 No error_log.


The error log only exists if he configures it properly and the script has
error.  IE: log_errors  error_log.  Like I said, Ethan should start from
the beginning of the manual.  It covers the configuration of PHP in addition
to the fundamentals of PHP.

 This works ...

 htmlbody
 ?php phpinfo(); ?
 /body/html

 Ethan
 ++
 At 02:23 AM 10/19/2010, Tamara Temple wrote:
 On Oct 18, 2010, at 11:01 PM, Ethan Rosenberg wrote:
 
 
 I've added the code you suggest, and I still get a blank screen.
 Should I be explicitly be using mysqli functions; eg mysqli_connect?
 Odd you should still get a blank screen and nothing in the error_log...
 
 Does phpinfo() work?
 
 Ethan
 
 At 11:00 PM 10/18/2010, you wrote:
 Where do you set $host, $user and $password?
 
 You should add the following after the new mysqli statement:
 
 if ($mysqli-connect_error) {
 die('Connect Error (' . $mysqli-connect_errno . ') '
 . $mysqli-connect_error); }
 
 Tamara Temple
 -- aka tamouse__
 mailto:tam...@tamaratemple.comtam...@tamaratemple.com
 
 
 May you never see a stranger's face in the mirror.
 
 On Oct 18, 2010, at 4:09 PM, Ethan Rosenberg wrote:
 
 At 05:37 PM 10/17/2010, Tamara Temple wrote:
 gah, i botched that up.
 
 For the first part, you want the following:
 
 $cxn = new mysql($host, $user, $password);
 $res = $cxn-query(create database test22:);
 if (!$res) {
 die(Failed to create database test22:  .
  $cxn- error());
 }
 
 Then, reopen the connection with the new data base:
 
 $cxn = new mysql($host, $user, $password, test22);
 
 Then the following code will work.
 
 
 Tamara Temple
 -- aka tamouse__
 mailto:tam...@tamaratemple.comtam...@tamaratemple.com
 
 
 May you never see a stranger's face in the mirror.
 
 On Oct 17, 2010, at 4:26 PM, Tamara Temple wrote:
 
 
 On Oct 17, 2010, at 1:22 PM, Ethan Rosenberg wrote:
 At 01:41 AM 10/17/2010, Tommy Pham wrote:
   I cannot get the following to work.  In my Firefox
   [Iceweasel]
 browser, I
   enter the following URL: [w/ the http]
 
 Whenever you get a blank screen running a php application, the
 place to look is the http server's error_log. This is frequently
 found in / var/log/httpd/error_log or /var/log/apache2/error_log.
 (If your system is hosted someplace else, it could very easily be
 in a different place). Typically you need root permission to read
 this file. Tail the file after you run your PHP script to see the
 most recent errors.
 
   The code  contained in the file CreateNew.php is:
  
   /*
 *  Create Database test22
 */
 htmlbody
   ?php
   $cxn = mysqli_connect($host,$user,$password);
 
 Better to use the OO approach:
 
 $cxn = new mysqli($host, $user, $password);
 
   echoCreate database test22;
 
 Instead of echo statements (which would just echo the contents to
 the output, i.e., your browser, you want to assign them to a
 variable, such as:
 
$sql = create database test22; use test22;
 
 Then you need to execute the sql statement:
 
 $res = $cxn-query($sql);
 if (!$res) {
 die(Could not create database test22:  .
  $cxn- error());
 }
 
   echoCreate table Names2
 
 $sql = create table Names2
 
   (
RecordNum Int(11) Primary Key Not null default=1
 auto_increment,
FirstName varchar(10),
LastName varchar(10),
Height  decimal(4,1),
Weight0 decimal(4,1),
BMI decimal(3,1)
Date0 date
   );
 
   ; // to close off the php statement
 $res = $cxn-query($sql);
 if (!$res) {
 die(Could not create table Names2:  . $cxn-
error());
 }
 
  
   echo   Create table Visit2
 
 $sql = 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)
   );
 
 ; // again, to close off the php statement
 $res = $cxn-query($sql);
 if (!$res) {
 die(Could not create table Visit2:  . $cxn-
error());
 }
 
  
$sql= SHOW DATABASES;
 
 This doesn't work in a programmatic 

RE: [PHP] Questions from a Newbie - Please Help

2010-10-19 Thread Steve Staples
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
  */
  htmlbody
?php
$cxn = mysqli_connect($host,$user,$password);
echoCreate database test22;
echoCreate table Names2
(
 RecordNum Int(11) Primary Key Not null default=1
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:

  htmlbody
?php
/*
  *  Create Database test22
  */
$cxn = mysqli_connect($host,$user,$password);
echoCreate database test22;
echoCreate table Names2
(
 RecordNum Int(11) Primary Key Not null default=1
auto_increment,
 FirstName varchar(10),
 LastName varchar(10),
 Height  decimal(4,1),
 Weight0 decimal(4,1),
 BMI decimal(3,1)
 Date0 date
);;

echoCreate 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:


  htmlbody
?php
/*
  *  Create Database test22
  */
$cxn = mysqli_connect($host,$user,$password);
echoCreate database test22;
mysqli_query($cxn, Create table Names2
(
 RecordNum Int(11) Primary Key Not null default=1
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



RE: [PHP] Questions from a Newbie - Please Help

2010-10-19 Thread Tommy Pham
 -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
   */
   htmlbody
 ?php
 $cxn = mysqli_connect($host,$user,$password);
 echoCreate database test22;
 echoCreate table Names2
 (
  RecordNum Int(11) Primary Key Not null default=1 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:
 
   htmlbody
 ?php
 /*
   *  Create Database test22
   */
 $cxn = mysqli_connect($host,$user,$password);
 echoCreate database test22;
 echoCreate table Names2
 (
  RecordNum Int(11) Primary Key Not null default=1 auto_increment,
  FirstName varchar(10),
  LastName varchar(10),
  Height  decimal(4,1),
  Weight0 decimal(4,1),
  BMI decimal(3,1)
  Date0 date
 );;
 
 echoCreate 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:
 
 
   htmlbody
 ?php
 /*
   *  Create Database test22
   */
 $cxn = mysqli_connect($host,$user,$password);
 echoCreate database test22;

The 2 statements below would fail ;)

 mysqli_query($cxn, Create table Names2
 (
  RecordNum Int(11) Primary Key Not null default=1 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



RE: [PHP] Questions from a Newbie - Please Help

2010-10-19 Thread Steve Staples
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
*/
htmlbody
  ?php
  $cxn = mysqli_connect($host,$user,$password);
  echoCreate database test22;
  echoCreate table Names2
  (
   RecordNum Int(11) Primary Key Not null default=1 
  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:
  
htmlbody
  ?php
  /*
*  Create Database test22
*/
  $cxn = mysqli_connect($host,$user,$password);
  echoCreate database test22;
  echoCreate table Names2
  (
   RecordNum Int(11) Primary Key Not null default=1 
  auto_increment,
   FirstName varchar(10),
   LastName varchar(10),
   Height  decimal(4,1),
   Weight0 decimal(4,1),
   BMI decimal(3,1)
   Date0 date
  );;
  
  echoCreate 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:
  
  
htmlbody
  ?php
  /*
*  Create Database test22
*/
  $cxn = mysqli_connect($host,$user,$password);
  echoCreate 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=1 
  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

RE: [PHP] Questions from a Newbie - Please Help

2010-10-19 Thread Tommy Pham
 -Original Message-
 From: Steve Staples [mailto:sstap...@mnsi.net]
 Sent: Tuesday, October 19, 2010 11:51 AM
 To: php-general
 Subject: RE: [PHP] Questions from a Newbie - Please Help
 
 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
 */
 htmlbody
   ?php
   $cxn = mysqli_connect($host,$user,$password);
   echoCreate database test22;
   echoCreate table Names2
   (
RecordNum Int(11) Primary Key Not null default=1
 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:
  
 htmlbody
   ?php
   /*
 *  Create Database test22
 */
   $cxn = mysqli_connect($host,$user,$password);
   echoCreate database test22;
   echoCreate table Names2
   (
RecordNum Int(11) Primary Key Not null default=1
 auto_increment,
FirstName varchar(10),
LastName varchar(10),
Height  decimal(4,1),
Weight0 decimal(4,1),
BMI decimal(3,1)
Date0 date
   );;
  
   echoCreate 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:
  
  
 htmlbody
   ?php
   /*
 *  Create Database test22
 */
   $cxn = mysqli_connect($host,$user,$password);
   echoCreate 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
 

I did point out MySQLi section in the manual but he said it was too much for 
him to comprehend.  And from the codes he provided, he lacked the basic 
knowledge of PHP.  Thus, he shouldn't even consider doing anything else, much 
less accessing the DB as there are more complications arise other than just PHP 
syntax error.

   mysqli_query($cxn, Create table Names2 (
RecordNum Int(11) Primary Key Not null default=1
 auto_increment,
FirstName varchar(10),
LastName varchar(10