fullyloaded Posted January 18, 2012 Share Posted January 18, 2012 hey anyone know how to fix the problem im having with my code? the first 10 lines of code is working great and doing what it should do but the rest of the code is not doing what i want it to do. what im trying to get it to do is select the packagelink from the database and go to that link thanks... <?PHP $username1 = @$HTTP_GET_VARS["username"]; $actnum1 = @$HTTP_GET_VARS["actnum"]; include("cfg.php"); $query = "Select * from ".$DBprefix."signup where username='$user_name1' And actnum='$actnum1'"; $result = mysql_query($query); if ($row = mysql_fetch_array($result)){ $query = "UPDATE ".$DBprefix."signup Set actnum = '0' where username='$username1'"; $result = mysql_query($query); $query = "Select * from ".$DBprefix."signup where username='$username1'"; $result = mysql_query($query); //CODE BELOW IS WHAT IM HAVING THE PROBLEM WITH// $result = mysql_query ("Select packages from ".$DBprefix."signup where username='$username1'"); $package = '$result'; $result2 = mysql_query("SELECT packagelink FROM packages WHERE packages ='$package'"); $link = '$result'; header("Location: '$link'"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/255255-errors-in-coding-need-help/ Share on other sites More sharing options...
freelance84 Posted January 18, 2012 Share Posted January 18, 2012 (if you put your code into is puts in syntax highlighting) [code=php:0] //CODE BELOW IS WHAT IM HAVING THE PROBLEM WITH// $result = mysql_query ("Select packages from ".$DBprefix."signup where username='$username1'"); $package = '$result'; //singles $result2 = mysql_query("SELECT packagelink FROM packages WHERE packages ='$package'"); $link = '$result'; //singles header("Location: '$link'");//singles [/code] Take package and link out of single quotations... the way you have written is $package is a string and so is $link... basically, don't put variables in single quotations.. If you want to use the content of the variable put them in doubles... but only if needed... you don't even need doubles in your script (you can place variables in singles if in a heredoc) Quote Link to comment https://forums.phpfreaks.com/topic/255255-errors-in-coding-need-help/#findComment-1308750 Share on other sites More sharing options...
AyKay47 Posted January 18, 2012 Share Posted January 18, 2012 (if you put your code into is puts in syntax highlighting) basically, don't put variables in single quotations.. If you want to use the content of the variable put them in doubles... but only if needed... you don't even need doubles in your script (you can place variables in singles if in a heredoc) [/quote] you need to encase a variable in single quotes in a mysql query if its value is a string, yes. [quote author=fullyloaded link=topic=352008.msg1662140#msg1662140 date=1326847758] hey anyone know how to fix the problem im having with my code? the first 10 lines of code is working great and doing what it should do but the rest of the code is not doing what i want it to do. what im trying to get it to do is select the packagelink from the database and go to that link thanks... [code]<?PHP $username1 = @$HTTP_GET_VARS["username"]; $actnum1 = @$HTTP_GET_VARS["actnum"]; include("cfg.php"); $query = "Select * from ".$DBprefix."signup where username='$user_name1' And actnum='$actnum1'"; $result = mysql_query($query); if ($row = mysql_fetch_array($result)){ $query = "UPDATE ".$DBprefix."signup Set actnum = '0' where username='$username1'"; $result = mysql_query($query); $query = "Select * from ".$DBprefix."signup where username='$username1'"; $result = mysql_query($query); //CODE BELOW IS WHAT IM HAVING THE PROBLEM WITH// $result = mysql_query ("Select packages from ".$DBprefix."signup where username='$username1'"); $package = '$result'; $result2 = mysql_query("SELECT packagelink FROM packages WHERE packages ='$package'"); $link = '$result'; header("Location: '$link'"); } ?>[/code] however, you do not want them in your header() code. header("Location: $link"); is what you want. 2. in the developmental stage of coding, you want to see all of the errors that are being reported, therefore avoid using the error suppression operator @. 3. $HTTP_GET_VARS is deprecated and should no long be used, use $_GET instead. A plus is that $_GET is a superglobal, while HTTP_GET_VARS is not. 4. it is always encouraged to debug your code thoroughly, echo your query statements and make sure that they are outputting what you expect. Make sure error_reporting is set to -1 and display_errors is set to "ON" or 1. 5. typically, you should store different query resources in different variables, to avoid confusion and simplify the debugging process. 6. mysql_query() returns a result resource, and cannot be used in a header() call and treated like a url. 7. perhaps you should look at these functions, which you will need for your logic. mysql_query, mysql_fetch_assoc, mysql_num_rows Quote Link to comment https://forums.phpfreaks.com/topic/255255-errors-in-coding-need-help/#findComment-1308753 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.