Jump to content

Recommended Posts

>:( I have been an ASP programmer for 10 years. I am trying to learn PHP and get away from ASP. I have struggled for days to get things to work in PHP that would have taken me minutes in ASP.

I have a page that uses an include.

It took a day and a half to get a connection to mysql to work (literally 8 lines of code). But I finally got it to work and return a value from the database.

I then moved on to $_SESSION which I could only get to return the session data on the page that set the session data. Once I went to another page, $_SESSION is blank.

After scouring the internet for a solution I ran across one. I tried to implement it but it didn't work. The result was a blank page. So I reverted back to my "working" code and the page is still blank. I can't get it to do anything. Even this won't display:

<?php
echo "Hello World!";
?>

The above code produces a blank page as well.

Again this page is an include file. If I remove the include, the HTML on the page displays. If I include the above code as an include the page is blank. If I open the above code by itself it is still a blank page.

It seems that as soon as I ran "!isset" in my code, PHP stopped working COMPLETELY. Even though I took it back out PHP is still broken.

What is going on? I could have finished the site in ASP by now. I still want to do it in PHP but this is frustrating!!!!!! >:(
Link to comment
https://forums.phpfreaks.com/topic/34432-why-doesnt-php-work/
Share on other sites

For me it sounds like your installation is f***ed.

try this site:
[url=http://www.apachefriends.org/en/xampp.html]http://www.apachefriends.org/en/xampp.html[/url]

Its a very cool program that installs all you need for php and mysql to work correctly.

You also get a mail server and ohter stuff installed.

Its very nice.

Let me know if there still are problems after installation.


JJohnsenDK
Link to comment
https://forums.phpfreaks.com/topic/34432-why-doesnt-php-work/#findComment-162109
Share on other sites


include('dbconn.php');
  // Connect to the database to retrieve challenge response
  $cxn = mysql_connect($mysql_HOST,$mysql_USER,$mysql_PASS);  // Connect to server
  $db_selected = mysql_select_db($mysql_DB, $cxn);                      // Select the database
 
  $result = mysql_query("SELECT * FROM Secure");      // Perform MySQL SELECT statement
 
  if ($result){             // Make sure select statement worked
      $row = mysql_fetch_array($result);                    // Get database values in array
  session_start();             // Start the session
      $_SESSION['avar'] = $row['id'];                         // Set the avar value
$_SESSION['bvar'] = $row['email'];                    // Set the bvar value
  }
 



like I said, that code worked fine until I added:

if(!isset($_SESSION['avar'])){
  $_SESSION['avar'] = $row['id'];
}



That code produced a blank page. so I reverted back to the other code and I still get a blank page.
Link to comment
https://forums.phpfreaks.com/topic/34432-why-doesnt-php-work/#findComment-162168
Share on other sites

However, I think everyone is missing the point.
I changed the include page to have this code, and only this code:

echo "Hello World!";


and it is still a blank page. So it doesn't make a difference what the code is. Anycode makes it blank whereas it was working before I used isset.
Link to comment
https://forums.phpfreaks.com/topic/34432-why-doesnt-php-work/#findComment-162171
Share on other sites

To make it easier I moved all the code from the include file into the index.php file (I chaged to <edit> to remove sensitive data:

-----------------------------------------------------------
<?php
session_start();

$mysql_HOST = "<edit>";
$mysql_USER = "<edit>";
$mysql_PASS = "<edit>";
$mysql_DB = "<edit>";

$cxn = mysql_connect($mysql_HOST,$mysql_USER,$mysql_PASS);
$db_selected = mysql_select_db($mysql_DB, $cxn);
 
$result = mysql_query("SELECT * FROM Secure");
 
if ($result){
  $row = mysql_fetch_array($result);
  $_SESSION['<edit>'] = $row['<edit>'];
  $_SESSION['<edit>'] = $row['<edit>'];
}
?>
-----------------

(continued in next post)
Link to comment
https://forums.phpfreaks.com/topic/34432-why-doesnt-php-work/#findComment-162193
Share on other sites

This produces a blank page!


NOW, I comment out EVERYTHING!!!!!! to look like this:

-----------------------------------------------------------
<?php
//session_start();

//$mysql_HOST = "<edit>";
//$mysql_USER = "<edit>";
//$mysql_PASS = "<edit>";
//$mysql_DB = "<edit>";

//$cxn = mysql_connect($mysql_HOST,$mysql_USER,$mysql_PASS);
//$db_selected = mysql_select_db($mysql_DB, $cxn);
 
//$result = mysql_query("SELECT * FROM Secure");
 
//if ($result){
  //$row = mysql_fetch_array($result);
  //$_SESSION['<edit>'] = $row['<edit>'];
  //$_SESSION['<edit>'] = $row['<edit>'];
//}
?>
-----------------

(continued in next post)
Link to comment
https://forums.phpfreaks.com/topic/34432-why-doesnt-php-work/#findComment-162197
Share on other sites

Looking at the code you posted (which would have been helpful in your first post) you would get no output if the query failed. Add some error handling to your query to see if any errors are produced:

[code]$result = mysql_query("SELECT * FROM Secure") or die (mysql_error());[/code]
Link to comment
https://forums.phpfreaks.com/topic/34432-why-doesnt-php-work/#findComment-162198
Share on other sites

[quote author=voxanBoxer link=topic=122665.msg506274#msg506274 date=1168972908]
The resulting page is STILL blank.

I remove the <?php & ?> and the page displays the html
[/quote]

If you comment out everything wouldn't you expect a blank page? What do you mean "I remove the <?php & ?> and the page displays the html". What HTML is displayed?
Link to comment
https://forums.phpfreaks.com/topic/34432-why-doesnt-php-work/#findComment-162202
Share on other sites

The HTML below the php code

<?php
echo "Hello World!<P>";
?>
<html>
<body>
Hello World!
</body>
</html>

We can all agree that the expected result should be:

Hello World!

Hello World!


correct? I get a blank page.
If I comment out echo "Hello World!<P>"; in the php code the expected result would be:

Hello World!

correct? Well the page is still blank! If I take out all the PHP tags the expected result would be:

Hello World!

correct? And in fact that is what I get. BUT with php tags in the page, I get nothing.

Having said all that. It only happens on this page. PHP works on other pages. AND USED TO WORK ON THIS PAGE.
Link to comment
https://forums.phpfreaks.com/topic/34432-why-doesnt-php-work/#findComment-162206
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.