Jump to content

Recommended Posts

How do I got about outputing one row that can only hold one value? Any reason why the function below doesn't work?

 

<?php
include "database.php";
session_start();
$name = $_session['outname'];

function output_wins(){
$sql = 'SELECT * FROM account_info WHERE username ="' . $name .'"';
$result = mysql_query($sql);
$wins = mysql_fetch_array($result);
echo $wins['win'];
}



output_wins();

?>

 

Is there an easier way I can output this one row?

Link to comment
https://forums.phpfreaks.com/topic/217956-output-a-row/
Share on other sites

Variables do NOT automatically pass to functions.

 

Try...

$name = $_session['outname'];
function output_wins($name){
  $sql = "SELECT * FROM account_info WHERE username = '$name'";
  $result = mysql_query($sql);
  $wins = mysql_fetch_array($result);
  return $wins['win'];
}
echo output_wins($name);

Link to comment
https://forums.phpfreaks.com/topic/217956-output-a-row/#findComment-1131193
Share on other sites

<?php
include "database.php";
session_start();

$name = $_session['outname'];
function output_wins($name){
  $sql = "SELECT * FROM account_info WHERE username = '$name'";
  $result = mysql_query($sql) or die(mysql_error());
  $wins = mysql_fetch_array($result);
  return $wins['win'];
}



?>

Link to comment
https://forums.phpfreaks.com/topic/217956-output-a-row/#findComment-1131231
Share on other sites

mysql_fetch_array(): supplied argument is not a valid MySQL result resource

 

on line 8, correct?

 

I guess we need to look at the sql. try this or something similar:

 

function output_wins($name){
  $sql = "SELECT * FROM account_info WHERE username = '$name'";

echo "sql: $sql <br />";
  $result = mysql_query($sql) or die(mysql_error());
echo "result: ".$result."<br />";
  $wins = mysql_fetch_array($result);
echo "after mysql_fetch_array <br />";
  return $wins['win'];
}

Link to comment
https://forums.phpfreaks.com/topic/217956-output-a-row/#findComment-1131234
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.