[PHP-DB] php4 + sqlite - quoting stuff

2004-12-25 Thread Peter Jay Salzman
Hi all,

I'm a kinda-sorta newbie to php -- I basically just futz around with it
because it's pretty cool.

However, I'm brand spanking new to databases.  Never did anything with them.
I taught myself a little SQL because it looked fun to learn, but I just
thumbed through some books.  I never really used a database in earnest.  Too
difficult to set up, and my dual Celeron 333 is underpowered as it is
without having an extra daemon running.

Yesterday, I taught myself sqlite + perl, and that was a LOT of fun.  But
then I remembered I hate using perl for CGI, so today I started messing
around with sqlite for php4.

There's something I'm not groking about php's syntax.  When I look at how
you're supposed to quote stuff in sqlite for php4:

sqlite_query( $handle, 
INSERT INTO course VALUES (
' . sqlite_escape_string($termcode). ',
' . sqlite_escape_string($semester). ',
' . sqlite_escape_string($course)  . ',
' . sqlite_escape_string($course_desc) . ',
' . sqlite_escape_string($college) . ',
' . sqlite_escape_string($reference)   . '
)
) or die(Error bravo in query:  .
sqlite_error_string(sqlite_last_error($handle)));

it makes me want to cry.  Php should be prettier than Perl, not uglier.  We
have single quotes, double quotes and a string quote function.

How am I supposed to parse this?  What's the purpose for all this quoting?

And is there a _nicer_ way of doing this?

Thanks!
Pete

PS- I don't want to count out the possibility that some of my values have
quote characters in them.

-- 
The mathematics of physics has become ever more abstract, rather than more
complicated.  The mind of God appears to be abstract but not complicated.
He also appears to like group theory.  --  Tony Zee's Fearful Symmetry

GPG Fingerprint: B9F1 6CF3 47C4 7CD8 D33E  70A9 A3B9 1945 67EA 951D

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



Re: [PHP-DB] how to connect new html page in PHP.

2004-12-25 Thread graeme
The following two scripts should help you...
in file Page1.php
?php
echo Hello this is the first page br\n;
echo This is in file Page1.phpbr\n;
echo form method=\POST\ action=\Page2.php\\n;
echo \tinput type=\submit\ name=\submit\ value=\Next Page\\n;
echo /form\n;
echo Note the input button must be wrapped in a form tagbr;
echo 'Also the name attribute is the variable name that will be held in 
the $_POST variable';
?

in file Page2.php
?php
echo We're now in Page2.phpbr\n;
echo 'The submit variable is held in the $_POST variablebr';
echo $_POST[submit];
echo brTo find out what has been POSTed use the var_dump functionbr\n;
echo pre\n;
var_dump($_POST);
echo /pre\n;
?
graeme
amol patil wrote:
hallo ,
i wrote this ,   echo Submit = $submit;as you said.
but comments in echo statements are appearing on same pages before clicking 
submit button
and in between same pages content .
i want these comment on new page or same page but without original content of 
that page
how to connect new html page in PHP after clicking submit button
let simple code is like this,
?php
echo --Submit= $submit--;
if ($submit)
   {
   $dbh=mysql_connect (localhost, root, ) or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db (dollar1_allinfo);  

   mysql_query(INSERT INTO totalinfo (username,password,) VALUES 
('$loginusername','$loginpassword',));
echo'thank you';
   echo' Hurry Up';
}  
?

THANK YOU.
Mike S. [EMAIL PROTECTED] wrote:
 

hallo ,
i have wriiten simple php script , below.
created databse dollar1_allinfo with table 'totalinfo'
but on clicking submit button ,
information entered is not entering in database.
also, echo statements are also not displaying after submit
   

if ($submit)
 

{
$db = mysql_connect(localhost,root);
mysql_select_db(dollar1_allinfo,$db);
mysql_query(INSERT INTO totalinfo (username,password,) VALUES
('$loginusername','$loginpassword'));
echo 'thank you';
echo 'So Hurry Up';
}
?
thank you.
   

