We help IT Professionals succeed at work.
Get Started

MySql query not returning results

Last Modified: 2014-03-09
I am trying to code a query whereby the query checks for duplicate items in a table and if found sends an error back to jquery. However, what is happening, is that jquery keeps giving me a typeError and I cannot see why. In my posted code, the code that is commented out, /* if ($box == 'DEMO111') works fine but not my query.

All mysql connections are working and I can connect to the db.

I would be grateful if someone could check my code and show me where I have gone wrong. Thanks


$array = split('[,]', $_POST['box_add']);
$boxerrortext = 'No duplicate boxes';


if (isset($_POST['submit'])) 	{
			$error = array();
			foreach ($array as $box) {
			$sql = "SELECT * FROM act WHERE item = '" . $box . "'";  
			$result = runSQL($sql) or die(mysql_error());
			$num_rows = mysql_num_rows($result);
			if ($num_rows) {
			//trigger_error('It exists.', E_USER_WARNING);
			$error[] = array('boxerror'=>$boxerrortext,
			$result = json_encode($error);

			echo $result;

			/* if ($box == 'DEMO111')
			//echo 'There was an error somewhere';
			//$box = 'ERROR';

			//$error = array('boxerror'=>$boxerrortext, 'box'=>$box);
			//$output = json_encode($error);

			//echo $output;
			} */
                       else {
                       $form = array();

                       foreach ($array as $box) {
                       $form[] = array('dept'=>$dept, 
$sql = "INSERT INTO `temp` (service, activity, department, company, address, user, destroydate, date, item, new) VALUES ('$service', '$activity', '$dept', '$company', '$address', '$requested', '$destdate', NOW(), '$box', 1)";
$result = runSQL($sql) or die(mysql_error());
        echo $result;


Open in new window

Watch Question
This problem has been solved!
Unlock 1 Answer and 48 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE