Jump to content

get mysqli error


Danny620

Recommended Posts

Warning: mysqli_query() [function.mysqli-query]: Couldn't fetch mysqli in C:\xampp\htdocs\weapons.php on line 35

 

Warning: mysqli_error() [function.mysqli-error]: Couldn't fetch mysqli in C:\xampp\htdocs\weapons.php on line 35

 

Notice: Query: UPDATE test SET money=money-'2000', weapon1=weapon1+'2', weapon2=weapon2+'0', weapon3=weapon3+'0' WHERE id='2'

MySQL Error: in C:\xampp\htdocs\weapons.php on line 35

 

heres my code

<?php require('config.php'); ?>
<form method="post">
Weapon1: 
  <input size="3" maxlength="4" value="0" name="buy1"> <br>
Weapon2: <input size="3" maxlength="4" value="0" name="buy2"> <br>
Weapon3: <input size="3" maxlength="4" value="0" name="buy3"> <br>
<input name="buy" type="submit" value="Buy">
</form>

<form method="post">
Weapon1: 
  <input size="3" maxlength="4" value="0" name="sell1"> <br>
Weapon2: <input size="3" maxlength="4" value="0" name="sell2"> <br>
Weapon3: <input size="3" maxlength="4" value="0" name="sell3"> <br>
<input name="sell" type="submit" value="Sell">
</form>

<?php
//now the PHP part
//first if buy button is pressed
if ($_POST[buy]) {
$buy1 = strip_tags(addslashes($_POST[buy1]));
$buy2 = strip_tags(addslashes($_POST[buy2]));
$buy3 = strip_tags(addslashes($_POST[buy3]));

//we check if it is numeric and positive
if (!is_numeric($buy1) OR !is_numeric($buy2) OR !is_numeric($buy3)) { die("Wrong input!"); }
if (($buy1 < 0) OR ($buy2 < 0) OR ($buy3 < 0)) { die("Wrong input!"); }

//we check if we have enough money
$buy_money = 1000*$buy1+2000*$buy2+4000*$buy3;
if ($user[money] < $buy_money) { die("Not enough money to buy so many weapons!"); }

$q = "UPDATE test SET money=money-'$buy_money', weapon1=weapon1+'$buy1', weapon2=weapon2+'$buy2', weapon3=weapon3+'$buy3' WHERE 		    id='$user[id]'";
$r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc));
}

//we now make script which will run if we press Sell button
if ($_POST[sell]) {
$sell1 = strip_tags(addslashes($_POST[sell1]));
$sell2 = strip_tags(addslashes($_POST[sell2]));
$sell3 = strip_tags(addslashes($_POST[sell3]));

//we check if it is numeric and positive
if (!is_numeric($sell1) OR !is_numeric($sell2) OR !is_numeric($sell3)) { die("Wrong input!"); }
if (($sell1 < 0) OR ($sell2 < 0) OR ($sell3 < 0)) { die("Wrong input!"); }

//we check if user wants to sell more weapons he has
if (($sell1 > $user[weapon1]) OR ($sell2 > $user[weapon2]) OR ($sell3 > $user[weapon3])) { die("You cannot sell more weapons then you have!"); }

//we calculate how much money we will get (75%)
$sell_money = round((1000*$sell1+2000*$sell2+4000*$sell3)*0.75);

//if script got it to this point it was all ok so we can update
mysql_query("UPDATE test SET money=money+'$sell_money', weapon1=weapon1-'$sell1', weapon2=weapon2-'$sell2', weapon3=weapon3-'$sell3' WHERE id='$user[id]'");
} ?>

Link to comment
https://forums.phpfreaks.com/topic/170392-get-mysqli-error/
Share on other sites

Your connection to the database likely failed and $dbc is not a valid connection. Your code in config.php must test for connection errors and take appropriate action, such as preventing the remainder of the code from blindly attempting to use a database connection that does not exist.

Link to comment
https://forums.phpfreaks.com/topic/170392-get-mysqli-error/#findComment-898861
Share on other sites

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.