Jim R Posted March 26, 2020 Share Posted March 26, 2020 (edited) This is a strange one, as I have many forms on my various sites, and on this site, the file in question is used by several functions. Ultimately, I'm wanting it INSERT values from the form, which I'll eventually add more of. Form is process and is stent to rn_process.php, which is the code listed below. include(ABSPATH ."resources/con.php"); $grade = $_POST['grade']; $position = $_POST['position']; echo $grade.$position; $query = "INSERT INTO a_rankings_select (username,userID,grade,position) VALUES ('" .$username. "', '" .$userID. "', '" .$grade. "', '" .$position. "')"; It echoes the correct $grade and $position when I comment out the INCLUDE. So I know it's passing the correct values. However, when the INCLUDE is active, I get the following error: Quote Warning: include(ABSPATHresources/con.php): failed to open stream: No such file or directory in /home2/csi/public_html/resources/rankings_navigation_process.php on line 2 resources/con.php is a file I link to many times, and it's work in those instances. It's certainly not executing the INSERT. Edited March 26, 2020 by Jim R Quote Link to comment https://forums.phpfreaks.com/topic/310375-issue-with-php-file-used-to-process-a-form/ Share on other sites More sharing options...
gw1500se Posted March 26, 2020 Share Posted March 26, 2020 Since you don't say what ABSPATH is, I am guessing there is a missing '/' in the resulting string. Quote Link to comment https://forums.phpfreaks.com/topic/310375-issue-with-php-file-used-to-process-a-form/#findComment-1575806 Share on other sites More sharing options...
Jim R Posted March 26, 2020 Author Share Posted March 26, 2020 1 hour ago, gw1500se said: Since you don't say what ABSPATH is, I am guessing there is a missing '/' in the resulting string. That's not it. There is a trailing / in the ABSPATH. This is line of code in a file that is included for several functions which are currently working as expected, as well as similar instances on other sites I've developed. Quote Link to comment https://forums.phpfreaks.com/topic/310375-issue-with-php-file-used-to-process-a-form/#findComment-1575812 Share on other sites More sharing options...
gw1500se Posted March 26, 2020 Share Posted March 26, 2020 What is line 2 of rankings_navigation_process.php? Quote Link to comment https://forums.phpfreaks.com/topic/310375-issue-with-php-file-used-to-process-a-form/#findComment-1575813 Share on other sites More sharing options...
Jim R Posted March 26, 2020 Author Share Posted March 26, 2020 The file that allegedly doesn't exist... include(ABSPATH ."resources/con.php"); Quote Link to comment https://forums.phpfreaks.com/topic/310375-issue-with-php-file-used-to-process-a-form/#findComment-1575814 Share on other sites More sharing options...
gw1500se Posted March 26, 2020 Share Posted March 26, 2020 echo ABSPATH ."resources/con.php"; Let's look at the resulting string. Then verify that is it correct and if the file does exist, has the right permissions. Quote Link to comment https://forums.phpfreaks.com/topic/310375-issue-with-php-file-used-to-process-a-form/#findComment-1575816 Share on other sites More sharing options...
Jim R Posted March 26, 2020 Author Share Posted March 26, 2020 (edited) 3 minutes ago, gw1500se said: echo ABSPATH ."resources/con.php"; Let's look at the resulting string. Then verify that is it correct and if the file does exist, has the right permissions. It is correct. The file exists. It has the right permissions. It's the same file being used by many other queries in other functions and files on the same site. EDIT: Hold on...I misread what you wrote. Edited March 26, 2020 by Jim R Quote Link to comment https://forums.phpfreaks.com/topic/310375-issue-with-php-file-used-to-process-a-form/#findComment-1575817 Share on other sites More sharing options...
Jim R Posted March 26, 2020 Author Share Posted March 26, 2020 I'm not sure I follow, but with that echo there, this is the result: ABSPATHresources/con.php Quote Link to comment https://forums.phpfreaks.com/topic/310375-issue-with-php-file-used-to-process-a-form/#findComment-1575819 Share on other sites More sharing options...
gw1500se Posted March 26, 2020 Share Posted March 26, 2020 (edited) So it is now clear that ABSPATH is not being substituted the way you expect. How is it defined and where? I don't normally use constants but somewhere you must have a "define('ABSPATH',<whatever>);" but is not executed before that include. Edited March 26, 2020 by gw1500se 1 Quote Link to comment https://forums.phpfreaks.com/topic/310375-issue-with-php-file-used-to-process-a-form/#findComment-1575820 Share on other sites More sharing options...
Jim R Posted March 26, 2020 Author Share Posted March 26, 2020 30 minutes ago, gw1500se said: So it is now clear that ABSPATH is not being substituted the way you expect. How is it defined and where? I don't normally use constants but somewhere you must have a "define('ABSPATH',<whatever>);" but is not executed before that include. That's how WordPress uses it, and the page it redirects from to process the form uses the same file. What should it show when I print that? Quote Link to comment https://forums.phpfreaks.com/topic/310375-issue-with-php-file-used-to-process-a-form/#findComment-1575822 Share on other sites More sharing options...
gw1500se Posted March 26, 2020 Share Posted March 26, 2020 It should show the absolute path (I'm guessing from the name). It should be something like '/var/www/html'. The solution is to not use absolute path but rather relative. Try: include("resources/con.php"); Quote Link to comment https://forums.phpfreaks.com/topic/310375-issue-with-php-file-used-to-process-a-form/#findComment-1575827 Share on other sites More sharing options...
Jim R Posted March 26, 2020 Author Share Posted March 26, 2020 Same error, and I had already tried Require and Require_once. Why would it work in all the other instances but not that one? Quote Link to comment https://forums.phpfreaks.com/topic/310375-issue-with-php-file-used-to-process-a-form/#findComment-1575828 Share on other sites More sharing options...
gw1500se Posted March 26, 2020 Share Posted March 26, 2020 You need to determine where that file is relative to the httpd root. Require and Require_once does the same thing as include. If the path is wrong, it is wrong. Quote Link to comment https://forums.phpfreaks.com/topic/310375-issue-with-php-file-used-to-process-a-form/#findComment-1575830 Share on other sites More sharing options...
Jim R Posted March 26, 2020 Author Share Posted March 26, 2020 At the bottom. con.php. resources menu at courtsideindiana.com. That's where the file is. It's been there for three years, and other places on the site are using it. Meanwhile I use ABSPATH in other locations too in my resources file, and they also are working. It's just this instance that isn't work. Quote Link to comment https://forums.phpfreaks.com/topic/310375-issue-with-php-file-used-to-process-a-form/#findComment-1575831 Share on other sites More sharing options...
ginerjm Posted March 26, 2020 Share Posted March 26, 2020 But where does that constant (ABSPATH) actually get setup? Apparently the set of modules in use during this process is missing something that sets the constant up. Your other uses must be setting it. For some reason this use is not doing that. Something's missing. Quote Link to comment https://forums.phpfreaks.com/topic/310375-issue-with-php-file-used-to-process-a-form/#findComment-1575832 Share on other sites More sharing options...
Jim R Posted March 26, 2020 Author Share Posted March 26, 2020 (edited) 6 minutes ago, ginerjm said: But where does that constant (ABSPATH) actually get setup? Apparently the set of modules in use during this process is missing something that sets the constant up. Your other uses must be setting it. For some reason this use is not doing that. Something's missing. I get what you're saying, but all those instances Include the same con.php file. It's set up with WordPress. Let me see if I can find it... con.php $con = mysqli_connect("localhost","###username","##password", "###database"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } Edited March 26, 2020 by Jim R Quote Link to comment https://forums.phpfreaks.com/topic/310375-issue-with-php-file-used-to-process-a-form/#findComment-1575833 Share on other sites More sharing options...
ginerjm Posted March 26, 2020 Share Posted March 26, 2020 I don't see what that "con.php" code you just posted has to do with this particular constant..... Quote Link to comment https://forums.phpfreaks.com/topic/310375-issue-with-php-file-used-to-process-a-form/#findComment-1575834 Share on other sites More sharing options...
Jim R Posted March 26, 2020 Author Share Posted March 26, 2020 wp-config.php Quote Link to comment https://forums.phpfreaks.com/topic/310375-issue-with-php-file-used-to-process-a-form/#findComment-1575835 Share on other sites More sharing options...
Jim R Posted March 26, 2020 Author Share Posted March 26, 2020 1 minute ago, ginerjm said: I don't see what that "con.php" code you just posted has to do with this particular constant..... I was just posting it so you know what any include I use to connect to my database uses that exact same code. So nothing is different on what I control between what is working and what isn't working. Quote Link to comment https://forums.phpfreaks.com/topic/310375-issue-with-php-file-used-to-process-a-form/#findComment-1575836 Share on other sites More sharing options...
ginerjm Posted March 26, 2020 Share Posted March 26, 2020 Proves nothing. My original post is still the problem you need to research. Quote Link to comment https://forums.phpfreaks.com/topic/310375-issue-with-php-file-used-to-process-a-form/#findComment-1575837 Share on other sites More sharing options...
Jim R Posted March 26, 2020 Author Share Posted March 26, 2020 (edited) 4 minutes ago, ginerjm said: Proves nothing. My original post is still the problem you need to research. I give it the path in the settings which is the base URL, and it accesses the database in the wp-config.php via localhost and my account information. I assume it draws the rest of the actual path, which for this site is /home2/csi/public_html/. I know that to be accurate. I checked it with my server. Edited March 26, 2020 by Jim R Quote Link to comment https://forums.phpfreaks.com/topic/310375-issue-with-php-file-used-to-process-a-form/#findComment-1575838 Share on other sites More sharing options...
gw1500se Posted March 26, 2020 Share Posted March 26, 2020 try this: include("/home2/csi/public_html/resources/con.php"); Quote Link to comment https://forums.phpfreaks.com/topic/310375-issue-with-php-file-used-to-process-a-form/#findComment-1575839 Share on other sites More sharing options...
Jim R Posted March 26, 2020 Author Share Posted March 26, 2020 (edited) 11 minutes ago, gw1500se said: try this: include("/home2/csi/public_html/resources/con.php"); Seemed like that should've been the first thing we tried, but in the past that has triggered errors. A long time ago I was told by WP people not to use that. I don't recall the reason. However, the query still isn't working. $query = "INSERT INTO a_rankings_select (grade,position) VALUES ('" .$grade. "', '" .$position. "')"; I removed the variables from above I'm not ready to insert just yet. Edited March 26, 2020 by Jim R Quote Link to comment https://forums.phpfreaks.com/topic/310375-issue-with-php-file-used-to-process-a-form/#findComment-1575840 Share on other sites More sharing options...
gw1500se Posted March 26, 2020 Share Posted March 26, 2020 You don't say what the error is but that is a different problem. Start an new thread on the MySQL forum. 1 Quote Link to comment https://forums.phpfreaks.com/topic/310375-issue-with-php-file-used-to-process-a-form/#findComment-1575841 Share on other sites More sharing options...
Jim R Posted March 26, 2020 Author Share Posted March 26, 2020 Will do. Quote Link to comment https://forums.phpfreaks.com/topic/310375-issue-with-php-file-used-to-process-a-form/#findComment-1575842 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.