Because your query and echoes are within an if block, I'd say that
$submit is evaluating to FALSE, and thus not executing the query and
echoes.
Add (before the if statement):
echo Submit = $submit;
Make sure that $submit is evaluating to TRUE.
To All Beginning Programmers (Newbies), or just people who want to
easily debug their code:
Try adding debugging statements to help you find problems. A few echoes
or prints in selected locations will help identify the issue. Make sure
your variables are evaluating to values that you think they should be.
If you want to keep the debugging statements in your code and just
activate them when you need to see them, do something like:
// near the top of your code
$debug=TRUE;
// and anywehere in your code
if ($debug) {
echo DEBUG: Submit = $submit
\n;
}
// or whatever echo might help you nail down the problem. Put as many of
these in your code and you can turm them ON and OFF very easily, by
changing one line of code.
OR for even quicker debugging, replace $debug=TRUE; with
$debug=$_GET['debug'];
and then you can turn it on in by adding ?debug=TRUE at the end of the
URL. Example: http://www.php.net/path/my.html?debug=TRUE
or: http://www.php.net/path/my.html?debug=1
**DISCLAIMER** Using the URL method is NOT a secure way to do this!!! 
And I'm sure there's plenty of folks groaning out there because it is a
BIG security hole. You really would want to do this on a development
machine and network, and remove the debug code for production. That
really should go without saying.

Good luck.
:Mike S.
:Austin TX USA


		
-
Do you Yahoo!?
Jazz up your holiday email with celebrity designs. Learn more.
 



Re: [PHP-DB] how to connect new html page in PHP.

2004-12-25 Thread Zareef Ahmed
Hi, 

 A simple example of the code. It send email and when it sends email
it does not display the original form.

Please note the use of isset() and submit button name use.

zareef ahmed 

?php
if(isset($_POST['sendmail']))
{
$to=$_POST['to'];
$sub=$_POST['sub'];
$message=$_POST['message'];

$header=from:[EMAIL PROTECTED] \n\r\n\r;


if(mail($to,$sub,$message,$header))
{
echo Mail successfully sent;
echo brbr a href='http://www.bankdrt.com/mail_test.php'Test Again/a;
}else
{
echo Mail function fail;
}


}
else
{
?

form method=post action=?php $_SERVER['PHP_SELF']; ?
To :: input type=text name=to size=30
br
Subject :: input type=text name=sub size=50
br
Message br
textarea name=message rows=8 cols=50

/textarea
brbr
input type=submit name=sendmail value=send
/form
brbr
?php
}
?



-- 
Zareef Ahmed :: A PHP Developer in India ( Delhi )
Homepage :: http://www.zareef.net

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



Re: [PHP-DB] how to connect new html page in PHP.

2004-12-25 Thread Zareef Ahmed
Please remove url bankdrt.com from example. it was included accidently.

zareef ahmed 


On Sat, 25 Dec 2004 14:02:58 +0530, Zareef Ahmed [EMAIL PROTECTED] wrote:
 Hi,
 
 A simple example of the code. It send email and when it sends email
 it does not display the original form.
 
 Please note the use of isset() and submit button name use.
 
 zareef ahmed
 
 ?php
 if(isset($_POST['sendmail']))
 {
 $to=$_POST['to'];
 $sub=$_POST['sub'];
 $message=$_POST['message'];
 
 $header=from:[EMAIL PROTECTED] \n\r\n\r;
 
 if(mail($to,$sub,$message,$header))
 {
 echo Mail successfully sent;
 echo brbr a href='http://www.bankdrt.com/mail_test.php'Test Again/a;
 }else
 {
 echo Mail function fail;
 }
 
 }
 else
 {
 ?
 
 form method=post action=?php $_SERVER['PHP_SELF']; ?
 To :: input type=text name=to size=30
 br
 Subject :: input type=text name=sub size=50
 br
 Message br
 textarea name=message rows=8 cols=50
 
 /textarea
 brbr
 input type=submit name=sendmail value=send
 /form
 brbr
 ?php
 }
 ?
 
 
 --
 Zareef Ahmed :: A PHP Developer in India ( Delhi )
 Homepage :: http://www.zareef.net
 


-- 
Zareef Ahmed :: A PHP Developer in India ( Delhi )
Homepage :: http://www.zareef.net

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



Re: [PHP-DB] how to connect new html page in PHP.

