Jump to content

Search the Community

Showing results for tags 'PHP'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome
    • Announcements & News
    • New Arrivals
  • Web Development
    • Programming
    • Database Development
    • Server Administration
    • Hosting & Domains
    • Frameworks
  • Web Design
    • HTML & CSS
    • Graphics & Multimedia
  • Desktop Discussion
    • Linux Development
    • Windows Development
    • Mac/Apple Development
    • Hardware Discussion
  • Marketing & Business
    • Advertising, Marketing, Monetization & Social Media
    • Search Engine Optimization & Traffic Building
    • Buy, Sell or Trade
  • Prodjex Web Development Applications, Tools and Plugins
    • IP.Board Applications and Plugins
    • Web Tools
  • The Developer Dump
    • General Chat

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests

Found 18 results

  1. WE ALL KNOW THAT THE HTML IS BECOMING NEXT TO THE CUSTOMER AND PHP IS BROUGHT NEXT TO THE SERVER. BUT I WOULD LIKE TO KNOW IF PROGRAMMING ALL THE DATABASE CAN BE DONE IN HTML?
  2. Hello guys, It is my first thread here, I did not intend to make one, but I saw a lot of you are using mysql_connect() mysql_query() please, don't! PDO : PHP Data Objects If you read this article : http://net.tutsplus.com/tutorials/php/why-you-should-be-using-phps-pdo-for-database-access/ you will probably understand why you should be using PDO, and if you still don't, please ask, I will do my best to convert you to use better programming practices
  3. Hand coding forms can be a pain, especially if you have a lot of them to code. I've noticed that there are many "form builder" solutions out there, but most have limitations or aren't what I am looking for. For example, many of the form building tools create a form that emails you instead of saves it in a database. Are there any good form building tools that create PHP code and saves the data to a database, preferably to a customizable set of fields in the database?
  4. MailChimp allows you to create sign up forms with their builder, but they can be a pain to style and for some don’t allow enough customization. The following code is an example of how you can take advantage of the MailChimp API to subscribe new users. Doing this allows you to then create a custom sign up form and style it easily to match your own look and feel. This example assumes you’re only passing the First Name, Last Name, and email of a new subscriber. It’s easy enough to add additional fields, but this will get you started. First you’ll need to setup an API key in your MailChimp account, so login and navigate to Account -> Extras -> API Keys. Once you’ve clicked to create a new API key go ahead and copy the API key and place it in your code. Now you will need to find the list ID. This is not the ID of the list from the URL. You need to go to your lists and in the drop down select settings. Scroll all the way down and here you will find your list ID to replace in the code. You’re all set, now create your form matching the names from the following script and set your form action to “GET”. <?php /** * Created by PhpStorm. * User: Prodjex * Date: 1/31/2018 * Time: 9:04 AM */ //Grab Data Variables Passed From Form $data = [ 'email' => $_GET['email'], 'status' => 'subscribed', 'firstname' => $_GET['firstname'], 'lastname' => $_GET['lastname'] ]; syncMailchimp($data); function syncMailchimp($data) { $apiKey = 'Your API KEY'; $listID = 'Your List ID'; $memberID = md5(strtolower($data['email'])); $dataCenter = substr($apiKey, strpos($apiKey, '-') + 1); $url = 'https://' . $dataCenter . '.api.mailchimp.com/3.0/lists/' . $listID . '/members/' . $memberID; $json = json_encode([ 'email_address' => $data['email'], 'status' => $data['status'], // "subscribed","unsubscribed","cleaned","pending" 'merge_fields' => [ 'FNAME' => $data['firstname'], 'LNAME' => $data['lastname'] ] ]); $ch = curl_init($url); curl_setopt($ch, CURLOPT_USERPWD, 'user:' . $apiKey); curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_POSTFIELDS, $json); $result = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); return $httpCode; } View Blog Post
  5. So this is my first little mini tutorial here. Hope someone will like it/find it useful. Basically what we are going to do is scrape some data from a remote website using PHP and cURL. cURL is a "client URL transfer library" for making all sorts of remote requests and is very useful for many things like getting data, logging in automatically, auto filling out forms etc. Lets get cracking! First and foremost we have to enable the cURL extension as this is not enabled by default. On a Windows machine edit your php.ini file and uncomment ;extension=php_curl.dll and restart your server. If you are using Ubuntu sudo apt-get install php5-curl and restart server. I use a WAMP server at home and it is super easy to install extensions on it simply: Go to icon down in the right corner of your screen->left click WAMPSERVER icon->PHP->PHP extensions->click on php_curl and then restart server. Voila! Alright now we are going to initiate cURL and make a request to another site and display the html with an echo: <?php $url = "http://www.nytimes.com/"; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $result = curl_exec($ch); curl_close($ch); echo $result; ?> Now that we have the html inside $result we can extract the data we are after using regular expressions. In this case I took a regex from http://regexlib.com/ to extract links and modded it just a little bit to make it work. You can just comment out the previous echo $result; and paste these 2 lines in there. preg_match_all("/<a[\s]+[^>]*?href[\s]?=[\s\"\']*(.*?)[\"\'].*?>([^<]+|.*?)?<\/a>/is", $result, $match, PREG_SET_ORDER); print_r($match); This is how this stuff works. Pretty easy basic stuff. You can read more about PHPs cURL support here http://php.net/manual/en/book.curl.php. I especially recommend the curl_setopt part were you can make all kinds of cool stuff like setting an user agent, set referrer, set cookie and a bunch of other stuff to mimic your request coming from an actual user. Any questions or suggestions, just fire away in the thread! More information on cURL: http://curl.haxx.se/
  6. How do I add a date and time to the end of my file upload? Currently I've tried: move_uploaded_file($_FILES["file"]["tmp_name"], "uploads/".$orgid."/".$_FILES["file"]["name"].date("Y-m-d H:i:s")); This doesn't quite work as it appends like this: filename.jpg2014-01-06 12:01:05 How can I do this so that it will be filename2014-01-06 12:01:05.jpg
  7. Is it important to close your database connection at the end of your PHP file? I assumed it closed as soon as the page was done executing, so what would be the benefit in including it in your code?
  8. I'm not sure what to call what I'm trying to do so hard to run a Google search on it. I have a spot where I want to assign team members to a project. There is an input box where I can type their names. As I start typing their name I would like it to query the users table and show possible results, then I can click their name and they are added, then I can start typing another persons name and add multiple people.
  9. PHP for all its sins is a very powerful tool. In terms of speed of productivity, nothing can touch it. Throw some code into a script, upload it and you are done! However this ease comes at a cost: what first appears to be "quick and easy" turns out to be an maintenance nightmare. Writing clean and robust code in PHP is hard. Often times, many newcomers do not always have a background in software engineering. This mixture of ease of use combined with no formal training in clean architecture can lead to "spaghetti code". This is one of the reasons PHP has gotten a bad reputation among professional developers. However with some effort and careful design, this does not have to be the case. In this short tutorial we shall look at writing clean and robust code that deals with databases. All web applications will have certain "settings", or "configurations". A bad approach is to copy and paste these settings all over the place! The clean approach is to place all settings and configurations into one file. This keeps things under control. When you need to make a configuration change, you no longer have to hunt you entire code base. So lets first create a "configuration" file: configuration.php: //================================== // config //================================== define("db_user", "user"); define("db_pass", "password"); define("db_name", "demo"); define("db_server", "127.0.0.1"); Now connection to a database in php is very common, however the code is quite a lot of boiler plate. Also when parameters are used for sql queries these need to be carefully "escaped" to avoid nasty security attacks such as "sql injections" By creating functions, we can encapsulate the core database access functions. This will reduce the code and also make it very clean. The sample below shows the data access functions: data_access.php: //================================== // Data Access //================================== function runSQL($Query) { //connect to server, then test for failure if(!($conn = mysql_connect(db_server,db_user,db_pass))) { print("Failed to connect to database!<br>\n"); exit(); } //select database, then test for failure if(!($dbResult = mysql_query("USE ".db_name, $conn))) { print("Can't use the database.<br>\n"); exit(); } $rs = mysql_query($Query) or die(mysql_error()); mysql_close($conn); return $rs; } function runSQLParms($Query,$Params) { //connect to server, then test for failure if(!($conn = mysql_connect(db_server,db_user,db_pass))) { print("Failed to connect to database!<br>\n"); exit(); } //select database, then test for failure if(!($dbResult = mysql_query("USE ".db_name, $conn))) { print("Can't use the database.<br>\n"); exit(); } foreach($Params as $key => $value) { $Query = str_replace($key,mysql_real_escape_string($value,$conn),$Query); } //echo $Query; $rs = mysql_query($Query) or die(mysql_error()); mysql_close(); return $rs; } In the above data access functions, we have two main functions runSQL and runSQLParms. These two functions are now ready to be used in your projects to cleanly access data. Example: Imagine we have a php file where we are required to do various database actions. First we need know we need the database "configurations" and also our database access functions. Lets import them at the start of the file: sample.php: require_once("configuration.php"); require_once("data_access.php"); Lets say we need to flush some data from a temporary table (we need to execute some sql): function FlushTemporaryData() { $sql = "delete from temp_table"; runSQL($sql); } What if we needed to delete a particular record between say a date range? We would require sql that has parameters. Usually these parameters would be values passed from client side forms. When accepting data from users, there is always a danger of "sql injections". We can safely do it using the second database access function: function DeleteUserLog($UserId, $Start_Date, $End_Date) { $sql = "delete from user_logs where userId = @UserId and log_date between @Start_Date and @End_Date"; $p["@UserId"] = $UserId; $p["@Start_Date"] = $Start_Date; $p["@End_Date"] = $End_Date; runSQLParms($sql, $p); } As you can see the runSQLParms function requires two things: The SQL query, and an array of Parameters. The function will automatically take each parameter and merge it into the SQL query. Also each parameter will be escaped to stop sql injections. Of course, we will often require to get some data back and do things with the result (such as render it as html). lets image we would like to display the top 5 students based on their score: function DisplayTopStudents() { $sql = "select First_Name, Last_Name, Score order by Score desc limit 5;"; $rs = runSQL($sql); $html = ""; while($row = mysql_fetch_array($rs)) { $html = $html . $row["First_Name"] . " " . $row["Last_Name"] . "Score:" . $row["Score"] . "<br/>"; } echo $html; } This is just the tip of the "iceberg". Hopefully you can see how easy it would be to create and maintain these functions. Questions and feedback welcome!
  10. I'm trying to find a good tutorial on how to create a spot on my website that will pull in data from a mysql table and auto update without reloading the page. Something very similar to the funtionality of Facebook's News Feed. I can't seem to find anything. Anyone know of any good tutorial on how to accomplish this in PHP?
  11. My below code isn't returning data for <h1><?php echo($query['id']); ?><h1> What am I missing? <?php //Connect to the Database $host = localhost; $username = db_user; $password = 'pass'; $connect = mysql_connect($host,$username,$password); //Select the Database $db = 'db_pm'; mysql_select_db($db); //Query the needed data $query = "select id,userid,title,description from projects where id=1"; $result = mysql_query($query) or die('Query failed: ' . mysql_error()); ?> <link href="../assets/front.css" rel="stylesheet" type="text/css" /> <?php include("header.php");?> <div class="workplace"> <div class="newprojectbox"> <h1><?php echo($query['id']); ?><h1> </div> </div> <?php include("footer.php");?>
  12. PHP 5.4 has been released. Anyone update their server yet?
  13. So 20 minutes later and all I've done is copied and pasted code from one page to another and it still doesn't work. So I thought 'I know I will start all over again' to start the processes of copying and pasting all over again. Anyone got any ideas to help me: Stick to it Help teach me php Stop me from Copy and Pasting
  14. This is a lesser known framework but I think it deserves more attention because it's by far the most amazing one I've used to date. http://laravel.com/ It teaches good practice too... The "routes" concept encourages you to keep all your logic in models where it belongs.
  15. So this one has been getting to me for a while now.. There is a site that I am trying to log in to, go to a reports page after a successful login, and then download up to 3 reports that are linked on that page. The problem that I'm having is that the reports are randomly named, and I can't get curl to download them. I'll post the html file that the site spit back out to me.. Can someone see how to download the 3 files that are on that page without hardcoding the file name? The 3 reports are named: My Company Invoice Upload_516_146_2012391728360 My Company Invoice Upload_516_146_20123917221402 My Company Patient Upload_516_146_2012391723258 My Scheduled Reports.htm
  16. This following will allow you to upload a .csv file via a web form then insert that data into a MYSQL database. I had a request for it this morning and so now that I have it created I figured I would share. Let me know if you see anything that would be an improvement. Step 1 - Create Web Form <form enctype="multipart/form-data" action="uploader.php" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="100000" /> Choose a file to upload: <input name="uploadedfile" type="file" /><br /> <input type="submit" value="Upload File" /> </form> Step 2 - Create the Uploader.php File <?php // Where the file is going to be placed $target_path = "uploads/"; /* Add the original filename to our target path. Result is "uploads/filename.extension" */ $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); $target_path = "uploads/"; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else{ echo "There was an error uploading the file, please try again!"; } ?> <br><a href="./import.php">Click To Import</a> Step 3 - Create the Import.php File that will insert the data into MYSQL <?php /********************************/ /* Edit the entries below to reflect the appropriate values /********************************/ $databasehost = "localhost"; $databasename = ""; $databasetable = ""; $databaseusername =""; $databasepassword = ""; $fieldseparator = ","; $lineseparator = "n"; $csvfile = "uploads/nameof.csv"; /********************************/ /* Would you like to add an ampty field at the beginning of these records? /* This is useful if you have a table with the first field being an auto_increment integer /* and the csv file does not have such as empty field before the records. /* Set 1 for yes and 0 for no. ATTENTION: don't set to 1 if you are not sure. /* This can dump data in the wrong fields if this extra field does not exist in the table /********************************/ $addauto = 0; /********************************/ /* Would you like to save the mysql queries in a file? If yes set $save to 1. /* Permission on the file should be set to 777. Either upload a sample file through ftp and /* change the permissions, or execute at the prompt: touch output.sql && chmod 777 output.sql /********************************/ $save = 0; $outputfile = "output.sql"; /********************************/ if(!file_exists($csvfile)) { echo "File not found. Make sure you specified the correct path.n"; exit; } $file = fopen($csvfile,"r"); if(!$file) { echo "Error opening data file.n"; exit; } $size = filesize($csvfile); if(!$size) { echo "File is empty.n"; exit; } $csvcontent = fread($file,$size); fclose($file); $con = @mysql_connect($databasehost,$databaseusername,$databasepassword) or die(mysql_error()); @mysql_select_db($databasename) or die(mysql_error()); $lines = 0; $queries = ""; $linearray = array(); foreach(split($lineseparator,$csvcontent) as $line) { $lines++; $line = trim($line," t"); $line = str_replace("r","",$line); /************************************ This line escapes the special character. remove it if entries are already escaped in the csv file ************************************/ $line = str_replace("'","'",$line); /*************************************/ $linearray = explode($fieldseparator,$line); $linemysql = implode("','",$linearray); if($addauto) $query = "insert into $databasetable values('','$linemysql');"; else $query = "insert into $databasetable values('$linemysql');"; $queries .= $query . "n"; @mysql_query($query); } @mysql_close($con); if($save) { if(!is_writable($outputfile)) { echo "File is not writable, check permissions.n"; } else { $file2 = fopen($outputfile,"w"); if(!$file2) { echo "Error writing to the output file.n"; } else { fwrite($file2,$queries); fclose($file2); } } } echo "Found a total of $lines records in this csv file.n"; ?> For this to work correctly all you need to do is put all 3 of these .php files in the same directory and create another directory within called "uploads".
  17. I'm trying to figure out how to use this code, but it's not working right. This query works fine: $var1= $_POST['user']; $var2 = $_POST['order']; //Connect to the Database $host = localhost; $username = user; $password = pass; $connect = mysql_connect($host,$username,$password); //Select the Database $db = 'devwp'; mysql_select_db($db); //Query the Needed Data $query = 'select distinct pm.meta_value from wp_shopperpress_orders o inner join wp_posts p on left(o.order_items, instr(o.order_items, "x")-1) = p.id inner join wp_postmeta pm on p.id = pm.post_id'; $result = mysql_query($query) or die('Query failed: ' . mysql_error()); I want to modify it to have a where clause in the query, but the code I'm trying to do fails. I'm trying to have $var2 filter in the where clause. $var1= $_POST['user']; $var2 = $_POST['order']; //Connect to the Database $host = localhost; $username = user; $password = pass; $connect = mysql_connect($host,$username,$password); //Select the Database $db = 'devwp'; mysql_select_db($db); //Query the Needed Data $query = 'select distinct pm.meta_value from wp_shopperpress_orders o inner join wp_posts p on left(o.order_items, instr(o.order_items, "x")-1) = p.id inner join wp_postmeta pm on p.id = pm.post_id where o.order_id = ' . $var2; $result = mysql_query($query) or die('Query failed: ' . mysql_error());
  18. Nathan

    PHP Line Break

    So I'm very new to PHP and trying to learn a few thing. I'm trying to keep all my code standard. What's the correct way to do a line break in PHP? Such as </br> in HTML? This is how I'm currently doing it: <?php echo $data[0]->like_count; print "<p>Thank you for your purchase!</p>"; ?>
×
×
  • Create New...