Showing posts with label php. Show all posts
Showing posts with label php. Show all posts

PHP: Insert data from form and another table in the same table

Wednesday, November 4, 2015

I want insert data from form and another table where inv_id = "'.$inv.'" in the same table "history" ($inv is data input from form) (sorry for my bad english)



Actually my query:



$query2 = "INSERT INTO istoric SET id_user = '".$user."',id_equipment = '".$nr_inv."',start = '".$startdate."',end = '".$enddate."',comment = '".$comment."'"; 
$id = "INSERT INTO `istoric`(`condition`) SELECT `status` FROM `echipament`WHERE `nr_inventar` = '".$nr_inv."'";


How to combine two query? Now this query insert data in two rows different.
Imagine with history table: link

502 Bad Gateway with Zend Debugger (nginx+php5-fpm) and PHPStorm

I'm trying to set up the debugging on a server but it won't work.



Here is my setup:




  • Nginx with PHP 5.5.9 (fpm, unix socket) @ 192.168.1.40

  • Network share with source code @ 192.168.1.50

  • The network share is mounted on the webserver at /shared/www/

  • My project is located under /shared/www/myProject and get accessed by http://myProject.local/

  • Zend Debugger is installed, the following is from the php.ini:


    zend_extension="/usr/lib/php5/20151104/ZendDebugger-5.5.x-64bit.so"
    zend_debugger.allow_hosts=192.168.1.0/24,127.0.0.1
    zend_debugger.expose_remotely=always



  • The website is working as intended and I don't have problems there.

  • My workstation has the IP 192.168.1.10



Now my PHPStorm settings:



File -> Settings -> Languages & Frameworks -> PHP




  • PHP language level 5.5

  • Interpreter: 192.168.1.40 (I get correct PHP-Version; Debugger: Zend Debugger, correct configuration file)



File -> Settings -> Languages & Frameworks -> PHP -> Debug




  • Zend Debugger port = 10137

  • [x] Can accept external connections



File -> Settings -> Languages & Frameworks -> PHP -> Server



New server added: 192.168.1.40:80 - Zend Debugger



[x] Use path mappings:
File/Directory: \192.168.1.50\shared\www\myProject



Absolute path on the server: /shared/www/myProject



I've configured zDebug for Chrome this way:




  • Debug Host: 192.168.1.10

  • Debug Port: 10137

  • [x] Check for Zend Debugger Cookie

  • [x] Use Fast File

  • [x] Debug Local Copy

  • [x] Disable Right-Click






Now with the config out of the way here is my problem with the debugging:



