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
https://forums.phpfreaks.com/topic/195738-please-help/
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
https://forums.phpfreaks.com/topic/195738-please-help/#findComment-1028358
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
https://forums.phpfreaks.com/topic/195738-please-help/#findComment-1028423
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
https://forums.phpfreaks.com/topic/195738-please-help/#findComment-1028424
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.