我面临的问题是我输入的条件句返回false!
class App extends Component {
constructor(props){
super(props);
this.state = {
elements: [],
dataLoaded: false,
}
}
loadData = () => {
fetch('http://localhost:3001/')
.then(res => res.json())
.then(data => {this.setState({elements: data, dataLoaded: true })})
.catch(err => console.log(err))
}
newElement = () => {
this.setState({dataLoaded: false}, () => {
this.loadData();
})
}
componentDidMount(){
this.loadData();
console.log(this.state.feladatok)
}
render() {
return (
dataLoaded ? <div className="App">
<Element newElem={() => this.newElement()}/>
</div> : <div>Loading......</div>
);
}
}
我需要说if ($db->addkey($key_value,$key_balance,$key_created_date))
{
echo 'TRUE';
}
else
{
echo 'FALSE';
}
工作并将值传递给数据库是完美的,但我仍然知道为什么这个语句返回false?
$db->addkey($key_value,$key_balance,$key_created_date
功能是:
addkey
变量是:
public function addkey($key_value,$key_balance,$key_created_date){
if ( !$this->link ) return false;
$query = "INSERT INTO `" . $this->table_prefix . "keys` (`key_value`,`key_balance`,
`key_created_date`)
VALUES('" . $this->realEscapeSingle($key_value) .
"', '" . $this->realEscapeSingle((int)$key_balance) . "', '" . $this->realEscapeSingle($key_created_date) . "')";
++$this->queries_;
mysqli_query($this->link,$query);
$key_id = mysqli_insert_id($this->link);
if( !$key_id )
{
echo mysqli_errno($this->link) . ": " . mysqli_error($this->link);
return false;
}
}
答案 0 :(得分:1)
您需要在return true
方法中的某处添加->addkey
。如果没有检测到错误,可能在底部?
答案 1 :(得分:1)
您的问题是addkey
方法永远无法返回 true
因此,当您在if(...)
语句中测试方法返回时,无论方法是否执行其预期任务,if都将永远不会运行。
参见代码:
public function addkey($key_value,$key_balance,$key_created_date){
....
$key_id = mysqli_insert_id($this->link);
if( !$key_id )
{
echo mysqli_errno($this->link) . ": " . mysqli_error($this->link);
return false;
}
return true; // this catch that if none of the return false
// are triggered then the function MUST be true.
}