Jump to content

PHP script that doesn't work


thom6258

Recommended Posts

I am making a game for my website but is having trouble getting the below script to work. It should give me my gold status and my level status but no it just doesn't want to:

<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$colname_rsst = "-1";
if (isset($_SESSION['MM_Username'])) {
  $colname_rsst = $_SESSION['MM_Username'];
}
mysql_select_db($database_owngame, $owngame);
$query_rsst = sprintf("SELECT * FROM players WHERE username = %s ORDER BY username ASC", GetSQLValueString($colname_rsst, "text"));
$rsst = mysql_query($query_rsst, $owngame) or die(mysql_error());
$row_rsst = mysql_fetch_assoc($rsst);
$totalRows_rsst = mysql_num_rows($rsst);
?>

Link to comment
https://forums.phpfreaks.com/topic/160937-php-script-that-doesnt-work/
Share on other sites

How do you verify that it returns data?

if you meant the hole code here it is:

<?php require_once('Connections/owngame.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$colname_rsst = "-1";
if (isset($_SESSION['MM_Username'])) {
  $colname_rsst = $_SESSION['MM_Username'];
}
mysql_select_db($database_owngame, $owngame);
$query_rsst = sprintf("SELECT * FROM players WHERE username = %s", GetSQLValueString($colname_rsst, "text"));
$rsst = mysql_query($query_rsst, $owngame) or die(mysql_error());
$row_rsst = mysql_fetch_assoc($rsst);
$totalRows_rsst = mysql_num_rows($rsst);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Your Company</title>
<body>
<table width="94%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="22%"> </td>
    <td width="63%" align="center"><h3>ThomasThings.coms Own Company game</h3></td>
    <td width="22%">TOTAL GOLD: <?php echo $row_rsst['gold']; ?></td>
  </tr>
  <tr>
    <td> </td>
    <td align="center"><img src="Images/<?php echo $row_rsst['level']; ?>.gif" alt="You are level: <?php echo $row_rsst['level']; ?>" width="200" height="200"/></td>
    <td> </td>
  </tr>
  <tr>
    <td> </td>
    <td> </td>
    <td> </td>
  </tr>
</table>
</body>
</html>
<?php
mysql_free_result($rsst);
?>

I just got another problem when i try to give gold/money to my user the code lookes like this:

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
  $pay1 = $row_rsjob['payment'];
  $pay2 = $row_rsuser['gold'];
  $pay = $pay2 + $pay1;
  $updateSQL = sprintf("UPDATE players SET gold=%s WHERE id=%s",
                       GetSQLValueString($pay, "text"),
                       GetSQLValueString($_POST['id'], "int"));

  mysql_select_db($database_owngame, $owngame);
  $Result1 = mysql_query($updateSQL, $owngame) or die(mysql_error());

  $updateGoTo = "jobs.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $updateGoTo));
}

I have set everything up allright

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.