Jump to content

Recommended Posts

I really have no idea where I went wrong on this, but after I got all my variables set and added I tried to echo them on the page and they won't show up and I don't know why, so please help.

 

Here's the page.

<?php session_start(); ?>
<?php

if($_SESSION['user']){

include_once('connect.php');

$session = $_SESSION['user'];

$w = $_GET['w'];

$find = "SELECT * FROM weapon_shop WHERE id = '$w'";
$run = mysql_fetch_array(mysql_query($find)) or die (mysql_error());

$weapon_id = $run['id'];
$weapon_name = $run['Weapon_Name'];
$weapon_image = $run['Weapon_Image'];
$weapon_level = $run['Weapon_Level'];
$weapon_cost = $run['Weapon_Cost'];
$weapon_sell_value = $run['Weapon_Sell_Value'];
$weapon_attack = $run['Weapon_Attack'];
$weapon_defense = $run['Weapon_Defense'];
$weapon_strength = $run['Weapon_Stength'];
$weapon_speed = $run['Weapon_Speed'];
$weapon_accuracy = $run['Weapon_Accuracy'];
$weapon_range = $run['Weapon_Range'];

$find_stats = "SELECT * FROM stats WHERE Username = '$session'";
$stats = mysql_fetch_array(mysql_query($find_stats)) or die (mysql_error());

$player_HBS = $stats['HBS'];
$player_Credits = $stats['Current_Credits'];
$player_attack = $stats['Attack'];
$player_defense = $stats['Defense'];
$player_strength = $stats['Strength'];
$player_speed = $stats['Speed'];
$player_accuracy = $stats['Accuracy'];
$player_range = $stats['Range'];

$find_duplicate = "SELECT Weapon_Name FROM weapons WHERE Weapon_Name = '$weapon_name'";
$dup = mysql_fetch_array(mysql_query($find_duplicate)) or die (mysql_error());

$weapon_name_check = $dup['Weapon_Name'];

if($weapon_name_check == $weapon_name){

header("location:weaponshop.php");

}elseif($weapon_cost > $player_Credits){

header("location:weaponshop.php");

}else{



$new_player_credits = $player_Credits-$weapon_cost;
$new_attack = $weapon_attack+$player_attack;
$new_defense = $weapon_defense+$player_defense;
$new_strength = $weapon_strength+$player_strength;
$new_speed = $weapon_speed+$player_speed;
$new_accuracy = $weapon_accuracy+$player_accuracy;
$new_range = $weapon_range+$player_range;
$new_HBS = $new_attack+$new_defense+$new_strength+$new_speed+$new_accuracy+$new_range *.3;

echo "
<html>
<img src='$weapon_image'/><br/>
$new_player_credits<br/>
$new_attack<br/>
$new_defense<br/>
$new_strength<br/>
$new_speed<br/>
$new_accuracy<br/>
$new_range<br/>
$new_HBS
</html>
";


}

}else{

header("location:index.php");
}

?>

Link to comment
https://forums.phpfreaks.com/topic/244090-having-_get-problem-i-think-help/
Share on other sites

See how this works:

<?php
error_reporting(E_ALL); //debugging remove after script works.
ini_set('display_errors',1); //debugging remove after script works.
session_start(); 
if(isset($_SESSION['user'])) {
include_once('connect.php');
$session = $_SESSION['user'];
$w = (isset($_GET['w'])) ? (int)$_GET['w'] : 0; //0 being default weapon.

$find = "SELECT * FROM weapon_shop WHERE id = '$w'";
$run = mysql_fetch_array(mysql_query($find)) or trigger_error(mysql_error());

$weapon_id = $run['id'];
$weapon_name = $run['Weapon_Name'];
$weapon_image = $run['Weapon_Image'];
$weapon_level = $run['Weapon_Level'];
$weapon_cost = $run['Weapon_Cost'];
$weapon_sell_value = $run['Weapon_Sell_Value'];
$weapon_attack = $run['Weapon_Attack'];
$weapon_defense = $run['Weapon_Defense'];
$weapon_strength = $run['Weapon_Stength'];
$weapon_speed = $run['Weapon_Speed'];
$weapon_accuracy = $run['Weapon_Accuracy'];
$weapon_range = $run['Weapon_Range'];

$find_stats = "SELECT * FROM stats WHERE Username = '$session'";
$stats = mysql_fetch_array(mysql_query($find_stats)) or trigger_error(mysql_error());

$player_HBS = $stats['HBS'];
$player_Credits = $stats['Current_Credits'];
$player_attack = $stats['Attack'];
$player_defense = $stats['Defense'];
$player_strength = $stats['Strength'];
$player_speed = $stats['Speed'];
$player_accuracy = $stats['Accuracy'];
$player_range = $stats['Range'];

$find_duplicate = "SELECT Weapon_Name FROM weapons WHERE Weapon_Name = '$weapon_name'";
$dup = mysql_fetch_array(mysql_query($find_duplicate)) or trigger_error(mysql_error());

$weapon_name_check = $dup['Weapon_Name'];

if($weapon_name_check == $weapon_name){

header("location:weaponshop.php"); //header expects a full URI.  Location must be capitalized, and a space must be after the colon.  This will insure that it works across ALL browsers.

}elseif($weapon_cost > $player_Credits){

header("location:weaponshop.php"); //see above.

}else{



$new_player_credits = $player_Credits-$weapon_cost;
$new_attack = $weapon_attack+$player_attack;
$new_defense = $weapon_defense+$player_defense;
$new_strength = $weapon_strength+$player_strength;
$new_speed = $weapon_speed+$player_speed;
$new_accuracy = $weapon_accuracy+$player_accuracy;
$new_range = $weapon_range+$player_range;
$new_HBS = $new_attack+$new_defense+$new_strength+$new_speed+$new_accuracy+$new_range *.3;

echo "
<html>
<img src='$weapon_image'/><br/>
$new_player_credits<br/>
$new_attack<br/>
$new_defense<br/>
$new_strength<br/>
$new_speed<br/>
$new_accuracy<br/>
$new_range<br/>
$new_HBS
</html>
";


}

}else{

header("location:index.php"); //see above.
}

?>

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.