-1

So, this is a problem that is bugging me for a while now.

I've got a query I want to run with PHP, but it Always fails, even if it's very simple.

This problem only occures at one table, all other tables just work fine so it isn't a problem with connecting to the database.

Here is the code:

<?php
// Start the session
session_start();
?>

<html>
<head>
<title>Chat room</title>
</head>
<body>

<?php
  include 'opendb.php';

  $query = "SELECT id
  FROM chat";

  $resultaat = mysql_query($query, $connectie) or die('Error, query failed 1');


  include 'closedb.php';
?>

<p><?php echo $user?><?php echo $text?></p>
</form>

</body>
</html>

Yes, this actually fails, here's a link to the adress: http://ln99030804.haperen.eu/chat.php

Here's a picture showing my table on phpMyAdmin.

I also need to tell that I took some code away just to make it less chaotic, but it didn't have anything to do with the part crashing.

could anybody please help me with this?

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
Lolslayer
  • 63
  • 8
  • Thank you @RiggsFolly, but it does work with other tables without any problem, so this doesn't fix it really – Lolslayer Oct 06 '16 at 12:32
  • Well if you look for the error rather than ignoring that as a possibility, you can probably solve this yourself. Add `if ( ! $resultaat ) { echo mysql_error(); exit; }` after you run the query and MYSQL will tell you what you did wrong – RiggsFolly Oct 06 '16 at 12:33
  • check for errors with error reporting and mysql_error() on the query – Funk Forty Niner Oct 06 '16 at 12:33
  • Thanks for this respond aswell @RiggsFolly, I added this just after I run the query but it doesn't show anything new at all, still the same error code, nothing more – Lolslayer Oct 06 '16 at 12:36
  • And thank you aswell @Fred-ii-, but as you can see in my previous comment it didn't work – Lolslayer Oct 06 '16 at 12:37
  • @Lolslayer That first comment was supposed to inform you that the code you are writing (_mysql_* code) **will not work** on PHP7, the latest greatest version of PHP that has been out now since December 2015. You are therefore writing code that will soon need to be re-written, therefore wasting your time – RiggsFolly Oct 06 '16 at 12:38
  • 2
    Add [error reporting](http://stackoverflow.com/questions/845021/how-to-get-useful-error-messages-in-php/845025#845025) to the top of your file(s) _while testing_ right after your opening PHP tag for example ` – RiggsFolly Oct 06 '16 at 12:40
  • `or die('Error, query failed 1')` won't help you here if something did crash in the query, did you in fact use `mysql_error()` instead? you may also have to add the connection parameter for it `mysql_error($connectie)`. You are using mysql_ to connect with, right? and not mysqli_ or pdo? start by `var_dump()`ing and echo/break here and there to see where it could be choking. Error reporting didn't show you anything neither? I see `include 'closedb.php';` which suggests you're probably closing the connection for `` may not show if it's related to the query. – Funk Forty Niner Oct 06 '16 at 12:42
  • Maybe you should also show us the contents of `opendb.php` (passwords obfiscated of course) as that may be where your issue lies – RiggsFolly Oct 06 '16 at 12:42
  • Thank your for informing me on that @RiggsFolly, I'll definitely try to learn the newer versions :) – Lolslayer Oct 06 '16 at 12:43
  • Ah, thank you very much @RiggsFolly, your error reporting thingy worked for me :) – Lolslayer Oct 06 '16 at 12:49
  • It works, thanks for your time though trying to help me @Fred-ii- :) – Lolslayer Oct 06 '16 at 12:52
  • you're welcome, however editing your question and the title as "solved" should be removed (Edit: I edited it). It doesn't tell us what the problem was, and I for one am curious to know what it was. I edited the question/title. Please post an answer below to let everyone know what the real problem was. Stack lets you do that ;-) but do give a detailed answer. – Funk Forty Niner Oct 06 '16 at 12:53
  • since you may not be posting what the problem really was (or you left Stack for today), then you should just delete the question, since it won't serve anyone here if they/we don't know what the real problem was. – Funk Forty Niner Oct 06 '16 at 13:02
  • @Fred-ii- Posted the fix, but I've to wait for 2 days before I can mark it as the solving answer :/ – Lolslayer Oct 06 '16 at 13:09
  • no problemo, *cheers* glad to see it was resolved. – Funk Forty Niner Oct 06 '16 at 13:10
  • Indeed, and again, thanks for the help @Fred-ii- – Lolslayer Oct 09 '16 at 15:37
  • you're most welcome @Lolslayer *cheers* – Funk Forty Niner Oct 09 '16 at 18:28

1 Answers1

1

Okay, on request of @RiggsFolly I'll tell what the problem was.

The problem was that my opendb.ph and closedb.php files were on another folder then this page itself.

I didn't suspect that this was the problem because somehow other database tables didn't give an error to me, so I thought that that part was completely working.

Thanks everybody for helping me with this, it was a really stupid mistake but I was really stuck for days on this before I dared to ask on stack overflow xD

Lolslayer
  • 63
  • 8