Hey guys help an intern out
I need to connect to a mySQL DB through PHP and print that data on the browser
Please help me with PHP integration with SQL.
Thanks in advance.
Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!
Hey guys help an intern out
I need to connect to a mySQL DB through PHP and print that data on the browser
Please help me with PHP integration with SQL.
Thanks in advance.
Good day Viki and welcome to Geeks to Go,
Hey guys help an intern out
I need to connect to a mySQL DB through PHP and print that data on the browser
Please help me with PHP integration with SQL.
Thanks in advance.
I am certain there are several ways of achieving exactly what you would like to do all differing in their implementations and capabilities. You could go about doing it from scratch, using a library or even an entire framework.
Seeing as you mentioned you're an intern I can assume you would like an easy to understand, easy to implement solution; and I would therefor recommend approaching this by using a library, namely MeekroDB. There might be simpler libraries out there, but I have personally used Meekro and would vouch for its simplicity and ease of use. Again I cannot compare this library to any others and tell you why it's the best, but I can tell you it's as simple as including the library, setting up your connection details and writing the query which puts the results in an array (There's examples on the front page of the site).
I hope this somehow solves your problem, if not please don't hesitate to respond back with a more detailed description of exactly what it is your require from connecting to your MySQL database.
MeekroDB: https://www.meekro.com
Regards,
Spike
Hey Spike,
Thanks a lot for the recommendations, right now i am testing my logic on mysqli and as soon as it works i will switch to a different library.
I am able to successfully run my php but i am unable to figure out how to send the input data from user to the query.
For eg. this function.
function GetVisitors($website){
$data = $website
$sql = "SELECT * FROM visitors where website = :data and last_visit<= NOW() - Interval 7 Day order by last_visit LIMIT 15";
}
I am getting this error: Notice: Trying to get property of non-object in test.php for :website
Please help me send the input passed to function to the sql query.
Thanks.
Edited by viki00762, 02 June 2017 - 08:31 AM.
Hey there again Viki,
If you're set on using mysqli, it'll definitly help you appreciate 3rd party libraries at a later stage but/and still recommend you use something like Meekro.
Although to assist you with your current delema; I am not certain if the code you have posted is final, but I see a few syntax errors.
So lets first deal with the error php is throwing out which is the "property of non-object..." which is a syntax error. You cannot pass parameters when building a string like you're doing with ":data" param, instead you require using the string concat operator which is the period character (.). It's possible you've seen the :param pass in a framework example or something. Some libraries allow you to pass these parameters directly in a function (Eg. query("select * from where field = %s", $param). But for your example the appropriate way is below:
Another "possible" error that could occur in your query depends on the expected type of the $data var... I don't want to make any assumptions about its expected type so have listed both options below depending on what it should be. So to clarify, if the $data var is of type integer or float then use the following query:
$sql = "SELECT * FROM visitors where website = " . $data . " and last_visit<= NOW() - Interval 7 Day order by last_visit LIMIT 15";
On the other hand if the $data var is a string type then remember to encompass your param in single quotes (') like in the query below:
$sql = "SELECT * FROM visitors where website = '" . $data . "' and last_visit<= NOW() - Interval 7 Day order by last_visit LIMIT 15";
This also assume that your query actually runs, I mean by a brief glance you query seems fine, although I always recommend you try run the query stand alone in sql and see if you get results or if you have a sql syntax error. But if you get results then you know you should recieve those same results in php. For example if your $data var is actually a string type and you passed it as an integer then you'd get an sql syntax error.
I did pickup another syntax error which is where you set "$data = $website". It appears you have forgotten to put a semi-colon ( at the end of the line. Remember to put semi-colons.
$data = $website;
Last comment... Again I am uncertain if you posted the final code or if this was just an example for me to get the idea... But I see you have a function which you pass some parameter to (GetVisitors), then you create a $sql var but never do anything with it. In other words you never actually call mysqli to run the query. My assumption is that this is obviously example code.
Please let me know if you need assistance with anything else.
Peace Out,
Spike
Hey Spike,
Although, I am getting 'Mail sent successfully!' whereas I am not receiving the mail.
Kindly help me with this.
Thanks
Good day again Viki,
I am sooo sorry I am only replying now! I'm certain by now, you've probably already resolved your problem...
Just in-case you haven't; your snippet seems fine from first view, although I see the last parameter of your mail() function, you are passing only the "from" email address.... The last parameter is the "header" parameter containing all header information including "from" address... It's usually in the form of:
$header = "From: [email protected]";
You can pass multiple header information such as a carbon copy addresses or even the content type... See w3schools link on mail function for details on usage.
Also not sure about your entire config, but make sure that your sendmail is setup with the appropriate details and works, if that still doesn't work, check your spam box, it could get caught up in there. Another option if you're still struggling with all this is possibly using a 3rd party mail library which allows you to simply provide your email credentials and call a simple function to email.
Sorry again for the late reply... Let me know if you came right or if you're still struggling.
Peace Out
0 members, 0 guests, 0 anonymous users
Community Forum Software by IP.Board
Licensed to: Geeks to Go, Inc.