Link to home
Create AccountLog in
Avatar of Ryan Bayne
Ryan BayneFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Using a PHP variable in an SQL query

The script I'm trying to get working is from another source which works fine but on changing it for the new purpose it does not work.

I wondered if it was possibly my use of php variable in the SQL as I do not recall ever doing this before. Can some tell me how this should be please thanks.


$SQL = mssql_query("SELECT username,email,createdate,fname,city 
					FROM users 
					WHERE username = '$myusername'");

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of Ryan Bayne

ASKER

Must be something else causing the problem then!

Problem being nothing shows on the page that has this query. The query is in  mypageprocess.php which is included in mypage.php. mypageprocess.php should make mypage.php show the current logged in users personel details user name etc.

Below is the mypageprocess.php

Any help will be great cant be something much just cant figure it out!
<?php
session_start();
$host="RRB\SQLEXPRESS"; // Host name
$username="ifolio"; // mssql username
$password="0505931"; // mssql password
$db_name="ifolio"; // Database name
 
// Connect to server and select databse.
mssql_connect("$host", "$username", "$password")or die("cannot connect");
mssql_select_db("$db_name")or die("cannot select DB");
 
$SQL = mssql_query("SELECT username,email,createdate,fname,city 
					FROM users 
					WHERE username = '$myusername'");
	
while($RS = mssql_fetch_array($SQL))
{
echo 'Username: '.$RS['username'].' ';
echo 'My E-mail: '.$RS['email'].' ';
echo 'Joined: '.$RS['createdate'].' ';
echo 'Name: '.$RS['fname'].' ';
echo 'Location: '.$RS['city'].' ';
}
?>

Open in new window

sorry cancel that I got it working thanks.
you never initialize the variable $myusername...

I guess this is the difference between older and newer versions of php, which eventually allows then to access the page parameters...

try adding a line like this in the beginning of your script:
$myusername = $_GET["myusername"];