I've been developing a news letter system locally and everything works fine . The mystery begun when I uploaded the whole content to my server , I could see the index page but when I enter the username / Password to log in (in the index page), I get redirected to "authenticate.php " where the Post data are processed this way :
<?php include("includes/initialize.php");
if(!isset($_POST['username']) OR !isset($_POST['password']))
{
// no data were given
redirect_to("error.php");
}
elseif(!$user = User::authenticate($_POST['username'],$_POST['password']))
{
// user not found in the database
redirect_to("error.php");
}
else {
$session->login($user);
redirect_to("enewsletter.php");
}
?>
On this page I get stuck (not on localhost ) , the server is rendering a blank page . after some tests , I tell you what happens : If I fall in the if situation i get redirected to error.php , but when I enter some credentials , It's doing nothing :/
So I added an echo statement to keep trace of the code :
and I had this remark, every time the script meets to a line containing a method that looks in the database (OOP approach) the server is always rendering blank pages , I tried it on many pages and it's always the same . I changed the database connection type from PDO to mysqli (because I thought the server is not supporting PDO) but no change !!
Does any one has a clue , what could be the reason?
well ,
it was just a " Self instead of self " problem ...
Thank you all for your help ;)
Related
I am trying to setup a PHP document but I currently am looking for a way to use the die() function and display some content on every page using my global configuration file. The way I am think how it should work is that IF the requested URL (e.g. domain.com/services/disabledservice) would have /services/disabled service and a value of 1 to make the value true in a MYSQL DB.
The plan is to have the URL be collected and checked with a table than if the row has a value of 1 for status it will display a disabled page message but if it’s 0 it will load normally.
Some research I have conducted may lead be to think that using the SQL query and the if function could work for this.
The idea I have is this but it may not be correct.
<?php $pageurl = [requested URL content here]
$checkstatus = "SELECT * FROM servicestatus WHERE page =" . $pageurl . "AND status = 1";
if ($status = mysqli_query($conn, $servicestatus)) {
if (mysqli_num_rows($status) = 1) { ?> html content here
<?php }
} else { ?>
page as normal
<?php } ?>
Edit:
To explain what I am trying to do.. I am trying to fetch the URL without everything past “?” Than I am trying to use that in a DB query to check with the database if that has a value of “m” or “d” and if it has one of those values next to the URL which is being fetched it will display the appropriate error page. This is being included as part of my core configuration file which includes my “$conn” and the core values for most stuff. The problem I am facing is that when I send my URL without everything past the “?” I am not receiving my error page and everything is loading like normal.
Use any one the following php functions:
include 'path_to_the_page.php' (or) require 'path_to_the_page.php';
The difference between include and require arises when the file being included cannot be found: include will emit a warning ( E_WARNING ) and the script will continue, whereas require will emit a fatal error ( E_COMPILE_ERROR ) and halt the script.
Well I build a form in html but I am unable to connect and collect data from the form to a database. Here is the code I used to connect and collect data from the form.
The HTML form -> https://drive.google.com/file/d/0B4eL9qVqrm2OOWpMZmV1dUlNbTg/view?usp=sharing
The PHP connect file ->
https://drive.google.com/file/d/0B4eL9qVqrm2OY2pDR09nb0w5bE0/view
The PHP database file ->
https://drive.google.com/file/d/0B4eL9qVqrm2OeU5IdVMxVHBkaVk/view
It returns the code back on clicking submit.
<?php include 'NENDatabase.php';?>
<?php
$Your_name=$_POST['Your_Name'];
$email=$_POST['Your_Email_ID'];
$Message=$_POST['Type_your_Message'];
$Gender=$_POST['sex'];
mysqli_query($connect, "INSERT INTO Visitors(Your_Name,Your_Email_ID,Message,sex)
VALUES('$Your_name','$email','$Message','$Gender')");
if(mysqli_affected_rows($connect) > 0){
echo "<p>People visited</p>";
echo "Go Back";
} else {
echo "People Added<br />";
echo mysqli_error ($connect);
}
?>
I have no idea about collecting data into databases and used the php codes from tutorials online. Still the code doesn't run. Any help or push in the right direction will be very helpful.
Found two errors
Error 1 - change form method to post, because php code uses $_POST
Error 2
mysqli_query($connect"INSERT INTO Visitors(Your_Name,Your_Email_ID,Message,sex)
VALUES('$Your_name','$email','$Message','$Gender')");
function parameters not seperated by comma, so change it to
mysqli_query($connect,"INSERT INTO Visitors(Your_Name,Your_Email_ID,Message,sex)
VALUES('$Your_name','$email','$Message','$Gender')");
Hmm the problem was not with the code but with the url path that I was using. I just had to change the paths to localhost/filename.php or localhost/site.html so that it is actually hosted and run on the localhost server. You can also use absolute servers instead of localhost. (And make sure all your files are in HTACCESS folder under xampp directory of mysql)
I am having an issue with my adding a new member page,, also having an issue with my login page which is similar in code. Both worked fine, tested multiple times and ways and then I switched hosting companies. The rest of the database driven site works fine still except this part. Have no idea why and possibly just need fresh eyes on it. I am fairly new to php and mysql to begin with,,, then attempting to learn the newer versions to keep my code upgraded has me at this point unable to figure out why the code is no longer working. Any help would be much appreciated. Thanks.
The page will run up to this point,, I have confirmed that using echo, then it fails. The page itself, does not load, justs stays completely blank and the little loading wheel in the tab corner just spins and spins.
$sql="SELECT * FROM table WHERE field LIKE'$username'";
$rs=$db->query($sql);
$arr = $rs->fetch_all(MYSQLI_ASSOC);
// test to make sure there was not an issue loading the db
if($rs != true) { // start second if in nested section
// if any errors in reading the db redirect to a general db is down error page
//close db connection
mysqli_close($db);
// redirect header goes here, removed for this post
} else { // else to go with second if
// get number of rows returned in this case should be 0 or 1
$rows_returned = $rs->num_rows;
echo "num of rows are $rows_returned";
} // end second if
Whilst moving from one host to another (to hostgator) we've received many errors. We did have a news editor edit code error once we moved, but we've fixed that. Now, we have an error updating data in page editor.
It can pull/select data and says saved, but it doesn't update the data in mysql.
Hosting error? was working before.
»Events Page
»Jobs Page
»Maintenance Page
»Staff Page
Thank you,
Maybe your previous host had autocommit=on, meaning you do not have to COMMIT.
Try a COMMIT statement at the end of each data update to actually save the data
echo("The CMS for the credits page has been updated!");
is just the php saying what you want it to say, it did not actually go into the database and check...
use
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
else
{
echo("maintenance page updated");
}
to identify that your query is working fine or not
Hoping some of you out there are great with php!
Basically the guy who made this is MIA so I can't ask him what I need to do to fix the problem we are having.
Background:
We are a locksmith company that uses a custom web app to inform our locksmiths on the road when they have a new job. This web app also does a few extra things like providing gps location, time taken at the job and the ability to have save signature from the client upon work completion.
Problem:
The app works by picking up an email sent from our account management application called E3, the email (example: http://cl.ly/image/2E433O330T0N) is read by this web app, parsed into both an email and a web page and sent to the locksmith to view his new job. When the locksmith arrives at the web page on his phone (example: http://cl.ly/image/0P1I0R0h0O3K), he can see the job details including the Name, address and contact details for the client. The problem is though, because Job Notes isn't assigned a heading in the original email the code has to work out where Job Notes is located, this is the part that has the problem as the web app is no longer showing the data in Job Notes. Job Notes is important because it tells the locksmith what he needs to fix. This worked previously but has now just stopped working and we aren't sure why.
How the data is transferred to the web app is very interesting, instead of having a database to store data to, it is put in the address bar and then the webpage interprets the code and formats it into the page.
For example, this is how the current link looks (data taken out, replaced with xxxxxxx):
http://www.xxxxxxx.com/apps/xxxxxx/on-my-way?client=xxxxxx&company=xxxxxx&mobile=xxxxxxx&phone=xxxxxxx&contact=xxxxxxxx&addressData=Array&addressIndex=3&streetAddress=xxxxxxxxx&addressLocality=xxxxxxxx&postcode=xxxxxxx&city=xxxxxxx&clientEmail=&jobDate=11/22/2012&jobTime=1:30:00%20PM&jobID=xxxxxx&jobAMPM=PM&adminEmail=xxxxxxx&noreplyEmail=xxxxxxxxxx&companyPhone=xxxxxxxx&staffEmail=xxxxxxxx&staffName=xxxxxxx&staffPhone=xxxxxxxx
Previously, when working, this link had a jobNotes field added:
http://www.xxxxxxxx.com/apps/xxxxxxxx/on-my-way?client=xxxxxxxx&company=xxxxxxxx&mobile=xxxxxxxx&phone=&contact=xxxxxxxx&addressData=Array&addressIndex=4&streetAddress=xxxxxxxx&addressLocality=xxxxxxxx&postcode=xxxxxxxx&city=xxxxxxxx&clientEmail=xxxxxxxx&jobNotes=Quote%20on%20installing%20new%20keying%20system%0A%0AAlso%20would%20like%20a%20Quote%20on%20Install%20CCTV%0A%0ASub%20Total%3A%202%2C236.36%0AGST%3A%20223.64%0ATotal%3A%202%2C460.00%0A%0AMISC&*jobDate=11/19/2012*&jobTime=2:00:00%20PM&jobID=xxxxxxxx&jobAMPM=PM&adminEmail=xxxxxxxx&noreplyEmail=xxxxxxxx&companyPhone=xxxxxxxx&staffEmail=xxxxxxxx&staffName=xxxxxxxx&staffPhone=xxxxxxxx
The code:
This is an extract from e3-parser.php, the main file that translates the data from the e3 email to the web app.
// Job notes
if ($this->clientEmail) {
// REMOVED NOW THAT EMAIL IS BEING PUT ON THIRD LINE OF ADDRESS
// // If customer email present grab everything after it save it as job notes
// preg_match("/$this->clientEmail[^-]+/",$e3Output,$matches);
// $result = implode("",$matches);
// $notes = trim(str_replace($this->clientEmail,'',$result));
// $this->jobNotes = rawurlencode($notes);
// } else {
// Fall back to grabbing everything after the time
preg_match("/AM[^-]+/",$e3Output,$matchesAM);
preg_match("/PM[^-]+/",$e3Output,$matchesPM);
$resultAM = implode("",$matchesAM);
$resultPM = implode("",$matchesPM);
$notes = trim(str_replace('AM','',$resultAM) . str_replace('PM','',$resultPM));
$this->jobNotes = rawurlencode($notes);
}
Question here is, does it successfully grab the data listed after the Required Time field? (example email that it's reading from: http://cl.ly/image/2E433O330T0N)
Here is the code that places the parsed data into the web page:
// Create job link
$url = $e3->create_job_url('http://www.prvgroup.com.au/apps/jobbook/on-my-way?');
$linkName = "View job details";
$href = '<a class="btn btn-small" href="' . $url . '&staffEmail=' . $staff- >staffEmail . '&staffName=' . $staff->staffName . '&staffPhone=' . $staff->staffPhone . '">' . $linkName . '</a>';
This is sent to the locksmith via email informing him of his new job on the clickable link "View job details". The link is impregnated with the data needed. However from the looks of it the data for jobNotes isn't there. My backups of this code display the exact same thing here when the code was displaying jobNotes so I'm not exactly sure how it is putting that field in.
If you got this far, well done! I hope I was clear enough with what the issue is but if you need anymore clarification, just ask!
Cheers,
Marc
After looking through your code you are only running the preg_match if there is a clientEmail. From the sample emails above it does not look like you are ever executing this code because there is no client email or it is not found using the preg_match. The specific location to look into is on line 113 of the e3-parser.php file. You will see this:
if($this->clientEmail)
{
//matching code here.
}
on line 109 and 110 you are looking for an email address and either not finding one or it is looking in the wrong location. At any rate, you should execute this code regardless of whether there is an email address or not. The notes must be set for later use, right now nothing is being set. Removing this if statement should resolve your issue.