2004-12-25 Thread Jason Wong
On Saturday 25 December 2004 16:32, Zareef Ahmed wrote:

 $header=from:[EMAIL PROTECTED] \n\r\n\r;

The newlines should be \r\n and not \n\r.

-- 
Jason Wong - Gremlins Associates - www.gremlins.biz
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-db
--
/*
Time goes, you say?
Ah no!
Time stays, *we* go.
  -- Austin Dobson
*/

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



Re: [PHP-DB] php4 + sqlite - quoting stuff

2004-12-25 Thread Jason Wong
On Saturday 25 December 2004 16:15, Peter Jay Salzman wrote:

 There's something I'm not groking about php's syntax.  When I look at how
 you're supposed to quote stuff in sqlite for php4:

  sqlite_query( $handle, 
   INSERT INTO course VALUES (
' . sqlite_escape_string($termcode). ',
' . sqlite_escape_string($semester). ',
' . sqlite_escape_string($course)  . ',
' . sqlite_escape_string($course_desc) . ',
' . sqlite_escape_string($college) . ',
' . sqlite_escape_string($reference)   . '
   )
  ) or die(Error bravo in query:  .
   sqlite_error_string(sqlite_last_error($handle)));

 it makes me want to cry.  Php should be prettier than Perl, not uglier.  We
 have single quotes, double quotes and a string quote function.

Perhaps if you understood what that oneliner was doing then you would 
appreciate it that a similar statement in any language would look, similar.

 How am I supposed to parse this?

How do you mean? It's PHP's job to parse.

 What's the purpose for all this quoting? 

OK for the SQL statement you need to construct a string that looks something 
like:

  INSERT INTO course VALUES ('valueoftermcode', ...)

The significant part is that you have single-quotes inside that string. so to 
make things easier for yourself you use double-quotes as your string 
delimiter:

  INSERT INTO course VALUES ('valueoftermcode', ...)

Now you could have used single-quotes as your string delimiter but then you 
would have had to escape the single-quotes that appear inside your string so 
it would look something like this mess:

  'INSERT INTO course VALUES (\'valueoftermcode\', ...)'

 And is there a _nicer_ way of doing this?

Yes, don't do oneliners. Rewrite like so:

  $sql_termcode = sqlite_escape_string($termcode);
  $sql_semester = sqlite_escape_string($semester);
  ...

  $sql = INSERT INTO course VALUES ('$sql_termcode', '$sql_semester', ...);
  sqlite_query( $handle, $sql) or die(Error bravo in query [$sql]:  .
sqlite_error_string(sqlite_last_error($handle)));

-- 
Jason Wong - Gremlins Associates - www.gremlins.biz
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-db
--
/*
It's no use crying over spilt milk -- it only makes it salty for the cat.
*/

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



Re: [PHP-DB] how to connect new html page in PHP.

2004-12-25 Thread Jason Wong
On Saturday 25 December 2004 17:07, Zareef Ahmed wrote:
 On Sat, 25 Dec 2004 16:41:40 +0800, Jason Wong [EMAIL PROTECTED] wrote:
  On Saturday 25 December 2004 16:32, Zareef Ahmed wrote:
   $header=from:[EMAIL PROTECTED] \n\r\n\r;
 
  The newlines should be \r\n and not \n\r.

 Does it really make a diffrence?

Yes. Some of the security problems with Outlook stems from MS's strict 
non-compliance with the standards. And it takes just as much effort doing it 
incorrectly by using '\n\r' as it does doing it correctly using '\r\n' :)

Also if there is only a single header in $header then there is no need for 
'\r\n' at all. You only need it to separate multiple headers, and even then 
you should not use two sets of them, ie:

correct: \r\n
  incorrect: \r\n\r\n

-- 
Jason Wong - Gremlins Associates - www.gremlins.biz
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-db
--
/*
The solution to a problem changes the nature of the problem.
  -- Peer
*/

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



Re: [PHP-DB] how to connect new html page in PHP.

