This question already has answers here:
Can I mix MySQL APIs in PHP?
(4 answers)
Closed 5 years ago.
Cant figure out why my query isn't returning the 'make'. I've checked the SQL many times.
$DBConnect = #mysqli_connect("host.com", "name","pass", "database")
Or die ("<p>Unable to connect to the database server.</p>". "<p>Error code ". mysqli_connect_errno().": ". mysqli_connect_error()). "</p>";
$query = "SELECT make FROM inventory";
$makeresult= #mysql_query($DBConnect, $query);
while($row = mysql_fetch_array($makeresult)) {
$options .="<option>" . $row['make'] . "</option>";
}
You're using a mysqli connection but trying the deprecated mysql functions.
try mysqli_fetch_array() instead
Related
This question already has answers here:
Correct way to use LIKE '%{$var}%' with prepared statements?
(1 answer)
How to include a PHP variable inside a MySQL statement
(5 answers)
Closed 19 days ago.
<?php
$search = $_POST['search'];
$server_name="localhost";
$user_name="root";
$password="";
$database="Product_Management";
$conn = mysqli_connect($server_name,$user_name,$password,$database);
if(!$conn){
die("Connection Failed : ".mysqli_connect_error());
}
$qry = "select * from Product where Product_Name like '%.$search.%' ";
$result = mysqli_query($conn,$qry);
while($row=mysqli_fetch_array($result)){
echo $row['Product_Name'];
}
mysqli_close($conn);
I tried all the ways of resolving this issue, but couldn't find the answer.
I am also trying to test by REST API
This question already has answers here:
Can I mix MySQL APIs in PHP?
(4 answers)
Closed 4 years ago.
okay guys so i was just writing the code for an admin panel just for fun, and i ran into a problem when i copied some code from w3schools.
Can someone tell me where i am wrong.
Here's My Code
<?php
$conn = mysql_connect("localhost", "root","","ATFlogin");
$sql = "SELECT id, username, password FROM users";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo "<br> id: ". $row["id"]. " - Name: ". $row["firstname"]. " " . $row["lastname"] . "<br>";
}
} else {
echo "0 results";
}
?>
it Looks like you are trying to mix mysql with mysqli.
Change your connection to be:
$conn = mysqli_connect("localhost", "root","","ATFlogin");
Read up on MySQLI here
mysql functions have all been depracted and mysqli is the successor so if possible use mysqli.
This question already has answers here:
Can I mix MySQL APIs in PHP?
(4 answers)
Closed 5 years ago.
I need assistance in understanding how to work with 2 tables from a database. I tried writing the code like this but it did not work. It works in MySQL but not in php. I am new coder trying to learn, but I am stuck any help would be appreciated. first and last name are on 1 table. Price is on another table.
Also I am getting this error
mysql_fetch_array() expects parameter 1 to be resource
index.php
<?php
include ('db.php');
$sql='SELECT * FROM `user_info` ,`customer_order` WHERE user_info.user_id=customer_order.uid';
$run_query=mysqli_query($conn,$sql);
if(! $run_query ) {
die('Could not get data: ' . mysql_error());
}
while($row = mysql_fetch_array($run_query, MYSQL_ASSOC)) {
echo "First Name:{$row['first_name']} <br> ".
"Last Name:{$row['last_name']} <br>".
"price:{$row['price]} <br>";
}
I made a mistake and mixed up MySQL with mysqli I fixed the issue and it is working thanks from Don't panic.
<?php
include ('dbconnect.php');
$sql='SELECT * FROM `user_info` ,`customer_order` WHERE user_info.user_id=customer_order.uid';
$run_query=mysqli_query($conn,$sql);
if(! $run_query ) {
die('Could not get data: ' . mysqli_error());
}
while($row = mysqli_fetch_array($run_query, MYSQLI_ASSOC)) {
echo "name:{$row['first_name']} <br> ".
"Last:{$row['last_name']} <br> ";
}
This question already has answers here:
Why shouldn't I use mysql_* functions in PHP?
(14 answers)
Closed 6 years ago.
I have two pages . In the first page if user will click on button then he will get relavant data with id column
<form action='edit.php?id=$id' method='post' name='edit_btn'>
<button type='submit' class='w3-btn w3-red w3-round-xlarge'>Proceed </button>
</form>
$con=mysqli_connect("localhost","root","","student_result_info_db");if (mysqli_connect_errno()){ echo "Failed to connect to MySQL: " . mysqli_connect_error(); }else{
if(isset($_GET['edit_btn'])){
echo "<div class='w3-container w3-red'> <h1>>Error Found!</h1> <h4>OK You Did Hit The EDIT Button</h4> </div> <br/>";
}else{
$get_selected_id = $_GET['id'];
echo $get_selected_id;
$res = "SELECT * FROM school_result";
while ($row = mysql_fetch_array($res)){
echo "$row[id]. $row[first_name] <br/>";
echo "$row[id]. $row[last_name] <br/>";
}
}
}
It'showing following error
Fatal error: Call to undefined function mysql_fetch_array() in
Use mysqli_fetch_array instead, along with mysqli_query to get a mysqli_result object:
$qresult = mysqli_query($con, $res);
while ($row = mysqli_fetch_array($qresult)){
You need to use this for 2 reasons:
You opened your database using mysqli_connect, so you need to use the mysqli functions.
mysql functions were removed in PHP 7.
Use mysqli function instead of mysql like
mysqli_query($con, $res);
This question already has answers here:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result [duplicate]
(6 answers)
Closed 8 years ago.
I am getting a warning message which I don't understand why and unable to resolve, (see below)
Warning: Supplied argument is not a valid MySQL result resource in /detail.php on line 34
Here is my code:
$rs = mysql_query($strSQL);
$strSQL = "SELECT * FROM <tablename> WHERE id=" . $_GET["serviceName"];
// Loop the recordset $rs
while($row = mysql_fetch_array($rs)) **(line 34) here ***
{
echo $row['ID']."<br />";
echo $row['serviceName']."<br />";
// Close the database connection
mysql_close();
?>
</dl>
<p>Return to the list</p>
</body>
</html>
thanks in advance, I am not getting any of the data on this webpage either,thanks...singhy
The query is failing - you need to wrap quotes around strings in MySQL:
$strSQL = "SELECT * FROM gu_service_cat WHERE id = '" .
$_GET["serviceName"] . "'";
plus, the $rs should be BELOW the $strSQL...
You need to do it like this
$strSQL = "SELECT * FROM gu_service_cat WHERE id=" . $_GET["serviceName"];
$rs = mysql_query($strSQL);
Because before setting value to the variable you are using it in the query. This is why it is throwing the error.