Hello there! could you help me please ? I’m stuck in my project. I use a local web server and data server (ALL INCLUDED IN XAMPP), and all servers are running as you can see
everything is fine except that after created my database using PhpMyAdmin and I did set a password which is 72981352Mmm and the default username is root. but I wanna show my database’s table using php from the web browser. the main file is an index.html which contains a button and when the button is submitted the database’s table data must be displayed in the browser. but if I try this, it says THIS PAGE DOESN’T WORK. I do not know why. here are my code:
I’m here to help out if you can’t find the bug in your code, but I’m not going to write it for you from scratch.
Have a look at this CC php course, that should be what you are looking for: Printing associative arrays
What do you mean exactly? Why your initially posted code didn’t work?
Which php version do you use? The mysql_connect() function you used in your first code is deprecated since version 5.5 and was removed with 7.0: https://www.php.net/manual/en/function.mysql-connect.php
What does your code with mysqli look like?
not about this topic, you helped me and it worked fine. it’s just that I’m working on files with mysql and php. I wanna save a picture in the server and then display it through PHP. friends told me that it’s a best practice to not store images files in mysql, instead I have to store only the path of the file in mysql VARCHAR(225) type . but my code doesn’t work, nothing is shown in the browser. I created many topics about it on this forum but nobody answers me, that is why I came back to you because I remember you helped me in my first question. help me please Sir. so here is my code:
THE TABLE IS ALREADY CREATED IN MYSQL, AND THE TABLE NAME IS profil, the table contains two rows : id the primary key auto_increment and the pic row VARCHAR(225).
// the image file is : /Applications/images/;
$conn = new PDO("mysql:host=localhost;dbname=$dbname", $user, $password);
$sql = "SELECT pic FROM profile";
$img = $conn->exec($sql);
``` but no image is shown in the browser.
I don’t know if I’m the best to help you with this as I’m not so firm with php and MySQL.
But if you have a query "SELECT pic FROM profile" ‘pic’ would be the name of the column. That means that the query would give you all image paths stored in the database.
If you want to see if you get any valid result from the query, I recommend that you either use var_dump() or print_r() rather than echo. echo prints strings. If your result is either null or an array, echo would not print anything or not anything of great use.
(fyi: about 50% of the world’s population is female )
According to the docs it looks like ->exec returns a number or false, so: no.
It would still return the result as an array. So you will have to do it differently. You could use the code snippet from above:
You could replace the asterisk by the column name ‘pic’ and get the path as a string with implode() as described in this lesson.
You would then have to embed the php result in an html image tag.