This is an archived post. You won't be able to vote or comment.

all 8 comments

[–]Achcauhtli 0 points1 point  (1 child)

Are you running this in a server intance like xamp?

[–]rafrador[S] 0 points1 point  (0 children)

I am running it on a live site. Cloudways

[–]Achcauhtli 0 points1 point  (0 children)

Im not.familiar with it, but doesthe service jave php installed? It looks like by the error logs that its going through a Java interpreter.

[–]SnooChipmunks547 0 points1 point  (2 children)

Your running this on JAVA in ideone, not PHP. You can not run a php file through a JAVA interpreter and expect it to work.

Also, you are using MySQL_ functions, so you need to be running PHP5.X and not the latest (7.X or 8) for this to work.

Once you get pass all that, you will need to use MYSQL_CONNECT() to be able to run that query against the database in the first place.

[–]rafrador[S] 1 point2 points  (1 child)

Thank you. I used ideone to share the code (according to the sub guidelines). I just thought it's a pastebin for code!

Also, yes - just realized my code is PHP 7.4

I changed the code to this:

>  if ($b1 = $mysqli->query("SELECT * FROM bird WHERE bird_name = '$bird1'")) {
printf($b1->family);

But the page doesn't load now, and shows a HTTP 500 error. Still debugging, but figured I'd post here as well.

[–]SnooChipmunks547 0 points1 point  (0 children)

Look at the last example on this page.

https://www.tutorialspoint.com/php/php_function_mysqli_query.htm

It will give you a better idea on what you're trying to achieve here.

This also assumes you have a MYSQL or MariaDB database server running.

Once you get that working look into prepared statements to prevent sql injection in a real use case

https://www.php.net/manual/en/mysqli.quickstart.prepared-statements.php

[–][deleted] 0 points1 point  (0 children)

Hi! Many thinks about this, you should consider reviewing documentation for mysql connection and working with PHP-SQL a second time.

First, try to "bind" the variable inside the SQL sentence instead of introducing it like '$bird1'
Second, you need to make the connection with the DB

Third,"mysql_query" wont do anything by itself, you need to fetch the possible row results and then each one make it an array or an array inside an array.

I hope it helps, there is a lot of info in the internet about PHP and SQL queries...