Jump to content

Cannot Execute Query in PHP, Executes in PhpMyAdmin


BloodyMind

Recommended Posts

Hi there,

I've tried this script for uploading and inserting projects details in the database

but this query doesn't work as u see i've tried all kinds of methods to write a query into php

I also echo the query and copy and paste it in PHPMyAdmin and it executes there perfectly

but it doesn't wanna work on php

if anyone got help please reply me ASAP

 

<?php
public function addProject($in_projectName,$in_projectDesc){
	try {

//			$user_id = $_SESSION['user_id'];
		$user_id = '1';

		// get filename here
		$projectsDir = 'c:/wamp/www/computek/projects/';

		$filename = Handles::uploadHandle('projectFile',$projectsDir,'Cannot upload Project.');

		$parts = explode('/computek',$filename);
		$filename = $parts[1];
		// verify the zip file
		if (substr($filename,-4,4)!=='.zip') {
			throw new Exception('We can only accept ZIP file format.');
		}
		$filename = urlencode($filename);
		echo $in_projectName;
		echo "<br/>";
		$prosql = <<<EOP
INSERT INTO projects(pro_title,pro_file,user_id) VALUES('$in_projectName','$filename','$user_id')
EOP;
		echo $filename;
		echo "<br/>";
		/*
		$prosql = sprintf("INSERT INTO projects(pro_id, pro_title,pro_filename,user_id)
		 VALUES('NULL','%s', '%s', '%d')",$in_projectName,$filename,$user_id);*/
		// insert project's details into the projects table
		/*$prosql = "INSERT INTO projects(pro_title,pro_filename,user_id)
		 VALUES('" . $in_projectName . "', '" . $filename . "', '" . $user_id . "');";*/
/*			$prosql = <<<EOPRO
INSERT INTO projects SET pro_title='{$in_projectName}',pro_filename='{$filename}',user_id='{$user_id}';
EOPRO;*/
		echo $prosql;
		echo "<br>";
		$results = $this->conn->query($prosql);
		if ($results == FALSE) {
			throw new Exception('Cannot Execute Project Query');
		}
}
?>

 

Thank you in Advance

Link to comment
Share on other sites

this is just a part of a function in a class

but i just put the part with the bug just not to confuse you with alot of code!

if you'd like me to paste all the class it's okay but i use this function solely it just used the file handle static method that returns the uploaded file and i have no problem with it

 

the point is that I execute this query in PhpMyAdmin and it works and not working on the script itself !!

 

I've copied and pasted this query from php and pasted it in phpMyAdmin and it works

 

I'm losing my mind seriously

 

and I have rewritten it in several methods including spritntf(), heredoc and concatenation of vars and nothing is happening but catching this exception

 

 

 

Link to comment
Share on other sites

Well, maybe we can narrow down the possibilities.

 

First, are you sure that $this->conn is set at the point when this code runs?  Try doing this right before you run your query:

 

print_r($this->conn);

 

if $this->conn is set, you should see a line that tells you what kind of object that variable houses.

Link to comment
Share on other sites

The Problem solved

It was the WAMP Server was hallucinating I reinstalled it and it works just fine.

 

Thanx for trying to help and I have an advice for anyone who donesn't know it already

 

WAMP Server is just for learning purposes

 

but is XAMMP good?!!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.