Jump to content

[SOLVED] Php code is not running. Why?


tomjung09

Recommended Posts

Hey all, I am trying to do a simple update to my database when it loads.  The php code that is written in there I have already tested on a blank template and it works just fine.  When I try to run it in this file, it does not work.

 

I have tried putting the php code in the body, header, before the header, and inside one of the framesets.  It will not output the Howdy, and nothing is happening to the database.  Any idea why?

 

<?php require_once('../Connections/emotos.php'); ?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>eMotos</title>
</head>
<frameset rows="56,*" cols="*" frameborder="NO" border="0" framespacing="0">
  <frame src="/html2/topNav.htm" name="topFrame" scrolling="NO" noresize >
  <frameset cols="214,*" frameborder="NO" border="0" framespacing="0">
    <frame src="/html2/leftNav.htm" name="leftFrame" scrolling="NO" noresize>
    <frame src="/html2/home.php" name="mainFrame">
  </frameset>
</frameset>
<body>
<?php 
//If link came from a setup advertising link
//Then adjust the database accordingly
$abrv = $_GET['abvr'];
echo "howdy!";
if ($abrv == ""){}
else{
//echo $abrv;

mysql_select_db("emotosn_main") or die(mysql_error());
$result = mysql_query("SELECT * FROM advertising WHERE abrv = '$abrv'") or die(mysql_error());
$row = mysql_fetch_array( $result );
$count = $row['count'];
$count = $count + 1;
mysql_query("UPDATE advertising SET count = '$count' WHERE abrv = '$abrv'");
}
?>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/153604-solved-php-code-is-not-running-why/
Share on other sites

First - are you making a connection to the database in emotos.php? I can see later in the script you're trying to select a DB to use but mysql_connect() must be called first.

 

Second - this code:

if ($abrv == ""){}
else{

Can be rewritten as:

if ($abrv != "") {

 

You can also replace:

$count = $count + 1;

With:

$count++;

Hey, thanks a bunch for the tips!  I like to keep it simple so I know what is up, but I would rather condense and learn something new.  So good stuff. 

 

As to your question, I did forget to connect to the database, but I put it in my code and now I am still having the same problem.

 

emotos.php

<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_emotos = "localhost";
$database_emotos = "emotosn_main";
$username_emotos = "<username>";
$password_emotos = "<thepassword>";
$emotos = mysql_pconnect($hostname_emotos, $username_emotos, $password_emotos) or trigger_error(mysql_error(),E_USER_ERROR); 
?>

 

new default.php

<?php require_once('../Connections/emotos.php'); ?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>eMotos</title>
</head>
<frameset rows="56,*" cols="*" frameborder="NO" border="0" framespacing="0">
  <frame src="/html2/topNav.htm" name="topFrame" scrolling="NO" noresize >
  <frameset cols="214,*" frameborder="NO" border="0" framespacing="0">
    <frame src="/html2/leftNav.htm" name="leftFrame" scrolling="NO" noresize>
    <frame src="/html2/home.php" name="mainFrame">
  </frameset>
</frameset>
<body>
<?php 
//If link came from a setup advertising link
//Then adjust the database accordingly
$abrv = $_GET['abvr'];
echo "howdy!";


if ($abrv == ""){}
else{
//echo $abrv;
mysql_select_db($database_emotos, $emotos);
//mysql_select_db("emotosn_main") or die(mysql_error());

if (mysql_query("UPDATE advertising SET `count`=`count`+1 WHERE abrv = '".$abrv."'")) {
  //success
} else {
  //failed
}
}
?>
</body>
</html>

 

 

Any idea why this won't update my database?  This is driving me nuts!

Ah, okay, I found the problem but I don't know how to fix it lol.

 

This line here:

<?php require_once('../Connections/emotos.php')or die(mysql_error()); ?>

 

Throws the error:

Warning: main(1) [function.main]: failed to open stream: No such file or directory in /home/emotosn/public_html/html2/updatetest.php on line 1

 

Fatal error: main() [function.require]: Failed opening required '1' (include_path='.:/usr/php4/lib/php:/usr/local/php4/lib/php') in /home/emotosn/public_html/html2/updatetest.php on line 1

 

The file does exist in Connections.... so .... any ideas?

 

  • 2 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.