Jump to content

Please Help


snan

Recommended Posts

Can you please tell me whats wrong with this code:

if($_POST){

$_SESSION['ID']=$_POST["ID"];

$_SESSION['pass']=$_POST["pass"];

}

$query=mysql_query("SELECT * FROM PHP_Customer WHERE Username='" . $_SESSION['ID'] . "'",$hold);

 

The connection is all set up correctly but everytime I try to run it I get this error:

 

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in ... on line 6

(with the ... replaced with the directory) Thank you.

Link to comment
Share on other sites

Thankyou, is the connection meant to be in that part of the query or is there just meant to be nothing there?

 

$hold should be pointing to a resource returned from mysql_connect.  If there was an error when establishing that connection, then $hold would hold a value of false, which isn't a valid MySQL connection.

Link to comment
Share on other sites

$dbHost = "localhost";		//Location Of Database usually its localhost
$dbUser = "xxxx";			//Database User Name
$dbPass = "xxxx";			//Database Password
$dbDatabase = "xxxx";	   //Database Name

$hold = mysql_connect("$dbHost", "$dbUser", "$dbPass") or die ("Error connecting to database.");
mysql_select_db("$dbDatabase", $hold) or die ("Couldn't select the database.");

session_start();
if($_POST){
$_SESSION['ID']=$_POST["ID"];
$_SESSION['pass']=$_POST["pass"];
}
$query=mysql_query("SELECT * FROM PHP_Customer WHERE Username='" . $_SESSION['ID'] . "'",$hold);

Link to comment
Share on other sites

The previous post has correct code, Although $_POST will never be undefined (try replacing

if($_POST) {

with

if(isset($_POST['ID']) && isset($_POST['pass'])) {

 

And most importantly, escape your data to prevent injection and bad issues down the road:

$_SESSION['ID'] = mysql_real_escape_string($_POST["ID"]);
$_SESSION['pass'] = mysql_real_escape_string($_POST["pass"]);

 

mysql_real_escape_string

Link to comment
Share on other sites

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.