Jump to content

[SOLVED] TWO WEEKS AND STILL NO ANSWER ON THIS ONE!!


Recommended Posts

in my application, i have one page that stores some data. and this form is supposed to retrieve.  for some reason this retreival form gets some records while it doesn't get other records.  i have no idea why this is.  when i go into phpMySQLAdmin, ALL the data is in there, but this code only retrieves some records.  i have played with all the commands i can think to play with(mysql_fetch_row,mysql_fetch_array, etc...) and nothing changes.  at my wits end...can anyone solve this puzzle?

 

<?php

session_start();

 

// get the variables from the login form

$sname = $_POST['sname'];

$pass  = $_POST['pass'];

 

mysql_connect($host,$user,$password);

mysql_select_db($dbname);

  $result = mysql_query("SELECT * FROM members

                  WHERE screenname = '$sname' ") or die(mysql_error()); 

  $row1 = mysql_fetch_row( $result );

  echo $row1['0']."<br>";

  echo $row1['1']."<br>";

  echo $row1['2']."<br>";

  echo $row1['3']."<br>";

  echo $row1['4']."<br>";

  echo $row1['5']."<br>";

 

Your not looping the data.

 

while($row1 = mysql_fetch_row( $result )) {
   echo $row1['0']."<br>";
   echo $row1['1']."<br>";
   echo $row1['2']."<br>";
   echo $row1['3']."<br>";
   echo $row1['4']."<br>";
   echo $row1['5']."<br>";
}

 

Should give you all the data that your query is setup to return (given that you limit it with the $_POST['sname']).

in my application, i have one page that stores some data. and this form is supposed to retrieve.  for some reason this retreival form gets some records while it doesn't get other records.  i have no idea why this is.  when i go into phpMySQLAdmin, ALL the data is in there, but this code only retrieves some records.  i have played with all the commands i can think to play with(mysql_fetch_row,mysql_fetch_array, etc...) and nothing changes.  at my wits end...can anyone solve this puzzle?

 

<?php

session_start();

 

// get the variables from the login form

$sname = $_POST['sname'];

$pass  = $_POST['pass'];

 

mysql_connect($host,$user,$password);

mysql_select_db($dbname);

   $result = mysql_query("SELECT * FROM members

                   WHERE screenname = '$sname' ") or die(mysql_error()); 

   $row1 = mysql_fetch_row( $result );

   echo $row1['0']."<br>";

   echo $row1['1']."<br>";

   echo $row1['2']."<br>";

   echo $row1['3']."<br>";

   echo $row1['4']."<br>";

   echo $row1['5']."<br>";

 

 

 

Hi, how is your loop structured?

 

 

thanks for your replies but at this point this is just testing...once i figure out why some records come and some don't a loop is not an issue.  this code, as is, does print some records...others it does not.  why would that be?

thanks for your replies but at this point this is just testing...once i figure out why some records come and some don't a loop is not an issue.  this code, as is, does print some records...others it does not.  why would that be?

 

I'm not familiar with PHPmyadmin since I don't use it, but I would assume that when you use that, it uses loops too in order to display your records which you say is coming out correctly..

 

So why not use loops to see if you can get the same results?

thanks for your replies but at this point this is just testing...once i figure out why some records come and some don't a loop is not an issue.  this code, as is, does print some records...others it does not.  why would that be?

 

Sorry, this just does not make sense to me. You are meaning to fetch one record. The code you have can sometimes fetch one record, given the sname or sometimes fetch a completely different record of the sname?

 

Do you have multiple records that have the sname? Maybe it is randomizing output, which it should not but is a possibility. There is nothing in your code that could be doing this? How are you testing the pulling of data with the query? There are a ton of unknowns and with us not knowing how experienced you are with php and mysql.

 

MySQL is not a guessing game, honestly. It returns what input you give it. Is this the full code you are executing? Can you print out the table data (if less than 10 rows) and print out one of the queries you can run in phpMyAdmin and what it returns? Then what does that same query return, using a loop, in your code....

 

There are a ton of scenarios here and yea. It is basically a needle in the haystack, however to find this needle you just need to provide us with a bit more detailed information.

 

EDIT:

Could it be directly related to the POST data not coming through? Are you checking if a form was submitted and not just assuming that data is there?

phpmyadmin is just a utility to look at the structure of the database, but as for the loop.  i have looped this data, i have done all kinds of things to this data.  i have had a while loop in there, i have used mysql_fetch_array,mysql_fetch_row,mysql_fetch_object i different configurations,but nothing changes.  the same records either are retrieved or not.

phpmyadmin is just a utility to look at the structure of the database, but as for the loop.  i have looped this data, i have done all kinds of things to this data.  i have had a while loop in there, i have used mysql_fetch_array,mysql_fetch_row,mysql_fetch_object i different configurations,but nothing changes.  the same records either are retrieved or not.

 

can you show us your table structure? And also, how may records do you have in it now?

 

And provide some sample output as well from your testing.....what you are getting and what you THINK you should get.....

thank you for your reply "premiso", but i have two questions for you...why would it randomize? what would make mysql randomize the retrieval of data? and second question is: other then randomizing, no matter what else my code is doing , why would it work on some data and not other data?  i assure you there is nothing special about the data.  just names. all the same length, no special characters or caps or anything.  and to answer one of your questions, i am not all that experienced but fairly well read, and this baffles me to no end.

It should not, it would be a glitch. However, if you have duplicate screennames in the DB, this may happen, especially if you do not have a primary key set on the table which is an id, or a unique value.

 

My bet is, the post data is causing the issue. Could be you need to trim it, or it is not posting when you think it is etc.

 

Try this as your page and see what happens:

 

<?php
session_start();

if (isset($_POST['sname'])) {
   // get the variables from the login form
   $sname = $_POST['sname'];
   $pass  = $_POST['pass'];

    mysql_connect($host,$user,$password);
    mysql_select_db($dbname);
   $result = mysql_query("SELECT * FROM members
                   WHERE screenname = '$sname' ") or die(mysql_error()); 
   
   while ($row1 = mysql_fetch_row( $result )) {
      echo $row1['0']."<br>";
      echo $row1['1']."<br>";
      echo $row1['2']."<br>";
      echo $row1['3']."<br>";
      echo $row1['4']."<br>";
      echo $row1['5']."<br><br>";
   }
}
?>

 

And just so you do realize that mysql randomizing data output is not normal, but given that I do not know how your tables are setup it is a possibility.  phpMyAdmin most likely sorts the data by an ORDER BY to prevent this randomization, but yea.

 

EDIT:

Major edit, had to remove the ! from the isset beginning as that was completely wrong.

Could it be directly related to the POST data not coming through? Are you checking if a form was submitted and not just assuming that data is there?

 

Adding to this, are you sure the query is the exact same every time?

$q = "SELECT * FROM members WHERE screenname = '$sname' ";
echo $q;
$result = mysql_query($q) or die(mysql_error());  
$row1 = mysql_fetch_row( $result );
// the following will output the data returned from the fetch_row - showing the key names, etc
echo '<pre>';
print_r($row1);
echo '</pre>';

I'm aware that you have data in there, but I'm more concerned about the query itself.

 

When you are getting different results, are your queries the exact same every time?

 

edit: sorry, I just realized that I put print_r in there. it's just habit to put in print_r when debugging mysql queries/results :D

thanks for your reply KingPhilip.  yes the data is definitely in there.  i can see it in phpmyadmin.  

 

No, he means the $_POST data. As that can change, are you sure it is being populated and the data coming into that is what you expect it. Maybe echo the $_POST['sname'] out on the page to make sure that contains what you expect it.

premiso, i have tried echoing the post data, the user name and password.  see this is not coming from other users yet so i know what is being sent as i am the one sending it.  and i tried the code you just gave me.  same results!! one thing you said is compeling though.  you said if i had duplicate data it might cause mysql glitch.  i am going to go thru and get rid of duplicates and see if that solves the problem.  please stay tuned :-)

nothing doing!! some data works and some doesn't.  i have no idea how this can be?

 

You might want to post the actual code your using (within


tags), the actual data your passing to the query and an example of the output.

 

ps: In the future, do not make your thread tittles all caps. Your question is no more important or urgent than anyone else's.

and it does only post one record.  but when i change the record i am asking for, some retrieve and some don't.  that is the question. if this test code will get one record, why wouldn't it get them all? the code doesn't change nor does the query.  only the result or lack there of.

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.