2004-12-25 Thread Zareef Ahmed
On Sat, 25 Dec 2004 17:27:18 +0800, Jason Wong [EMAIL PROTECTED] wrote:
 On Saturday 25 December 2004 17:07, Zareef Ahmed wrote:
  On Sat, 25 Dec 2004 16:41:40 +0800, Jason Wong [EMAIL PROTECTED] wrote:
   On Saturday 25 December 2004 16:32, Zareef Ahmed wrote:
$header=from:[EMAIL PROTECTED] \n\r\n\r;
  
   The newlines should be \r\n and not \n\r.
 
  Does it really make a diffrence?
 
 Yes. Some of the security problems with Outlook stems from MS's strict
 non-compliance with the standards. And it takes just as much effort doing it
 incorrectly by using '\n\r' as it does doing it correctly using '\r\n' :)
Thanks a lot for your information.
 
 Also if there is only a single header in $header then there is no need for
 '\r\n' at all. You only need it to separate multiple headers, and even then
 you should not use two sets of them, ie:
 
 correct: \r\n
   incorrect: \r\n\r\n
 
Sorry code was very old and for testing purpose only.  I just paste it
from my one of my old project for the example purpose only. I did not
check  it for such things (multiple headers, double use of \r\n etc.)
as main topic was use of isset and form submission. (Thats why it have
bankdrt.com as url , it belongs to  my previous employer ). Thanks
again for your information.

zareef ahmed
 --
 Jason Wong - Gremlins Associates - www.gremlins.biz
 Open Source Software Systems Integrators
 * Web Design  Hosting * Internet  Intranet Applications Development *
 --
 Search the list archives before you post
 http://marc.theaimsgroup.com/?l=php-db
 --
 /*
 The solution to a problem changes the nature of the problem.
   -- Peer
 */
 
 --
 PHP Database Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 


-- 
Zareef Ahmed :: A PHP Developer in India ( Delhi )
Homepage :: http://www.zareef.net

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



[PHP-DB] Filling Drop-Down Box.

2004-12-25 Thread Nayyar Ahmed
Hello All,

I want to fill drop-down box from mysql table, if any body
be kind to tell me a sample code :)
e.g:
In my application i want to gather subject list from current 
semester-subject table of a student. 

TIA
-- 
Nayyar Ahmad

Lecturer
Faculty Of Computer Science,
Institute Of Management Sciences,
Hayat Abad Peshawar , Pakistan.
Office : 92-091-9217404 , 9217452
Cell :  92-0333-9139461

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



RE: [PHP-DB] Filling Drop-Down Box.

2004-12-25 Thread Bastien Koert
i suggest you google for this...there are a million examples of this kind of 
code

bastien
From: Nayyar Ahmed [EMAIL PROTECTED]
Reply-To: Nayyar Ahmed [EMAIL PROTECTED]
To: php-db@lists.php.net
Subject: [PHP-DB] Filling Drop-Down Box.
Date: Sat, 25 Dec 2004 20:18:05 +0500
Hello All,
I want to fill drop-down box from mysql table, if any body
be kind to tell me a sample code :)
e.g:
In my application i want to gather subject list from current
semester-subject table of a student.
TIA
--
Nayyar Ahmad
Lecturer
Faculty Of Computer Science,
Institute Of Management Sciences,
Hayat Abad Peshawar , Pakistan.
Office : 92-091-9217404 , 9217452
Cell :  92-0333-9139461
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] Filling Drop-Down Box.

2004-12-25 Thread Mike S.
 Hello All,

 I want to fill drop-down box from mysql table, if any body
 be kind to tell me a sample code :)
 e.g:
 In my application i want to gather subject list from current
 semester-subject table of a student.

 TIA
 --
 Nayyar Ahmad

You know that the HTML code for the drop-down is:
SELECT NAME=SAMPLE
OPTION VALUE=1Whatever 1/OPTION
OPTION VALUE=2Whatever 2/OPTION
/SELECT

Here's some pseudo-code remarks that should help you with your coding:

- whatever.html -
Drop-down: SELECT NAME=sample
?php
   //  connect to your database - if you haven't already
   //  construct a query to pull the records you want, and
   //  in the order you want to display them
   //  execute the query
   //  loop through the results, building an OPTIONwhatever/OPTION
   //  for each element in the drop-down.  You can get creative
   //  here if you need to.  Like:
   //  OPTION VALUE=##whatever/OPTION
   //  where ## is the key field, and whatever is another
   //(descriptive) field in your query
   //  close your database connection (or later, if needed)
