Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

php5 and mysql 5

Status
Not open for further replies.
Apr 16, 2003
117
US
I am trying to setup a test page that will say if you can connect to the database.
I use an html for the form and the $_POST command for the variables to the php page
all seems to go ok except that it always says that I am connected.
If I hard code the php variables it works fine
[i am using the mysqli commands]
I am not sure if I am doing something wrong of if i should be using something besides $_POST
Any help would be great. Thanks.
 
without any code, to work off of, there is not a whole lot I can tell you maybe check how you're validating the connection.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
yeah i figured code would be needed but of course don;t have it on this compputer
this is my first attempt at php
This is the basics of it from what i rememebr

<?
$user = $_POST['user'];
$password = $_POST['password'];
$myCon = mysqli_connect ('localhost',$user,$password);
if (!$myCon)
{
printf("Connection Failed!!!");
end();
}
printf("Connection Successful");
mysqli_close($myCon);
?>
 
the problem is that you are using end() which is not the same as die(). end moves an array pointer whereas die kills the script. however since your code is a straightforward conditional it is better (imo) to use if ... else rather than if die.

i suggest trying out this slight modification to your code instead.

Code:
<?
$user = $_POST['user'];
$password = $_POST['password'];

$myCon = mysqli_connect ('localhost',$user,$password);

if (!$myCon) 
{ printf("Connection Failed!!!"); }
else
{ printf("Connection Successful");}
mysqli_close($myCon);
/*
//alternative code
if (!$myCon) { die("Connection Failed!!!"); }
printf("Connection Successful");
mysqli_close($myCon);
*/
?>
 
thanks
it still did not work for me.
i put this line in before the connection string to print out my variables
print "$db, $user, ,$password";

the result screen has just the "," and then conenction successful

this would then lead me to the fact that I am not passinf my variables properly correct?

Now that I know i need to work on my HTML form... why would it still stay conenction successful?
 
ok i think i figured out the form and of course that now give me an error when I want it too
I was missing this line in my form

enctype="application/x-
Like I said this was my first form.
Thanks
 
If there is nothing in the $_POST array it means it's not getting any values from the form.

How are you attempting to send the form? Better yet, can we see your Form code?
As an example,
a standard form would look something like this:

Code:
<form action=process.php method=POST>
<input type=text name='user' value=''>
<input type=text name='password' value=''>
<input type=submit name='sent' value='Submit Form'>
</form>

Now if you were to do check it in process.php.

$_POST['user'] and
$_POST['password'] should have the contents of the textboxes in them after the form is submitted.



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top