Jump to content

[SOLVED] Request Data


Ads

Recommended Posts

A simple example.

 

<?php

  $sql = "SELECT data FROM foo WHERE id = 1 LIMIT 1";
  if ($result = mysql_query($sql)) {
    if (mysql_num_rows($result)) {
      $row = mysql_fetch_assoc($result);
      echo $row['data'] . "<br />";
    } else {
      echo "No results found";
    }
  } else {
    echo "Query failed<br />" . mysql_error() . "<br />$sql";
  }

?>

Link to comment
Share on other sites

A simple example.

 

<?php

  $sql = "SELECT data FROM foo WHERE id = 1 LIMIT 1";
  if ($result = mysql_query($sql)) {
    if (mysql_num_rows($result)) {
      $row = mysql_fetch_assoc($result);
      echo $row['data'] . "<br />";
    } else {
      echo "No results found";
    }
  } else {
    echo "Query failed<br />" . mysql_error() . "<br />$sql";
  }

?>

 

Query failed

Unknown column 'data' in 'field list'

SELECT data FROM players WHERE id = 1 LIMIT 1

 

Thats the Error :(

 

  $sql = "SELECT data FROM players WHERE id = 1 LIMIT 1";
  if ($result = mysql_query($sql)) {
    if (mysql_num_rows($result)) {
      $row = mysql_fetch_assoc($result);
      echo $row['username'] . "<br />";
    } else {
      echo "No results found";
    }
  } else {
    echo "Query failed<br />" . mysql_error() . "<br />$sql";
  }

Link to comment
Share on other sites

You might want.....

 

<?php

  $sql = "SELECT username FROM players WHERE id = 1 LIMIT 1";
  if ($result = mysql_query($sql)) {
    if (mysql_num_rows($result)) {
      $row = mysql_fetch_assoc($result);
      echo $row['username'] . "<br />";
    } else {
      echo "No results found";
    }
  } else {
    echo "Query failed<br />" . mysql_error() . "<br />$sql";
  }

?>

Link to comment
Share on other sites

This is the New error i get:

Query failed

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

SELECT username FROM players WHERE email =

 

	$email = $_SESSION['email'];
  $sql = "SELECT username FROM players WHERE email = $email";
  if ($result = mysql_query($sql)) {
    if (mysql_num_rows($result)) {
      $row = mysql_fetch_assoc($result);
      echo $row['username'] . "<br />";
    } else {
      echo "No results found";
    }
  } else {
    echo "Query failed<br />" . mysql_error() . "<br />$sql";
  }

 

 

What i am trying to do is get the Persons Name to Be displayed By Finding there Email.

Link to comment
Share on other sites

Cool thanx, BUT, now it says That there are no results found? But there should be.

 

heres the code.

	$email = $_SESSION['email'];
$sql = "SELECT username FROM players WHERE email = '$email'";
  if ($result = mysql_query($sql)) {
    if (mysql_num_rows($result)) {
      $row = mysql_fetch_assoc($result);
      echo $row['username'] . "<br />";
    } else {
      echo "No results found";
    }
  } else {
    echo "Query failed<br />" . mysql_error() . "<br />$sql";
  }

Link to comment
Share on other sites

The results don't lie. Have you got a call to session_start() prior to using the $_SESSION array? Also, try trimming the email of any extra whitespace.

 

<?php

  session_start();
  $email = trim($_SESSION['email']);
  $sql = "SELECT username FROM players WHERE email = '$email'";
  if ($result = mysql_query($sql)) {
    if (mysql_num_rows($result)) {
      $row = mysql_fetch_assoc($result);
      echo $row['username'] . "<br />";
    } else {
      echo "No results found";
    }
  } else {
    echo "Query failed<br />" . mysql_error() . "<br />$sql";
  }

?>

Link to comment
Share on other sites

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.