If I click on "Debug this page" (doesn't matter if I use the marklets or the Chrome extension) the site loades a minute or so and I'm getting a 504 Gateway Timeout from nginx.



Now if I click on the "Start Listening for PHP Debug Connections" (for zero-config debugging) and try the debug again, I'll get instantly a 502 Bad Gateway.



I really have no idea why I'm getting this error. Nginx error logs say this:




2015/11/04 18:11:05 [error] 4613#0: *107 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 192.168.1.10, server: 192.168.1.40, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "192.168.1.40"




If I disable the debugging there is no error at all.



Does someone has any ideas about this problem? I've searched all PHPStorm documentation but to no avail.



Thank you!

Inserting unique value from one table to another table

I have table with attributes ticket number and category. I need to insert data from this table into another table with ticket number as primary key.



What I need is if table 1 contains two entry for same ticket number, than I have to update the second table.



How do I go about doing this?

is there ViewModels in CakePhp like .Net MVC?

I'm developing a web application with Cakephp and I have a complex view with complex forms, I come from .NET MVC world and I used something called 'ViewModels' they are very friendly to make extremely custom views well formed and supported for back-end validations. I understand that in cakephp I can use non persistent models using



$useTable = false;


But I would like to make relationship between that non persistent model with another model (persistent or not) to make validation and have custom validations.

MySQLi Prepare statement

Clearly there something I miss when I try to do my prepare statement for a SELECT query.



Can any body tell me how the correct version is:



$db = new mysqli($config_databaseServer, $config_databaseUsername ,$config_databasePassword, $config_databaseName);

if(isset($_POST['queryString'])) {
$queryString = $db->real_escape_string($_POST['queryString']);

if(strlen($queryString) >3) {

$numberOfProducts = $_POST['numberOfProducts'];
$numberOfBrands = $_POST['numberOfBrands'];
$query = $db->prepare("SELECT name, image_url FROM `".$config_databaseTablePrefix."products` WHERE name LIKE '?%' LIMIT ?");
$query->bind_param('ss', $queryString, $numberOfProducts);
$query->execute();
if($query) {
while ($result = $query ->fetch_object()) {
code continues..


Error:



Warning: mysqli_stmt::bind_param(): Number of variables doesn't match number of parameters in prepared statement



Fatal error: Call to undefined method mysqli_stmt::fetch_object()



I only see I have two variables ?

Unable to get LinkedIn library to work

I have tried to use this LinkedIn library



https://github.com/CuelogicTech/social-media-api/tree/LinkedIn


I got the link from this article here:



http://www.cuelogic.com/blog/manage-linkedin-profile-using-linkedin-api-with-oauth-2-0-3/


However, it seems to be outdated, buggy and not working anymore.



For example, in the linkedin_app.php file the file in require call require_once('LinkedIn.OAuth2.class'); miss the .php extension.



Can somebody suggest a similar simple LinkedIn library I can use with PHP to share messages on LinkedIn?



My app is authorized I got all the tokens and w_share scope. I just need to find a simple PHP library that will offer some functions to post to linkedin profile some messages from the script instead of writing everything from scratch.

Add imap extension to PHP on OSX El Capitan

I'm working on a project where I need imap_open() function and I just bought my first Macbook Pro with OSX El Capitan on it.



I activated the extension in php.ini but the .so file is missing, searching on how to install imap extension doesn't work on El Capitan and while compiling I get error osdep.c:170:10: fatal error: 'x509v3.h' file not found



Anyone know what should I install in order to get that header file or is there any easy way to install extension like on Linux (yum install php5-imap, apt-get install php5-imap) ?

url rewrite with blog url included

I need to configure my website with blog for url rewriting. to make it seo friendly i have placed url rewrite, where it count www.amadcrew.com and http://www.amadcrew.com saperate urls. following is the code which made it working perfectly.



# Redirect to www location
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^amadcrew.com [NC]
RewriteRule ^(.*)$ http://www.amadcrew.com/$1 [R=301,NC]


but some how i am unable to run my blog which url is .amadcrew/madcrew_blog. before it was working perfectly and now there is a white page i see.



kindly help me for url rewriting for seo friendly.



thanks

How to delete cookie with HttpOnly using PHP or JS

I have a cookie with these parameters:



Name:   workgroup_session_id
Content: ""
Domain: agrobman1.tsi.lan
Path: /
Send for: Any kind of connection
Accessible to script: No (HttpOnly)
Created: Wednesday, November 4, 2015 at 9:31:58 AM
Expires: When the browsing session ends


I have tried to delete the cookie using PHP using this code:



setcookie("workgroup_session_id", "\"\"", time() - 3600, "/", "agrobman1.tsi.lan", false, true);


But I am still unable to delete it. Does anyone know how to delete a cookie of this type using PHP or JS?

What is some code I could use to download the WWW [on hold]

By WWW, I mean all HTML files currently existing on the Internet, in any order. I need this problem solved using PHP. No Images, at this time... Just .HTML Documents.



Regardless of how long it will take, I would like to see something that could logically do it.



For example, I could use Curl to scan IP Addresses for index.html and download.

MySQL rows to a PHP class array

I have a class that i made, class art in PHP. I want to copy data from a MySQL table to an array of class art objects (array size varies depending on the tables number of rows).
The table containing the data has the same structure as my class art.



SHORT VERSION: Is it possible to create an array of art objects in PHP and how do I do that?



Here's the class that I have:



<?php

class art {
var $title='';
var $body='';
var $category='';
var $date='';

function does_whatever() { }
}
?>


Here's the mysql and code that should add each row of data as an 'art' object to an array:



    $mysqli = new mysqli("localhost", "root", "", "blog");
$query = "select * from article";
if ($result = $mysqli->query($query))
{
while ($obj = $result->fetch_object())
{ //create the array of art type objects and add data to them
}
}


edit: i will eventually sort the array and echo the newest 5 articles

How to code "like" button in php?

I am developing web application and want to code "like" button like how Facebook designed. I wanted to store the user information in MySQL database. I was trying this by using Java script and ajax with php. But I got 'alpha numeric' problem while store the user information.

\http\client\Request - set cookies from http response

I use pecl_http 2.xx library to do HTTP requests from PHP scripts.
The problem is that i cannot correctly re-send cookies supplied by server on a new response.



My code:



$request = new \http\client\Request("GET", "http://1", $custom_headers);
$client = new \http\client();
$client->enqueue($request)->send();
$re = $client->getResponse($request);

$cookies = $re->getCookies();

$request = new \http\client\Request("GET", "http://2", $custom_headers);
$client = new \http\client();
$client->enqueue($request)->send();
$re = $client->getResponse($request);


I have tried passing cookies as array to setOptions() (cookies key), using \http\client\request::setCookies() but nothing seems to work - cookies are not sent with second request.



I have also tried using one client instance for two requests but this did not help, cookies are not re-sent.



source code of this library seem to be bad-written and not pretty to solve my problem.



Documentation lacks samples on keeping cookies between requests.



Thanks for suggestions

Wampserver doesn't recognize php_oci8_12c.dll

I can't connect to oracle using wampserver php if php.ini include extension=php_oci8_12c.dll instead of extension=php_oci8_11g.dll.
When I run a PHP scripts I get This connection error:




"Fatal error: Call to undefined function oci_pconnect() in
c:\wamp\www\PHPScript1.php"




Since the installation did not include php_oci8_12c.dll file I tried several files I found, versions 5.5.4.0 , 5.6.2, 5.6.11, 5.6.14. None worked.
The file that worked was php_oci8_11g.dll version 5.5.12.
Oracle Server, Client, Apache and PHP are on the same windoes server.
Installation file: wampserver2.5-Apache-2.4.9-Mysql-5.6.17-php5.5.12-64b.exe.



Software and hardware details:



Wampserver (64 bits & PHP 5.5) 2.5  
Apache : 2.4.9 MySQL : 5.6.17 PHP : 5.5.12 PHPMyAdmin : 4.1.14 SqlBuddy : 1.3.3 XDebug : 2.2.5

Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
Full oracle client Version 12.1.0.2.0

OS Name Microsoft Windows Server 2012 R2 DataCenter
Version 6.3.9600 Built 9600
System Manufacturer VMware Inc.
System Type x64-based PC

Upload Laravel 5.1 to Shared host

I have a Laravel 5.1 Project on my localhost (Apache) and I uploaded to my Shared Host via FTP (previosuly I was doing my last composer update locally).




  1. I was upload all files from my local server to shared server

  2. I was dump my database from my local server to my database on sharedhost

  3. I was config my .ENV file with the right configuration

  4. I was config my Virtual Host to point /public, (I paste the virtual host config here)



Virtual Host Configuration



<VirtualHost 194.140.166.118:80>
DocumentRoot /var/webs/dilemy.com/html/public
ServerName www.dilemy.com

ServerAlias dilemy.com

AssignUserId dilemycom dilemycomgroup

MaxClientsVHost 30

# awstats support
<Files "awstats.pl">
AuthUserFile /var/webs/dilemy.com/.awstats-passwd
AuthName "dilemy.com Stats"
AuthType Basic
require valid-user
</Files>

ErrorLog /var/webs/dilemy.com/logs/error.log
CustomLog /var/webs/dilemy.com/logs/access.log combined




When I try to access to my site www.dilemy.com it appears this errors from my errors.log



[Wed Nov 04 18:43:40 2015] [error] [client 88.10.131.34] PHP Parse error:  syntax error, unexpected 'class' (T_CLASS), expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$' in /var/webs/dilemy.com/html/public/index.php on line 50


The structure of my Shared Host is like this:



/var/webs/dilemy.com


enter image description here



Thr structure of my project inside the /html directory is like this:



/var/webs/dilemy.com/html


enter image description here

google oauth2 server localhost

I have a virtual localhost (http://server.ehc.localhost) and I want to use the Google oauth in PHP.



In console (https://console.developers.google.com)
APIs&auth->credentials->myproject->credentials:



http://server.easyhomecosts.localhost:8081
http://server.easyhomecosts.localhost



I have always get the same error.




Authorized redirect URIs
Must have a protocol. Cannot contain URL fragments or relative paths. Cannot be a public IP address.




this is my code in php file



$client = new Google_Client();
$client->setClientId(CLIENTID);
$client->setClientSecret(CLIENTSECRET);
$client->setRedirectUri('http://server.easyhomecosts.localhost:8081');
$client->addScope("email");
$client->addScope("profile");
$service = new Google_Service_Oauth2($client);
$authUrl = $client->createAuthUrl();
echo '
';
echo '

Login with Google -- Demo

';
echo '';
echo '
';


the url generated is https://accounts.google.com/o/oauth2/auth?response_type=code&redirect_uri=http%3A%2F%2Fserver.easyhomecosts.localhost%3A8081&client_id=CLIENTID&scope=email+profile&access_type=online&approval_prompt=auto



I click on the link and I have always:




error: invalid_request Invalid parameter value for redirect_uri: Non-public domains not allowed: http://server.easyhomecosts.localhost:8081




Is it possible to use my localhost server?

Update prices in wordpress external link

I want the prices to be updated from this website http://bit.ly/1dJUrA5 to my website of the product's i choose . would that be possible for you to do . where my website is based on word press Please anybody can help me please.

Wordpress htaccess rewriterule for custom tab urls

I've done this a dozens times outside of wordpress but for some reason I can't get it to work in wordpress and not sure why. Here's what I'm trying to achieve.



The page http://wordpress.dev/digital/ has tabbed content, the tabs are books, movies, magazines, etc.



User visits url http://wordpress.dev/digital/movies/



Display the digital page with the tabbed content, but instead of showing the default 1st tab, the movies tab is shown. The url stays the same in the browser but now wordpress sees http://wordpress.dev/digital/?tab=movies. So on my digital page I can check what tab the user is trying to view and make that tab visible.



Here's an example of code that's not working on wordpress but I've used before on static sites. Perhaps this wouldn't work on a static site either, but I've done this before using a similar rewrite rule.



RewriteRule ^digital/(movies)[/]?$ http://wordpress.dev/digital/tab=$1 [L]

joomla external sign in

I am trying to login to the main joomla site from a xenforo site in the subdirectory of the joomla site i.e. www.joomlasite.com/xenforo/index.php?login/login
i have writtent the following code to login to the site:
xenforo login modification:



url = 'http://www.joomlasite.com/xenforo_login.php';
$fields = array(
'username' => urlencode($data['login']),
'password' => urlencode($data['password'])
);

//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');

//open connection
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);

//execute post
$result = curl_exec($ch);

//close connection
curl_close($ch);


and xenforo_login.php file in www.joomlasite.com/xenforo_login.php is as follows:



    define( '_JEXEC', 1 );
define('JPATH_BASE', dirname(__FILE__) );
define( 'DS', DIRECTORY_SEPARATOR );

require_once( JPATH_BASE .DS.'configuration.php');
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
require_once ( JPATH_BASE .DS.'libraries'.DS.'joomla'.DS.'factory.php' );

/* Create the Application */
$mainframe =& JFactory::getApplication('site');
jimport('joomla.plugin.helper');
jimport( 'joomla.user.user');
jimport( 'joomla.session.session');

$credentials = array();
$credentials['username'] = $_REQUEST['username'];
$credentials['password'] = $_REQUEST['password'];
//print_r($credentials);exit();

//perform the login action
$error = $mainframe->login($credentials);
$user = JFactory::getUser();


Now the issue I am facing is the code gives me the user but it does not login the user in the www.joomlasite.com nut the user is logged in www.joomlasite.com/xenforo
Can someone please help me asap!

Laravel Chumper Datatables Post AJAX update

I am trying to use Chumper datatables in my project. Now I have a column with delete row. Basically, which deletes a row if you click it. But when you click it, it, there's a connfirmation dialogue box which asks if you're sure to delete it.



Now it works if I do not use any AJAX call after first page content load and row id is posted to the controller method.



But if I sort or filter the data using the search box, the id is not extracted.
That means that when new content is loaded, the id and other data of new elements is not being taking properly by the jquery method:



function confirmation() {
$('.delete').on('click', function(e) {
e.preventDefault();
var el = $(this).parent();
var data = el.attr('data-form');
console.log(data);
$('.myModal').find('.confirm').attr('data-form', data);
});
$('.myModal').on('click', '.confirm', function(e) {
var id = $(this).attr('data-form');
console.log(id);
window.location = "{{URL::route('deleted.success') .'/'}}" + id;

});
}
$(window).load(function() {
confirmation();
});


When new data is loaded and delete is clicked, instead of id (loaded in data-form) it says undefined. How to get correct ID here after AJAX call?