I am trying to math between value of 0 but in php code it's work properly but when that value come from database then it does not work.
Here is a demo to test only PHP code:
<?php
$a = 0;
echo $a+1;
?>
The result of this code
1
That ran properly, but when it came from database table then the "+" math does not work properly.
Here is my full code:
<?php
ob_start();
require('config2.php');
// move_up & move_down ** up_down //
$move_up = $_POST['move_up'];
$move_down = $_POST['move_down'];
$up_down1 = $_POST['up_down'];
$up_down11 = $_POST['up_down'];
$forid = $_POST['forid'];
$up = $up_down1-1;
$down = $up_down11+1;
if($move_up) {
if($up_down1) {
$insert=mysql_query("UPDATE widgets_mata SET `up_down` = '$up' WHERE `widgets_mata_id` = $forid");
header("Location: yyy.php");
}
}
if($move_down) {
if($up_down11) {
$insert2=mysql_query("UPDATE widgets_mata SET `up_down` = '$down' WHERE `widgets_mata_id` = $forid");
header("Location: yyy.php");
}
}
?>
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php $query2=mysql_query("SELECT * FROM widgets_mata ORDER BY up_down ASC");
while($rows2=mysql_fetch_assoc($query2))
{
$widgets_mata_id2=$rows2['widgets_mata_id'];
$widgets_id2=$rows2['widgets_id'];
$up_down2=$rows2['up_down'];
$field2=$rows2['field'];
if($field2=='R') {
$query3 = "SELECT * FROM widgets WHERE `widgets_id`=$widgets_id2";
$result3 = mysql_query($query3);
while($rows3 = mysql_fetch_assoc($result3))
{
$widgets_id3=$rows3['widgets_id'];
$fu_name3=$rows3['fu_name'];
$func_name3=$rows3['func_name'];
$func3=$rows3['func'];
?>
<h3> <?php echo $fu_name3; ?></h3>
<div>
Plaese select your options
<br />
<br />
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<label>
<input name="forid" type="hidden" id="hiddenField" value="<?php echo $widgets_mata_id2; ?>" />
<input name="up_down" type="hidden" id="hiddenField" value="<?php echo $up_down2; ?>" />
<input type="submit" name="move_up" value="Move Up" />
<input type="submit" name="move_down" value="Move Down" />
<br />
<br />
<input type="submit" name="button" id="button" value="Save" />
</label>
<label>
<input type="submit" name="button2" id="button2" value="Delete" />
</label>
<label>
<input type="submit" name="button3" id="button3" value="Cancel" />
</label>
</form>
</div>
<?php
}
}
}
?>
</body>
</html>
Here is my config2.php
<?php
$con = mysql_connect('localhost','root','')
or die(mysql_error());
mysql_select_db ("myweb");
?>
Here is my SQL
CREATE TABLE IF NOT EXISTS `widgets_mata` (
`widgets_mata_id` int(11) NOT NULL,
`widgets_id` int(11) NOT NULL,
`up_down` int(10) DEFAULT '1',
`field` text NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;
--
-- Dumping data for table `widgets_mata`
--
INSERT INTO `widgets_mata` (`widgets_mata_id`, `widgets_id`, `up_down`, `field`) VALUES
(1, 1, 0, 'R'),
(2, 2, 2, 'R'),
(3, 3, 3, 'R');
--
-- Indexes for dumped tables
--
--
-- Indexes for table `widgets_mata`
--
ALTER TABLE `widgets_mata`
ADD PRIMARY KEY (`widgets_mata_id`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `widgets_mata`
--
ALTER TABLE `widgets_mata`
MODIFY `widgets_mata_id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=4;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
My problem is with the "0" here:
Then the addition is not working. But when the value is "1"or"2"or"3" then the code works properly.
If you don't understand my question so please run my codes I give full code here