473,323 Members | 1,560 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

Query Failed Problem

38
I'm a novice, so bear with me.

I'm trying to use a query string that has worked fine for me in the past, however, I'm now using mysql 5 which may be causing the problem, or not.

I've tried various versions of this with still no joy.

Here is my mysql_error message...

Query failed:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'desc='Page Description', keywords='Page Keywords', content='
Page content html' at line 1


Here is my code

Expand|Select|Wrap|Line Numbers
  1. $str = "UPDATE pages SET title='".$pagetitle."', desc='".$pagedescription."', keywords='".$pagekeywords."', content='".$pagecontent."' WHERE id = '1'";
  2. mysql_query($str) or die("Query failed:<br>".mysql_error());
many thanks in advance.
Mar 3 '10 #1
3 1551
Dormilich
8,658 Expert Mod 8TB
what does the printed query string look like?
Mar 3 '10 #2
Philth
38
Hi there,

Thanks for the message.

Here is what is printed...

UPDATE pages SET title='Page Title', desc='Page Description', keywords='Page Keywords', content='
Page content html

' WHERE id = '1'

There appears to be somthing funny going on with the content field.

Here is my whole page...

Expand|Select|Wrap|Line Numbers
  1. <?
  2. include("../check_session.php"); 
  3. ?>
  4.  
  5. <html>
  6. <head>
  7. <link href="tutorial_styles.css" rel="stylesheet" type="text/css">
  8. <link href="../../css/styles.css" rel="stylesheet" type="text/css">
  9. <body>
  10. <br>
  11. <table width="938" border="0" align="center" cellpadding="3" cellspacing="10" bgcolor="#FFFFFF" class="border">
  12.   <tr>
  13.     <td width="190" valign="top"><table width="239" height="168" border="0" align="center" cellpadding="0" cellspacing="10" bgcolor="#FFFFFF">
  14.       <tr>
  15.         <td width="156" class="smalltitles">Home Page </td>
  16.         <td width="148" class="bodytext"><a href="home_edit.php">Edit</a></td>
  17.       </tr>
  18.       <tr>
  19.         <td class="smalltitles">Kenya Safaris </td>
  20.         <td class="bodytext">Edit</td>
  21.       </tr>
  22.       <tr>
  23.         <td class="smalltitles">Tanzania Safaris </td>
  24.         <td class="bodytext">Edit</td>
  25.       </tr>
  26.       <tr>
  27.         <td class="smalltitles">South Africa Safaris </td>
  28.         <td class="bodytext">Edit</td>
  29.       </tr>
  30.       <tr>
  31.         <td class="smalltitles">About Us </td>
  32.         <td class="bodytext">Edit</td>
  33.       </tr>
  34.     </table></td>
  35.     <td width="676" valign="top"><span class="smalltitles">Homepage Edit...</span>
  36.       <br />
  37.     <br />
  38.  
  39.  
  40.     <?
  41. include_once("../../fckeditor/fckeditor.php") ;
  42. ?>
  43.  
  44.  
  45. <?php
  46. include("../connect.php"); 
  47. if ($_POST['submit'])
  48. {
  49. $pagetitle = $_POST['pagetitle'];
  50. $pagekeywords = $_POST['pagekeywords'];
  51. $pagedescription = $_POST['pagedescription'];
  52. $pagecontent = $_POST['pagecontent'];
  53.  
  54. $str = "UPDATE pages SET title='".$pagetitle."', desc='".$pagedescription."', keywords='".$pagekeywords."', content='".$pagecontent."' WHERE id = '1'";
  55. mysql_query($str) or die("Query failed:<br>".mysql_error());
  56.  
  57. echo "<br><span class='bodytext'>Page Updated Successfully!</span><br><br>";
  58. }
  59. // ************* End update part *************
  60.  
  61.  
  62.  
  63. $result=mysql_query("select * from pages where id='1'") or die($qry."Cannot find the page".mysql_error());
  64. $row=mysql_fetch_assoc($result);
  65.  
  66. mysql_close();
  67. ?>
  68. <form action="home_edit.php" method="post" enctype="multipart/form-data">
  69.   <table width="650" border="0" cellspacing="10" cellpadding="0">
  70.  
  71.     <tr>
  72.       <td width="611" class="bodytext">Page Title </td>
  73.     </tr>
  74.     <tr>
  75.       <td><textarea name="pagetitle" cols="45" rows="4" class="border" id="pagetitle"><? echo $row['title']; ?></textarea></td>
  76.     </tr>
  77.     <tr>
  78.       <td class="bodytext">META Description </td>
  79.     </tr>
  80.     <tr>
  81.       <td><textarea name="pagedescription" cols="45" rows="4" class="border" id="pagedescription"><? echo $row['desc']; ?></textarea></td>
  82.     </tr>
  83.     <tr>
  84.       <td class="bodytext">META Keywords </td>
  85.     </tr>
  86.     <tr>
  87.       <td><textarea name="pagekeywords" cols="45" rows="4" class="border" id="pagekeywords"><? echo $row['keywords']; ?></textarea></td>
  88.     </tr>
  89.     <tr>
  90.       <td class="bodytext">Page Content </td>
  91.     </tr>
  92.     <tr>
  93.       <td><?php
  94. $oFCKeditor = new FCKeditor('pagecontent') ;
  95. $oFCKeditor->BasePath = '../../fckeditor/' ;
  96. $oFCKeditor->Value = $row['content'] ;
  97. $oFCKeditor->Height = '400';
  98. $oFCKeditor->Create() ;
  99. ?></td>
  100.     </tr>
  101.     <tr>
  102.       <td><input type="submit" name="submit" value="Edit Page" /></td>
  103.     </tr>
  104.   </table>
  105. </form>
  106. </TD>
  107.   </TR>
  108. </TABLE>
  109.    </td>
  110.   </tr>
  111. </table>
  112. </body>
  113. </html>
  114.  
