在PHP脚本中调用mysql中的存储过程

时间:2021-07-24 16:44:05

I have a php script that is being called by an ajax post. I am getting the error
Parse error: syntax error, unexpected T_VARIABLE in C:\xampp\htdocs\Escape\SendTestimony.php on line 9

我有一个由ajax帖子调用的PHP脚本。我收到错误Parse错误:语法错误,第9行C:\ xampp \ htdocs \ Escape \ SendTestimony.php中的意外T_VARIABLE

Here is the paramaters

这是参数

$name = $_POST['name'];   

$message = $_POST['message'];

$ message = $ _POST ['message'];

Here is line 9 where the error occurs. Thanks for any help.

这是第9行发生错误的地方。谢谢你的帮助。

mysql_query("CALL sp_CreateTestimony("$name.", "$message.")");

EDIT ADDED JQUERY AJAX CALL

编辑添加了JQUERY AJAX CALL

 var parameters = {
                    'name': $('#cf_name').val(),
                    'message': $('#cf_message').val()
                }; //Use JSON to pass parameters into ajax calls  
                parameters = JSON.stringify(parameters); 


                //Make ajax call to post to database
                $.ajax({
                    type: 'POST',
                    url: '../Escape/SendTestimony.php',
                    datatype: 'json',
                    data: parameters,
                    success: function (result) {
                    alert(result);
                        $('#ValidateTest').html('Thank-you!').css({ 'color': 'green' }).show();
                    },
                    error: function(jqXHR, textStatus, errorThrown) {alert(textStatus + ":" + errorThrown);}
                });

2 个解决方案

#1


3  

you should add dots before variables and single quotes around them:

你应该在变量和它们周围的单引号之前添加点:

mysql_query("CALL sp_CreateTestimony('".$name."', '".$message."')");

#2


0  

stringify was the problem. I removed that and it fix the problem.

stringify是问题所在。我删除了它,它解决了问题。

#1


3  

you should add dots before variables and single quotes around them:

你应该在变量和它们周围的单引号之前添加点:

mysql_query("CALL sp_CreateTestimony('".$name."', '".$message."')");

#2


0  

stringify was the problem. I removed that and it fix the problem.

stringify是问题所在。我删除了它,它解决了问题。