[英]MySql PHP Connection issues
I am aware that this has already been posted but have tried the options available on here, so am forced to ask again...have been trying all sorts for weeks now...to no avail!我知道这已经发布了,但已经尝试过这里可用的选项,所以我不得不再次询问......已经尝试了好几个星期......但无济于事!
Have an account in cPanel, with a database in phpMyAdmin and am trying to return data to my website.在 cPanel 中有一个帐户,在 phpMyAdmin 中有一个数据库,我正在尝试将数据返回到我的网站。
Initially, I kept getting errors connecting, and found that I hadn't set user privileges (am new to this).最初,我不断收到连接错误,发现我没有设置用户权限(对此我很陌生)。
Now I have sorted that, when I create a search in the text area and hit return, the Favicon spins around and goes back to the initial state.现在我已经对它进行了排序,当我在文本区域中创建搜索并点击返回时,Favicon 会旋转并返回到最初的 state。
I am so spun around with it all now, that I am unsure if its PHP, MYSQL, HTML etc. etc.我现在对它很感兴趣,我不确定它是否是 PHP、MYSQL、HTML 等。
Here's the PHP code:这是 PHP 代码:
<?php
$output=NULL;
if(isset($_POST['submit'])){
//Connect to the database
$mysqli = new mysqli("localhost", "jj3wg2td_wix", "Sebastian!16", "jj3wg2td_careerslist");
$search = $mysqli->real_escape_string($_POST['search']);
//Query the database
$result = $mysqli->query("SELECT * FROM careers WHERE Job Title LIKE '%$search%'");
if($resultSet->num_rows > 0){
while($rows=$resultSet->fetch_assoc())
{
$jobTitle=$rows['Job Title'];
$jobDesription=$rows['Job Description'];
$salaryLow=$rows['Salary Low'];
$salaryHigh=$rows['Salary High'];
$output .="Job Title:$jobTitle<br />
Job Description:$jobDesription<br />
Salary Low:$salaryLow<br />
Salary High:$salaryHigh<br />
<br />";
}
}else{
$output="No results";
}
}
?>
This doesn't return "No Results" at all, just blank space.这根本不返回“无结果”,只是空白。
I also have a PHP output after my search button code of:在我的搜索按钮代码为:
<?php echo $output; ?>
Search button being:搜索按钮为:
<!--SEARCH BOX-->
<div class="search-box">
<form method="POST">
<input class="search-txt" type="TEXT" name="search" placeholder="SEARCH CAREERS">
<a class="search-btn" type="SUBMIT" name="submit">
<i class="fa fa-search" aria-hidden="true"></i>
</a>
</form>
</div>
The 'Local Host' in phpMyAdmin states that the name', Localhost:3306 (have seen this issue a lot). phpMyAdmin 中的“本地主机”声明名称“本地主机:3306”(经常看到此问题)。 So I have tried that, as well as just 'localhost....but nothing works at all now.所以我已经尝试过了,以及'localhost....但现在根本没有任何效果。
Apologies for my basic understanding in advance...and that you for any help!!!提前为我的基本理解道歉......以及您的任何帮助!
Completely giving up!彻底放弃!
I think your form was not submitting on click of <a>
.我认为您的表单没有在点击<a>
时提交。 So, you have to make such changes to submit your form first.因此,您必须先进行此类更改才能提交表单。
Solution 1 (With help of JS):解决方案1(在JS的帮助下):
<div class="search-box">
<form method="POST" id="searchForm">
<input class="search-txt" type="TEXT" name="search" placeholder="SEARCH CAREERS">
<a class="search-btn" onclick="document.getElementById('searchForm').submit()">
<i class="fa fa-search" aria-hidden="true"></i>
</a>
</form>
</div>
Solution 2: Use <button>
as a control for form submitting方案二:使用<button>
作为表单提交的控件
<button class="search-btn" name="submit" type="submit">
<i class="fa fa-search" aria-hidden="true"></i>
</button>
or use <input>
as submit button,或使用<input>
作为提交按钮,
<input type="submit" name="submit" value="submit" />
The main problem in your code is from PHP side, when you're checking for $_POST['submit']
here,您的代码中的主要问题来自 PHP 方面,当您在此处检查$_POST['submit']
时,
if(isset($_POST['submit'])){ }
It's not entering in the if()
statement, because it's not getting $_POST['submit']
in you're code.它没有进入if()
语句,因为它没有在你的代码中得到$_POST['submit']
。
Please make sure you're following naming conversations for datatables & fields.请确保您正在关注数据表和字段的命名对话。 So, please don't use uppercase & space in table/field name.因此,请不要在表/字段名称中使用大写和空格。 Like you used in your query ("SELECT * FROM careers WHERE Job Title LIKE...").就像您在查询中使用的那样(“SELECT * FROM careers WHERE Job Title LIKE...”)。 Here Job Title should be job_title .这里的Job Title应该是job_title 。 (***Update in data-table too) (***也在数据表中更新)
$mysqli->query("SELECT * FROM careers WHERE job_title LIKE '%$search%'");
Hope this will help you.希望这会帮助你。
there are no object assigned to the variable $resultSet
in your code.您的代码中没有分配给变量$resultSet
的 object。 but you try to read it's property like $resultSet->num_rows
this.但是您尝试读取它的属性,例如$resultSet->num_rows
这个。
use $result
insted of $resultSet
使用$result
插入$resultSet
try this尝试这个
$output=NULL;
if(isset($_POST['submit'])){
//Connect to the database
$mysqli = new mysqli("localhost", "jj3wg2td_wix", "Sebastian!16", "jj3wg2td_careerslist");
$search = $mysqli->real_escape_string($_POST['search']);
//Query the database
$result = $mysqli->query("SELECT * FROM careers WHERE Job Title LIKE '%$search%'");
if($result->num_rows > 0)
{
while($rows=$result->fetch_assoc())
{
$jobTitle=$rows['Job Title'];
$jobDesription=$rows['Job Description'];
$salaryLow=$rows['Salary Low'];
$salaryHigh=$rows['Salary High'];
$output .="Job Title:$jobTitle<br />
Job Description:$jobDesription<br />
Salary Low:$salaryLow<br />
Salary High:$salaryHigh<br />
<br />";
}
}
else{
$output="No results";
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.