5 Replies - 496 Views - Last Post: 24 February 2012 - 06:59 AM Rate Topic: -----

#1 Noirdeathe  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 29-March 11

PHP Script not working as intended.

Posted 23 February 2012 - 09:41 PM

Hi guys,

I've been given a task where I have to create a PHP based shopping cart but have run into a rather large problem that I cannot for the life of me be able to figure out.

For some strange reason my .PHP pages refuse to actually run the PHP script that I have attached (this is including off a friends website where I get the Could not connect: Lost connection to MySQL server at 'reading initial communication packet', system error: 110 error). The thing to top it all off however is supposedly the PHP -actually- works and have had it tested by someone else .. but I have no way of seeing this as it does not seem to load up.

If anyone could tell me where I'm going wrong, I would greatly appreciate it.


<?php
$con = mysql_connect("hostname","username","password");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("co525", $con);

$result = mysql_query("SELECT * FROM beer WHERE country_id = 3");

echo "<table border='1'>
<tr>
<th>ABV%</th>
<th>Bottle Size (mL)</th>
<th>Case Size</th>
<th>Price</th>
</tr>";

while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['abv'] . "</td>";
echo "<td>" . $row['bottleSize'] . "</td>";
echo "<td>" . $row['caseSize'] . "</td>";
echo "<td>" . $row['price'] . "</td>";
echo "</tr>";
}
echo "</table>";

mysql_close($con);
?>



(I cut out the HTML and changed the hostname, username and password)

I will attach a screenshot of the browser also.

Thank you for your time,
Noir.

Attached File(s)


This post has been edited by Noirdeathe: 23 February 2012 - 09:42 PM


Is This A Good Question/Topic? 0
  • +

Replies To: PHP Script not working as intended.

#2 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3069
  • View blog
  • Posts: 10,750
  • Joined: 08-August 08

Re: PHP Script not working as intended.

Posted 23 February 2012 - 09:48 PM

If I understand you correctly you're trying to access some one else's MySQL server and they're not on your subnet? Have they set up their server to allow this? (They shouldn't.)
Was This Post Helpful? 0
  • +
  • -

#3 no2pencil  Icon User is online

  • Admiral Fancy Pants
  • member icon

Reputation: 5379
  • View blog
  • Posts: 27,350
  • Joined: 10-May 07

Re: PHP Script not working as intended.

Posted 23 February 2012 - 09:48 PM

Looks like your webserver isn't setup or configured to run php files. This wouldn't be an error in the php code, it would be with your webserver.

I would recommend creating a test.php page that contains the following :

<?php
phpinfo();
?>



If that doesn't work, I must ask, have you ever had php files function on this server?
Was This Post Helpful? 0
  • +
  • -

#4 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3069
  • View blog
  • Posts: 10,750
  • Joined: 08-August 08

Re: PHP Script not working as intended.

Posted 23 February 2012 - 09:56 PM

If they're getting a MySQL error it's because PHP communicated with the MySQL server, so it seems that PHP is running.
Was This Post Helpful? 1
  • +
  • -

#5 no2pencil  Icon User is online

  • Admiral Fancy Pants
  • member icon

Reputation: 5379
  • View blog
  • Posts: 27,350
  • Joined: 10-May 07

Re: PHP Script not working as intended.

Posted 23 February 2012 - 10:05 PM

My mistake. I was just referring to the plan text php code from the screen shot.
Was This Post Helpful? 0
  • +
  • -

#6 Noirdeathe  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 29-March 11

Re: PHP Script not working as intended.

Posted 24 February 2012 - 06:59 AM

Aha! Well I should have access to the MySQL server (I can access it via MySQL workbench using the given hostname, username and password) it could be that I am not on the same network and/or the VPN I have to use for it isn't good enough.

Could that be the only issue?

Also; the webserver I am trying to run it off should allow PHP files, all I can think is that I am not-onsite currently to do it. (the screenshot is from the webserver that should allow PHP).

This post has been edited by Noirdeathe: 24 February 2012 - 07:05 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1