File download window when php script runs<

admin

Administrator
Staff member
Hi just installed postgres and am trying to setup a connection not to do anything in particular just to see how things work with postgres as opposed to mysql.

I have a html page with a button when the button is clicked it posts a user name to the Connect.php which should then connect to db and run query. What happens is that when the submit button is clicked a Download window appears the "Do you want to open this file or save to disk..."

connect.html
<html>
<head>
<Title>testlogin</Title>

</head>

<body >
<p> </p>
<p> </p>
<p> </p>
<form name="login" method ="post" action = "Connect.php" >
<div align="center">
<table width= "314" border="0" cellpadding="0" cellspacing="0">
<tr >
<td colspan="2"> <div align ="left"><font color="#000033" size="+1" face="Courier New, Courier, mono">Enter
UserId and Password</font></div></td>
</tr>
<tr >
<td width="104"> <div align="right"> <div align ="left"><font color="#000033" size="+1" face="Courier New, Courier, mono">User
ID:</font></div></td>
<td width="192"> <input maxlength="15" type="text" name="userID"> </td>
</tr>
<tr >
<td> <div align="left"> <font color="#000033" size="+1" face="Courier New, Courier, mono">Password:</font></div></td>
<td > </td>
</tr>
<tr >
<td colspan="2"> </td>
</tr>
<tr >
<td colspan="2"> <center>
<div align ="center"><font color="#000033" size="+1" face="Courier New, Courier, mono">
<input class="button" type ="submit" name="Submit" value="Submit">
</font> </div>
</center></td>
</tr>
</table>
</div>
</form>
</body>
</html>

Connect.php

<?php

$userID=$_POST["userID"];
$password=$_POST["password"];

if (empty($userID))
die("You haven't entered a userID");

$connection = @ pg_connect( "dbname=biblio host=localhost user=$userID ") or
die ("Couldn't connect to database");

session_start();
$_SESSION['userID']=$_POST['userID'];
$query = "SELECT * FROM title";
$result = pg_exec($db_handle, $query);
echo "Number of rows: " . pg_numrows($result);
pg_freeresult($result);
pg_close($db_handle);
//if (!empty($connection))
//header('location: query.php');
//die();
?>

Any help appreciated.

Bob1) I did not see a input field for "password"

2) I did not see the passworded added to the DB connect

3) Try to use single quote marks on the $_POST part

4) Last three lines of the Connect.php started with a comment line ( // )

5) Does your host allow for PHP? If your using it on
your own computer, do you have a sever with PHP setup?
If not, Download & install Apache and PHP.

As for the DB connect parts, no idea as I've never
used postgres before, and I barely can do mySQL :P

memo: Can a moderator please move this?3) Try to use single quote marks on the $_POST part

it doesn't matter if you do or not. makes no difference.

if you get a Download box when submitting to a php page then your server is not setup correctly.Thanks for the quick reply.
I have a small LAN with a Linux box that has Apache, Postgres, mysql and PHP installed. I can access the db's on the server no problem using DBTools and telnet also can access mysql database through a web interface.

The database I'm trying to connect to isn't passworded.
and the user was created without a password.

The last three lines are edited out so....?

If the server isn't setup right then how is it that I can access MySQL databases through Apache?can you run any php scripts?Yes Ihave a website on the LAN that is PHP driven.
It is through this that I access the MySQL Database (updates,inserts,deletes....)well, connecting to the db won't give you the Download box, so it has to be the php.

comment out all that stuff and see if you can actually post to the php page.Tried this

<?php
$connection = @ pg_connect( "dbname=biblio host=localhost user=$userID ") or
die ("Couldn't connect to database");
?>
But still got the file Download windowno, I said without the db connection. can you run this


<?php
phpinfo();
?>

add that into the connect.php script and submit the form. then if that works then make a change to the script you already have.

<?php
$connection = @pg_connect("dbname=biblio host=localhost user=$userID") or
die ("Couldn't connect to database");
?>

notice I took the spaces away that you hadThanks found the problem. When I defined the site in Dreamweaver I used a capital for first letter of the name in one place and not in another.
Sorry for wasting your time.

Bob
 
Back
Top