?/SELECT

Try to fill in the actual code yourself.
If you get stuck, you can look at:
http://www.netmask.com/php-db/sample-dropdown.html

Good luck!

:Mike S.
:Austin TX USA

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



[PHP-DB] [ Re: [PHP-DB] Filling Drop-Down Box.]

2004-12-25 Thread Alexandru Mihai
SELECT name=student title=Student list
  OPTION value=---/OPTION
?PHP
  while ($row = mysql_fetch_array($result)) {
?
  OPTION value=?php echo $row[3]? title=Select student ?php 
echo $row[1], , $row[2]? ?php echo $row[3]?/OPTION
?php
}
?
  /SELECT
In this case I've assumed that you'll have in mysql the following table:
row0: id (autoincrement)
row1: Nick name
row2: First name
row3: Last name

You can modify the code as you wish to get what you need.
Alexandru Mihai
Bastien Koert wrote:
i suggest you google for this...there are a million examples of this 
kind of code

bastien
From: Nayyar Ahmed [EMAIL PROTECTED]
Reply-To: Nayyar Ahmed [EMAIL PROTECTED]
To: php-db@lists.php.net
Subject: [PHP-DB] Filling Drop-Down Box.
Date: Sat, 25 Dec 2004 20:18:05 +0500
Hello All,
I want to fill drop-down box from mysql table, if any body
be kind to tell me a sample code :)
e.g:
In my application i want to gather subject list from current
semester-subject table of a student.
TIA
--
Nayyar Ahmad
Lecturer
Faculty Of Computer Science,
Institute Of Management Sciences,
Hayat Abad Peshawar , Pakistan.
Office : 92-091-9217404 , 9217452
Cell :  92-0333-9139461
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

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


[PHP-DB] what is wrong with my code.. please help

2004-12-25 Thread S Kumar
Dear group, 
 I am trying to query my db and print the results. 

when i execute my script, i am not getting any result
except a blank page. can any one please help me what
is going wrong with my script. 

Script:

$conn = pg_connect(user = $user dbname = $dbname host
= $host password = $pass);
if (!$conn)
{
echo('could not establish connection with
database br');
exit;
}
$sql = select * from experiment;
$sth = pg_exec($connect,$sql)
if (! $sth){
die(Can't execute query.pg_errormessage());
}

for($i = 0,$j = pg_numrows($sth);$i  $j;$i++){
$ar = pg_fetch_row($sth,$i);
foreach($ar as $col){
print $col ;
}
print \n;
}

?

thank you in advance

kumar

__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

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



Re: [PHP-DB] data is not entering in created database

2004-12-25 Thread amol patil
hallo,
this was working well , submit is evaluating true, no errors, but
now data is not shown in databse table 
 
?php
if($submit)
{

$dbh=mysql_connect (localhost, root) or die ('I cannot connect to the 
database because: ' . mysql_error());
mysql_select_db (dollar1_allinfo);  

mysql_query(INSERT INTO totalinfo (Username,Password) VALUES 
('$loginusername','$loginpassword'));
}
?
 
what may be glitch

  
  


graeme [EMAIL PROTECTED] wrote:
I suspect that your $submit is not set up, try the following echo 
statements before the if statement:

echo --$submit--;
echo --$_POST[submit]--;

amol patil wrote:

hallo ,
 
i have wriiten simple php script , below.
created databse dollar1_allinfo with table 'totalinfo'
 
but on clicking submit button , 
 
information entered is not entering in database.
 
also, echo statements are also not displaying after submit 
 
if ($submit)
 {
 $db = mysql_connect(localhost,root);
 mysql_select_db(dollar1_allinfo,$db);
 mysql_query(INSERT INTO totalinfo (username,password,) VALUES 
 ('$loginusername','$loginpassword'));

 echo 'thank you';
 echo 'So Hurry Up';
 }
 ?
 
 
 
 

thank you.


 
-
Do you Yahoo!?
 Yahoo! Mail - Easier than ever with enhanced search. Learn more.
 




__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com