php - MySQL Syntax error - at line 1 -


i stuck @ error in php. can me?

i error:

you have error in sql syntax; check manual corresponds mysql server version right syntax use near 'fulltext, surl, burl, date) values 'webite online!', 'this short text lo' @ line 1

and code:

<?php if(isset($_post['submit'])) {         if(!empty($_post['titel']) && !empty($_post['stext']) && !empty($_post['fulltext']) && !empty($_post['surl']) && !empty($_post['burl'])) {             $titel = secure($_post['titel']);             $stext = secure($_post['stext']);             $fulltext = secure($_post['fulltext']);             $surl = secure($_post['surl']);             $burl = secure($_post['burl']);             $date = date('d/m/y h:i:s');                      $sql = mysql_query("insert news (titel, stext, fulltext, surl, burl, date) values '".$titel."', '".$stext."', '".$fulltext."', '".$surl."', '".$burl."', '".$date."'")or die(mysql_error());                     if($sql) {                         echo('news posted succesful.');                         echo('<meta http-equiv="refresh" content="3" />');                     } else {                         echo'there error, please try again.';                         echo('<meta http-equiv="refresh" content="3" />');                     }         } else {             echo('not fields filled.');             echo('<meta http-equiv="refresh" content="3" />');         }     } else {         echo('         <form method="post" action="#">         <table width="100%" cellpadding="0" cellspacing="2">         <tr>         <td>titel</td>         <td><input type="text" name="titel" /></td>         </tr>         <tr>         <td>short news</td>         <td><textarea name="stext" rows="4" cols="50" ></textarea></td>         </tr>         <tr>         <td>long news</td>         <td><textarea name="fulltext" rows="4" cols="50" ></textarea></td>         </tr>         <tr>         <td>150x150 image url</td>         <td><input type="text" name="surl" /></td>         </tr>         <tr>         <tr>         <td>*x* image url</td>         <td><input type="text" name="burl" /></td>         </tr>         <tr>         <tr>         <td></td>         <td><input type="submit" name="submit" value="post" /></td>         </tr>         </table>         </form>');     } ?> 

first of stop using mysql_* deprecated , close in php 7. use mysqli_* or pdo.

issue in query missing brackets of values ():

example:

insert table (column1...) values (values1...) 

your modified query:

insert news (titel, stext, `fulltext`, surl, burl, date) values ('".$titel."', '".$stext."', '".$fulltext."', '".$surl."', '".$burl."', '".$date."'") 

side note:

make sure column titel correct name.

update:

and mr barmar @barmar mentioned fulltext mysql reserve word need add backtick around column.


Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -