Jump to content

MarkT

Members
  • Posts

    168
  • Joined

  • Last visited

Posts posted by MarkT

  1. My $_SESSION['id'] returns null.These are where it sets the Session variable; $id = mysql_query("SELECT * FROM `users` WHERE `name` = '{$name}' AND `email` = '{$email}'");$ida = mysql_fetch_assoc($id); $_SESSION['id'] = $ida['id2'];

  2. Then it's not returning a record. Print the query to see what you're telling the database to do.
    No records returned.Resource id #26is what it says, when I print the query ($pass)
  3. I suggest you look at the documentation on php.net for the functions you're trying to use. There are plenty of explanations and examples. You might also want to get some books, I would recommend oreilly.com as a publisher. If you don't understand what you're doing then looking at some code isn't going to change that, but here it is:
    $pass=mysql_query("SELECT password FROM users WHERE username='$user'");$pass2=mysql_fetch_assoc($pass);if ($pass2) {  echo "Password:" . $pass2['password'] ;}else {  echo 'No records returned.';}

    I've tried that, But i know there's a record, but it's still showing "No Records Returned"
  4. $pass is a resource returned from mysql_query. $pass2 is an array representing the first row returned from the query, or false if it didn't return any rows. If the query returned at least one row then the array will have an element called password that contains the value from the database.
    Dont get it, Can you write the code I should have?
  5. Hello,I currently have the following code;$user=$_GET['user']; $pass=mysql_query("SELECT password FROM users WHERE username='$user'"); $pass2=mysql_fetch_assoc($pass); echo "Password:" . $pass ; but it's only saying; Password:Resource id #26

  6. If the session ID is null then it sounds like you did not print out the query to verify it. That's why I said you should never assume anything, always verify.
    Maybe you need to verify the values of $name and $email? Are you extracting them from $_POST, maybe? Could that be a problem?
    What should I do now then?
  7. Hello,I recently saw a lot of malicious spam flooding on the forums, was this a malicious attack? i'm just wondering why they did it, and how they got round the spam prevention features?

    • Like 1
  8. Try temporarily dumping more data. echo var_dump($_SESSION) . '<br>';$id= $_SESSION['id'];echo var_dump($id) . '<br>';$id2 = mysql_query("SELECT * from friends WHERE id1 = '{$id}'");echo var_dump($id2) . '<br>';$eid = mysql_fetch_assoc($id2);echo var_dump($eid);
    array(4) { ["id"]=> NULL Tried that and thats what I got ^^I think it's not saving the ID of the session in the below code;$id = mysql_query("SELECT * FROM `users` WHERE `name` = '{$name}' AND `email` = '{$email}'");$ida = mysql_fetch_assoc($id);$_SESSION['id'] = $ida['id2'];
  9. No, there's no reason why a given query would return one set of results in one script and a different set in another script, that's not how databases work. It's going to return exactly what you tell it to return. If it's not returning anything, then there's nothing to return. If there was something to return then it wouldn't skip it. If you're telling me that you print the query that you're running in PHP, and you run that exact same query in phpMyAdmin, and it returns results there, then it's going to return the same results in PHP. Something's missing, but I don't know what it is. The code that you've shown looks fine to me. Maybe you're assuming incorrect things about what is in the session or something like that, but if you say that you used PHP to print out the query that you are actually running, and that query returns results in phpMyAdmin, then the query is not the problem. If you didn't actually print the query from PHP, but just assumed you knew what it was going to be, then that's not going to help you debug the problem. Don't assume that you know what anything is, always verify.
    If you think of anything I could do! Let me know!!!!!
  10. 201306131440.jpg im having trouble with indentation, as you can see in the picture,i already tried with margin, padding,  , but still had a left indentationhere css code that had relation with the problem
    .container{width: 960px;background: #CCC;margin: 0 auto;overflow: hidden;}  .sidebar1{float: left;width: 180px;background: #CCC;padding-bottom: 0;font-family: Verdana, Arial, Helvetica, sans-serif;}/*This is the "Archive: " word in stylin */  /*all below is belong to Home, About, and Sign-In anchor thats no relation on this problem */ ul.nav{list-style: none;margin-bottom: 15px;} ul.nav li{/* i didnt inserting this, nothing changed though*/} ul.nav a, ul.nav a:visited{padding: 7px 5px 7px 15px;display: block;width: 160px;text-decoration: none;background: rgb(41, 41, 41);;}

    Try this;padding-left: 10px; then post what happens
  11. My host is godaddy, and i found it, however changing the height in the code below, doesn't do anything, not even after i published the website. Even if i delete the height entirely then publish it, nothing happens, any ideas? When i submitted a ticket, i was told they couldn't provide help with advanced coding? .sf_header_wrapper {background-image:url(http://i.imgur.com/0QBv29V.png);background-position:top;background-repeat:no-repeat;background-size: 100%;border:solid 10px #fff; height:377px }
    You want to make the header appear lower down the page?Do a margin-top: 10px;in the main header div that encloses everything in the header
  12. Look at the examples here, they call the error function if the query fails: http://www.php.net/m...mysql-query.php
    $id= $_SESSION['id'];$id2 = mysql_query("SELECT * from friends WHERE id1 = '{$id}'");$eid = mysql_fetch_assoc($id2);if (!$id2) { die('Invalid query: ' . mysql_error());}echo "ID: " . $eid['id2'] ; is my current code;It's not displaying any errors, but it's also not displaying "2" because |I have a record where ID 1 = 1 (My session['id']) and ID2 = 2
  13. That means your query had an error, you need to check for errors from MySQL like Dad showed. If a query has an error then it will return boolean false instead of a resource, so that's why the error message says it was expecting a resource but got a boolean. After you run the query you need to check if it succeeded before you go on.
    $id= $_SESSION['id'];$id2 = mysql_query("SELECT * from Friends WHERE id1 = '$id'"); Is my query, but i dont see any problems with it?
  14. You shouldn't need the '{ }' characters. They are generally used to disambiguate arrays. And add a semicolon to the end of line 2. Other than that, it looks OK. You should probably switch to the mysqli functions. The mysql functions are deprecated and will eventually disappear. You should also add some error handling. The example here shows ways to do that.
    On another page i have this code;
    $id= $_SESSION['id'];$id2 = mysql_query("SELECT * from Friends WHERE id1 = '{$id}'");$eid = mysql_fetch_assoc($id2);echo  "ID: " . $eid['id2'] ;?>

    But the echo isn't echo'ing what it should be, at the moment there is a entry where id1=1, which is the ID i'm logged in as which should be set in $_SESSION['id']and ID2 = 2, so it should echo 2, however it's not. It's saying;Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in /home/u872116037/public_html/home.html on line 66 ID:

  15. I have edited it to this, is it right?

    $id = mysql_query("SELECT * FROM `users` WHERE `name` = '{$name}' AND `email` = '{$email}'");  $ida = mysql_fetch_assoc({$id})$_SESSION['id'] = $ida['id2'];

  16. $id = mysql_query("SELECT * FROM `users` WHERE `name` = '{$name}' AND `email` = '{$email}'");$_SESSION['id'] = . $id["id"];

    For starters, this won't work. As justsomeguy explained, $id is not an array. It's a resource. You pass it to mysql_fetch_assoc(), and the return value is an array. Same problem below:

    $id2 = mysql_query("SELECT * from Friends WHERE id1 = '{$id}'");$eid = mysql_fetch_assoc("{$id2['id2']}");

    Pass $id2 to mysql_fetch_assoc(). $eid will then be an array. I don't know the structure of your table, but it looks like the value you want will be returned in $eid['id2']

    Can you please edit my code to show me?
  17. $id2 isn't a record from the database, it's the entire result set. You need to use another function to get a record from the result, like mysql_fetch_assoc if you're using the old mysql extension.
    I now have;
    $id = mysql_query("SELECT * FROM `users` WHERE `name` = '{$name}' AND `email` = '{$email}'");$_SESSION['id'] = . $id["id"];on the login page ^^^ On the page where i want to use the ID:$id= $_SESSION['id'];$id2 = mysql_query("SELECT * from Friends WHERE id1 = '{$id}'");$eid = mysql_fetch_assoc("{$id2['id2']}");echo  "ID: " . $_SESSION['id'] ;

    But it's not picking up $_SESSION['id']

  18. Remove the quotes around Friends and id1, identifiers are not supposed to be quoted. You only quote a text value.
    Still not working,It should at the moment, echo "2", because thats the only record in the database,.
×
×
  • Create New...