For some reason this is killing me, I am trying to update the field available to '-1' and don to '0' when the user submits the correct string into the input box, the thing I cant work out is why available wont update but don will the code is below along with the other way of putting the statement which did update it but constantly so as soon as the page refreshed it would be set at '-1' whether the user input anything or not!

<?php function puzz($comm0,$comm1,$comm2) {
include('mysqlconnect.php');
 $query = "SELECT * FROM plyr_room";
      $result = mysql_query($query) or die(mysql_error());
      $row = mysql_fetch_array($result);
      $dbplyr_id = $row['player_id'];
      $dbroom_no = $row['roomno'];

$query = 'SELECT * FROM puzzles, roomitem WHERE puzzles.item = roomitem.item AND re_room = " ' . $dbroom_no . ' " AND available = "0"';
    $result = mysql_query($query) or die(mysql_error());
	$row = mysql_fetch_array($result);
	$dbre_room = $row['re_room']; //required room number
	$dbexit_no = $row['exit_no']; //exit direction
	$dbdon = $row['don']; // task completed
	$dbword1 = $row['word1']; // 1st entered word
	$dbword2 = $row['word2']; // second entered word
	$dbroomno1 = $row['roomno']; // current room number
	$dbitem = $row['item'];  // required item
	$db_ava = $row['available']; // if item is available
$query = 'SELECT item,needed FROM roomitem WHERE item = " ' . $dbitem . ' "';
    $result = mysql_query($query) or die(mysql_error());
	$row = mysql_fetch_array($result);
	$item = $row['item']; // item in inventory
	$needed = $row['needed']; // needed in task

echo "<br /> $query <br /> $dbitem <br />";


if (($comm0 = $dbword1) && ($comm1 = $dbword2)) {
 $con = mysql_connect("localhost","root","*****");
      if (!$con)
	{
	die('Could not connect: ' . mysql_error());
	}

      mysql_select_db("game");


      mysql_query('UPDATE roomitem SET available = "-1" WHERE item =" ' . $db_item . ' " ')
      mysql_query('UPDATE puzzles SET don = "0" WHERE re_room =" ' . $dbroom_no . ' "');}
else{echo "You can not do that!";}}
?>

the other statement I tried

mysql_query('UPDATE roomitem SET available = "-1" WHERE roomno =" ' . $dbre_room . ' " AND needed = "1"');

any help would be amazing.

Daryll

Member Avatar for diafol

You place a value within $dbitem but use $db_item in the SQL. They aren't the same.

Thank you didn't notice that and I also realised I was calling the wrong variable in the if statement, sorted now .

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.