views:

68

answers:

2

I have a stored procedure:

CREATE PROCEDURE busi_reg 
    (IN instruc VARCHAR(10), 
     IN tble VARCHAR(20), 
     IN busName VARCHAR(50), IN busCateg VARCHAR(100), 
     IN busType VARCHAR(50), 
     IN phne VARCHAR(20), IN addrs VARCHAR(200), IN cty VARCHAR(50), 
     IN prvnce VARCHAR(50), IN pstCde VARCHAR(10), IN nm VARCHAR(20), 
     IN surname VARCHAR(20), IN eml VARCHAR(50), IN pswd VARCHAR(20), 
     IN srce VARCHAR(50), IN refr VARCHAR(50), IN sess VARCHAR(50))

BEGIN

INSERT INTO b_register SET

       business_name = busName,
       business_category = busCateg,
       business_type = busType,
       phone = phne,
       address = addrs,
       city = cty,
       province = prvnce,
       postal_code = pstCde,
       firstname = nm,
       lastname = surname,
       email = eml,
       password = pswd,
       source = srce,
       ref_no = refr;

END;

This is my php script:

$busName = $_POST['bus_name'];    
$busCateg = $_POST['bus_cat'];
$busType = $_POST['bus_type'];    
$phne = $_POST['phone'];
$addrs = $_POST['address'];    
$cty = $_POST['city'];    
$prvnce = $_POST['province'];    
$pstCde = $_POST['postCode'];    
$nm = $_POST['name'];    
$surname = $_POST['lname'];    
$eml = $_POST['email'];    
$srce = $_POST['source'];    
$ref = $_POST['ref_no'];

$result2 = $db->query("CALL busi_reg('$instruc', '$tble', '$busName', 
    '$busCateg', '$busType', '$phne', '$addrs', '$cty', '$prvnce', 
    '$pstCde', '$nm', '$surname', '$eml', '$pswd', '$srce', '$refr', '')");

if($result)
{
    echo "Data has been saved";
}
else
{
    printf("Error: %s\n",$db->error);
}

Now the error that I get:

**Commands out of sync; you can't run this command now**
A: 

$result and $result2 are two different objects. Also concatenation is faster if you use "Call sp_xxx('".$xxx.",".$yyy.")" instead of inline.

RandyMorris
Premature Optimization, the code becomes a lot more complicated with a benefit that "vanishes" when using a opcode cache-- a tool much more important than complicating code to save a fraction of a percent on your load time.
AlReece45
The second part was a suggestion on the side and your idea is you opinion. The main point was form the code the first thing I would look at was the obvious. I am sure he googled himself so not sure how you think you are helping.
RandyMorris
He did neglect to include setting his $result object, he might have also neglected checking his $result2 object. Regardless, he's getting an ACTUAL ERROR from MySQL. Changing if($result) to if($result2) is not going to make that error magically go away. Using the given information, I do not know whether or not he's using MYSQLI_USE_RESULT, which is why I included it as a question in my answer. If he includes that information, then the code he omitted code (that sets $result or checks $result2) might become more important.
AlReece45
Also, I only downvoted for the Premature Optimization, not the note about $result/$result2. Something you can still fix if you desire.
AlReece45
Wow, tough crowd. I suggest witholding downvotes unless the answer is actually wrong, or at least seriously misleading.
egrunin
yeah, alot of nerd rage it seems on this site. I thought the idea was to downvote misinformation, not difference of opinion.
RandyMorris
A: 

I assume because this is tagged MySQLi, that you're using it.

Are you using MYSQLI_USE_RESULT? A quick google search on the error quickly brought me to: http://php.net/manual/en/mysqli.query.php

If that is the problem you'll need to free your last result before executing the new one.

AlReece45
Why was this downvoted? It might not be the solution, but it's not misleading.
egrunin