Can't show output in html

I have a function that outputs several credits:

<?php function selectCredits() { include 'sqlvars.php'; $con = mysql_connect("localhost","bbbb","bbbb"); if (!$con){ die('Could not connect: ' . mysql_error()); } mysql_select_db("bbbb", $con); $result = mysql_query($selectCredits); while($row = mysql_fetch_array($result)){ echo $row['credits']; } } ?> 

When I call it from a php file using:

 <?php include 'sql.php'; selectCredits(); ?> 

I can see the result, but when I'm inside the HTML document, I can’t get the result using this code:

  <center><b>Your credits: </b></center> <?php include 'sql.php'; selectCredits(); ?> 

The solution is always: Your credits: no query result.

Of course, I miss something very small. I am not a php guy, but I want to find out after losing an hour without success.

+4
source share
4 answers

If you really want html files to execute PHP code, try adding this line to htaccess:

 AddType application/x-httpd-php .html 
+3
source

check the statement of the request '$ selectCredits'. check table name and attribute name - "Credits". $ Row ['credits'] does not receive a value.

+1
source

You have a problem with the code. You wrote

 while($row = mysql_fetch_array($result)){ echo $row['credits']; } 

You used mysql_fetch_array, and you immediately specified the string $ row with the attribute value. If you are using mysql_fetch_array, use $ row [0], $ row [1] or $ row [2], etc. All attributes act as an array. That is why you should consider it as an array index value. So, if the credit attribute is in the 5th column in your database, then you should respond as

 echo $row['4']; 

If you use mysql_fetch_assoc () instead of mysql_fetch_array, you can write the attribute name directly.

eg. then you can write

 echo $row['credits']; 

Hope this solves the problem. Please ask me if you have any further questions.

+1
source

You must use the JavaScript tag to implement the PHP file as follows:

<script type="text/javascript" src="credits.php"></script>

credits.php should be output:

echo "document.write('" . $row['credits'] . "');";

Plain:)

0
source

All Articles