Jump to content

Include - what am i doing wrong?


Go to solution Solved by PaulRyan,

Recommended Posts

Hey guys,

 

Quick one for you.

 

I'm trying to use include for my db connection variables, but for some unknown reason, it wont have any of it. :(

 

so my file 'usersmysql.php' contains this...

 

$host="127.0.0.1";
$username="globaluser";
$password="d4TXz4ATHgcvqJx";
$db_name="project1";
$tbl_name="useraccounts";

and my main script is this...

 

<?php

include("usersmysql.php");

mysql_connect("$host", "$username", "$password")or die("There was a problem connecting to the database");
mysql_select_db("$db_name")or die("cannot select DB");

$myusername=$_POST['loginusr'];
$myplainpassword=$_POST['loginpwd'];
$mypassword=md5($myplainpassword);

$myusername = stripslashes($myusername);
$myusername = mysql_real_escape_string($myusername);

$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);

$count=mysql_num_rows($result);

if($count==1){

session_register("myusername");
session_register("mypassword");
header("location:userhome.php");
}
else {
//$interact = 'Invalid username and/or password';
$_SESSION['interact'] = $count;
header("location:login.php?response=1");
}
?>

But when i test this, all i get is a dead output...

 

$host="127.0.0.1"; // Host name $username="globaluser; // Mysql username $password="d4TXz4ATHgcvqJx"; // Mysql password $db_name="project1"; // Database name $tbl_name="useraccounts"; // Table name There was a problem connecting to the database

 

The variables listed in the output are correct, so it obviously reads the include file, but i cant see why its not actioning it correclty.

 

Any help appriciated!!

Edited by john.muckley
Link to comment
https://forums.phpfreaks.com/topic/276664-include-what-am-i-doing-wrong/
Share on other sites

ahhh so i did! infact, i edited the username and password as i was typing the post to be safe and deleted an extra character. it is there in the actual 'usersmysql.php' file.

 

I should also add that when i copy and paste the exact contents of the usersmysql.php into the main script and comment out the include, it works straight away.

Edited by john.muckley

 

In the "usersmysql.php" do you have the opening PHP tags? Like so:

 

<?PHP
 
  $host="127.0.0.1";
  $username="globaluser";
  $password="d4TXz4ATHgcvqJx";
  $db_name="project1";
  $tbl_name="useraccounts";

That was exactly the problem!!!! :)

 

Thanks for your help!!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.