PostgreSQL / PHP problem 
Author Message
 PostgreSQL / PHP problem

I've been mulling over this all week.  From all the documentation I
read, this *should* work, but the pgsql database doesn't get updated
with the entered data.  Here's the PHP doc.  I should also note I don't
get any error msgs, either.

Thanks.

-----

<?php

$firstname = $_POST['firstname'] ;
$lastname = $_POST['lastname'] ;
$city  = $_POST['city'] ;
$state  = $_POST['state'] ;
$age  = $_POST['age'] ;

$tried  = ($_POST['tried'] == "yes") ;

if ($tried) {
 $validated = (!empty($firstname) &&
  !empty($lastname) &&
  !empty($city) &&
  !empty($state) &&
  !empty($age) &&
  is_int($age)) ;

 if ($validated) {

 echo("Please enter values for first name, last name, city, state and
age. \n") ;

 }

 if (!is_int($age)) {

 echo("Please enter a numerical value for age. \n") ;

 }

Quote:
}

if ($tried && $validated) {
 // success, post to database
 require_once('DB.php') ;
 $db = pg_Connect("host=192.168.0.1 port=5432 dbname=test user=andrew
password=tmp888x") ;
 if (!$db) {
  echo "Database connection failed, suck-o." ;
  exit ;
 }

 $sql = "INSERT INTO test (lastname, firstname, city, state, age)
  VALUES ('$lastname', '$firstname', '$city', '$state', $age)
  ";

 $q = pg_Exec($db, $sql) ;
 if (!$q) {
  die("Cannot insert into database, suck-o.") ;
 }

Quote:
}

?>

<HTML>
<HEAD>
 <TITLE>Database Entry Form 1</TITLE>
 <META NAME="GENERATOR" CONTENT="WebDesigner/0.1.6">
 <META NAME="Keywords" CONTENT="alpha database entry">

</HEAD>

<BODY>
<FORM action="<?= $PHP_SELF ?>" method="POST">

What is your first name?<br>
<INPUT TYPE="text" NAME="firstname" VALUE="<?= $firstname ?>" /><BR>
<BR>

What is your last name?<br>
<INPUT TYPE="text" NAME="lastname" VALUE="<?= $lastname ?>" /><BR>
<BR>

What city do you live in?<br>
<INPUT TYPE="text" NAME="city" VALUE="<?= $city ?>" /><BR>
<BR>

What state?<br>
<INPUT TYPE="text" NAME="state" VALUE="<?= $state ?>" /><BR>
<BR>

What is your age?<br>
<INPUT TYPE="text" NAME="age" VALUE="<?= $age ?>" /><BR>
<BR>

<input type="hidden" name="tried" value="yes" />
<INPUT TYPE="reset" VALUE="No good"><INPUT TYPE="submit" VALUE="
 <?php echo $tried ? "Try again" : "Yep, do it" ?>" />

</FORM>

</BODY>
</HTML>



Wed, 12 Jan 2005 06:47:37 GMT  
 PostgreSQL / PHP problem
I don't see any obvious error, but it might be useful to build up the
SQL query in PHP and then print it out to the screen.  Then take that
and copy it into psql (or whatever you use to connect directly to
postgres) and see if it spits out any errors.

It might turn something up...

good luck.

-philip



Quote:
>I've been mulling over this all week.  From all the documentation I
>read, this *should* work, but the pgsql database doesn't get updated
>with the entered data.  Here's the PHP doc.  I should also note I don't
>get any error msgs, either.

[code snipped]


Wed, 12 Jan 2005 07:20:27 GMT  
 PostgreSQL / PHP problem

Quote:

> $firstname = $_POST['firstname'] ;
> $lastname = $_POST['lastname'] ;
> $city  = $_POST['city'] ;
> $state  = $_POST['state'] ;
> $age  = $_POST['age'] ;

No need for this.

OK, register globals is switched off with good reason, but if you want
to make exceptions...

import-request-variables("p");
http://www.php.net/import-request-variables

Note that ini_set() will not work on register globals.



Sun, 16 Jan 2005 15:19:58 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. PHP+MySQL vs. PHP+PostgreSQL

2. php + mysql or php + postgresql?

3. PHP + Apache + PostgreSQL + Cygwin + Windows?

4. getingt php to work with postgresql on windows

5. TCL/PHP problem involving a PHP function that has to utilize a TCL proc

6. Store and PostgreSQL installDatabaseTables problem

7. PostgreSQL install dependency problem

8. PostgreSQL problems

9. Update template (ABC) with PostgreSQL (insert record using serial problem)

10. Inheritance problem with PostgreSQL ext ension

11. Inheritance problem with PostgreSQL extension

12. Pygresql / Postgresql Problem

 

 
Powered by phpBB® Forum Software