snan Posted March 18, 2010 Share Posted March 18, 2010 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. Quote Link to comment Share on other sites More sharing options...
jamesxg1 Posted March 18, 2010 Share Posted March 18, 2010 This is not the problem, the problem is the connection to your mysql. $hold Is where the error is. James. Quote Link to comment Share on other sites More sharing options...
snan Posted March 18, 2010 Author Share Posted March 18, 2010 Thankyou, is the connection meant to be in that part of the query or is there just meant to be nothing there? Quote Link to comment Share on other sites More sharing options...
fr34k Posted March 19, 2010 Share Posted March 19, 2010 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. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted March 19, 2010 Share Posted March 19, 2010 $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); Quote Link to comment Share on other sites More sharing options...
oni-kun Posted March 19, 2010 Share Posted March 19, 2010 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 Quote Link to comment Share on other sites More sharing options...
snan Posted March 22, 2010 Author Share Posted March 22, 2010 Thank you all for your help. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.