0

So I have a procedure in my database that's called insertRestaurant, and it takes a couple of variables. Problem is, I can't get it to work from my PHP, is it my syntax or am I using the procedure incorrectly? I was able to connect my PHP file to my DB so I know that's not an issue.

For reference, the $conn here is also described.

function OpenCon(){
      $dbhost = "localhost";
      $dbuser = "root";
      $dbpass = "";
      $db = "covid19";
      $conn = new mysqli($dbhost, $dbuser, $dbpass,$db) or die("Connect failed: %s\n". $conn -> error);
    
      return $conn;
    }

$conn = OpenCon();

$sql = 'CALL insertRestaurant($restaurant_name, $pnumber, $email, $address, $city, $province);';

    if(mysqli_query($conn, $sql)){
       echo "Successful Entry!";
    }else{
       echo "Couldn't input into database.";
    }
Dharman
  • 30,962
  • 25
  • 85
  • 135
  • print your response, and is this the full code sample? your variables are strings too – Ballard Oct 19 '20 at 13:52
  • I don't think `$restaurant_name` is a valid SQL. You probably wanted to interpolate PHP variables. – Dharman Oct 19 '20 at 14:23
  • I was actually able to figure it out. So the query wasn't correct because the final query looked like, "insertRestaurant(param1, param2, param3);" Without the quotes on any of the params, it wasn't valid SQL. Solved it by just putting single quotes on each of the params like so "CALL insertRestaurant('${restaurant_name}', '${pnumber}', '${email}', '${address}', '${city}', '${province}');"; Solved the problem. – Siam Shafiq Oct 19 '20 at 14:29

0 Answers0