tomjung09 Posted April 11, 2009 Share Posted April 11, 2009 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> Quote Link to comment Share on other sites More sharing options...
Yesideez Posted April 11, 2009 Share Posted April 11, 2009 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++; Quote Link to comment Share on other sites More sharing options...
Yesideez Posted April 11, 2009 Share Posted April 11, 2009 Oh, if all you want to do is increment the field "count" by one you can do it in one query: if (mysql_query("UPDATE advertising SET `count`=`count`+1 WHERE abrv = '".$abrv."'")) { //success } else { //failed } Quote Link to comment Share on other sites More sharing options...
tomjung09 Posted April 13, 2009 Author Share Posted April 13, 2009 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! Quote Link to comment Share on other sites More sharing options...
mandred Posted April 13, 2009 Share Posted April 13, 2009 Add "or die(mysql_error())" after each of your mysql functions, so they look like this: mysql_select_db($database_emotos, $emotos) or die(mysql_error()); That will give you an error message explaining why its not updating. Quote Link to comment Share on other sites More sharing options...
tomjung09 Posted April 13, 2009 Author Share Posted April 13, 2009 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? Quote Link to comment Share on other sites More sharing options...
mandred Posted April 14, 2009 Share Posted April 14, 2009 Post updatetest.php, if the file existed and you were using proper syntax then this error would not occur. Quote Link to comment Share on other sites More sharing options...
tomjung09 Posted April 14, 2009 Author Share Posted April 14, 2009 updatetest.php isn't working either.... I could have sworn it was earlier but it gets the same error. Quote Link to comment Share on other sites More sharing options...
tomjung09 Posted April 22, 2009 Author Share Posted April 22, 2009 I'm an idiot, I moved servers and didn't change the localhost to the server IP. Thanks for everyones help! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.