Mar 3 '10 #3
Atli
5,058 Expert 4TB
Hey.

The word "DESC" is a reserved keyword in MySQL. If you want to use it as a column name, it needs to be enclosed in back-ticks (`desc`).

Also, a couple of notes on your code:
  • Check out SQL Injection. Your code is wide open to an SQL Injection attack. - Basically; always run input variables through mysql_real_escape_string before using them in a MySQL query.
  • You don't have to break out of a double-quoted string to add a variable. PHP parses variables within double-quoted strings.
    Expand|Select|Wrap|Line Numbers
    1. // Instead of this:
    2. $string = " Hello, " . $world;
    3.  
    4. // Just do this:
    5. $string = " Hello, $world";
Mar 3 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: dogu | last post by:
Noob alert. Code is below. File is saved as a .php. What I'm trying to do: User uses 'select' box drop down list to pick a value. Value ($site) is derived from a db query. This works fine....
13
by: Wescotte | last post by:
Here is a small sample program I wrote in PHP (running off Apache 1.3.31 w/ PHP 5.0.1) to help illustrates problem I'm having. The data base is using DB2 V5R3M0. The client is WinXP machine using...
14
by: Bruce W...1 | last post by:
I do a query to MySQL using PHP. Well actually I do too many of them which is the problem, it's too slow. I think maybe an inner join or something would be better but I can't figure this out. ...
5
by: George Copeland | last post by:
This is a request for help fixing a SQL Server 2000/ADO problem on Windows XP. I would appreciate any useful assistance. PROBLEM: SQL Server access on my machine fails as follows: 1. All of...
3
by: shreedhar | last post by:
If I try to delete a record from my table which is giving following error Warning: PostgreSQL query failed: ERROR: pg_atoi: zero-length string in /xxx/database.inc on line 73 What might be...
6
by: Andy | last post by:
Hello, I am having many problems with setting up a parameter query that searches by the criteria entered or returns all records if nothing is entered. I have designed an unbound form with 3...
4
by: Miks | last post by:
The database scheme consists of four relations: Product(maker, model, type) PC(code, model, speed, ram, hd, cd, price) Laptop(code, model, speed, ram, hd, screen, price) Printer(code, model,...
1
by: Pradeep83 | last post by:
Hi All Problem : I am unable to retrieve the data from the table in postgres database using C application which i have written in solaris os. Query: How to check whether connection is there...
16
by: ARC | last post by:
Hello all, So I'm knee deep in this import utility program, and am coming up with all sorts of "gotcha's!". 1st off. On a "Find Duplicates Query", does anyone have a good solution for...
14
ddtpmyra
by: ddtpmyra | last post by:
Hi below is my script displaying all the information inside the table. Pupose: pupose of this php page is to display all the information on my table and have a check box at the last column that...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.