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) ?