Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 MySql to MsSql

Author  Topic 

lajus
Starting Member

4 Posts

Posted - 2009-04-27 : 08:21:56
Hi everybody;

First sory about my english, I hope you can understand me.
The following code was working perfect in PHP + MySql, but I need change to MsSql, something is wrong but I can't found the error.
Here is the error:
PHP Warning: mssql_query() [function.mssql-query]: message: Incorrect syntax near '='. (severity 15) in E:\home\abc1\Web\admin\editor_alt.php on line 16
PHP Warning: mssql_query() [function.mssql-query]: Query failed in E:\home\abc1\Web\admin\editor_alt.php on line 16

Here is the line 16:
$query_texto = mssql_query($sql_texto) or die(mssql_get_last_message());

And here is my code:
<?
include "conexao.php";
include "FCKeditor/fckeditor.php";
$id_select = $_GET['id'];
$id = $_POST['id'];
$titulo = $_POST['titulo'];
$texto = $_POST['texto'];

if ((isset($_POST['id'])) && ($_POST['titulo']) && ($_POST['texto'])){
$sql = "UPDATE editor SET titulo='$titulo', texto='$texto' where id=$id";
$result = mssql_query($sql) or die(mssql_get_last_message());

header("Location: editor_mostra.php");
}

$sql_texto = "SELECT * FROM editor where id=$id_select";
$query_texto = mssql_query($sql_texto) or die(mssql_get_last_message());
$row_texto = mssql_fetch_assoc($query_texto);
$id = $row_texto['id'];
$titulo = $row_texto['titulo'];
$texto = $row_texto['texto'];
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>RGM</title>
<!-- File js of FCK Editor-->
<script type="text/javascript" src="FCKeditor/fckeditor.js"></script>
</head>

<body>
<form method="post" name="form" action="<?=$_SERVER['PHP_SELF']?>">
<b>Titulo</b>
<input name="titulo" value="<?php echo "$titulo"; ?>" type="text" size="40" maxlength="200">
<br/><br/>
<?
$editor = new FCKeditor("texto");
$editor-> BasePath = "FCKeditor/";
$editor->ToolbarSet = "Basic2";
$editor-> Value = "$texto";
$editor-> Width = "600";
$editor-> Height = "300";
$editor-> Create();
?>

<input type="submit" value="Alterar">
<input type="hidden" name="id" value="<?php echo "$id"; ?>">
</form>
</body>
</html>


Thank you for any help

whitefang
Enterprise-Level Plonker Who's Not Wrong

272 Posts

Posted - 2009-04-27 : 08:40:57
$sql_texto = "SELECT * FROM editor where id=$id_select";
id_select is a variable in PHP and you're enclosing it in a string which does not work (you need to concatenate instead).

It needs to be
$sql_texto = "SELECT * FROM editor where id=".$id_select;
Go to Top of Page

lajus
Starting Member

4 Posts

Posted - 2009-04-27 : 08:50:41
Hi Whitefang;
thanks for quick response, I tried this but still giving the same error
Go to Top of Page

whitefang
Enterprise-Level Plonker Who's Not Wrong

272 Posts

Posted - 2009-04-27 : 08:54:29
$sql_texto = "SELECT * FROM editor where id=$id_select";

What is the datatype of the [id] column in the table [editor]? Also, are you sure you're passing in the "id" query string?
Go to Top of Page

lajus
Starting Member

4 Posts

Posted - 2009-04-27 : 09:04:24
id = int
I think so, because when this code was being used with mysql was working perfectly.
Go to Top of Page

whitefang
Enterprise-Level Plonker Who's Not Wrong

272 Posts

Posted - 2009-04-27 : 09:06:28
Do a echo on $id_select and see what it prints out. I'm pretty sure it's "empty" because you're not passing in the querystring which would cause a common incorrect syntax near '=' exception.
Go to Top of Page

maeenul
Starting Member

20 Posts

Posted - 2009-04-28 : 02:39:07
$sql_texto = "SELECT * FROM editor where id=$id_select";
id_select is a variable in PHP and you're enclosing it in a string which does not work (you need to concatenate instead).

In fact in php, it is not a problem. Php can automatically do the concatenation. The problem is with the query, I think. You can echo the full query before executing.

echo $sql_texto;

and will find what is going to the server. I think the problem is as whitefang wrote. $id_select is empty or it is holding something non integer.

-----------------------
maeenul
http://www.programmingsolution.net/sqlserver2005/sqlserversolutions/solution_list.php
http://sqlservertipsntricks.blogspot.com
Go to Top of Page
   

- Advertisement -