Jump to content

[SOLVED] This code is driving me insane! (Can't figure out bug)


Michan

Recommended Posts

Hi everyone,

 

The following code is driving me crazy;

 

$desc = ('test');

mysql_query('INSERT INTO vg_features (category, game, priority, limage, simage, link, title, type, desc) VALUES ("'.$cats.'", "'.$games.'", "'.$_POST['priority'].'", "'.$file.'", "'.$file2.'", "'.$link.'", "'.$_POST['featuretitle'].'", "'.$type.'", "'.$desc.'")');

 

It all works (tested), sans the "desc" and ""'.$desc.'"." I've tested it a gajillion times and tried changing $desc to a multitude of things, as well as replaced "'.$desc.'" with "test", but for some reason, only that "desc" part is not inserting into the database.

 

Here is the corresponding mysql structure for that area of the table:

 

  	link  	longtext  	latin1_swedish_ci
title 	text 	latin1_swedish_ci
desc 	text 	latin1_swedish_ci

 

It is ABSOLUTELY the "desc" part that isn't working, as it works fine without it.

 

Please, somebody help me here!

$query ='INSERT INTO vg_features (category, game, priority, limage, simage, link, title, type, desc) VALUES ("'.$cats.'", "'.$games.'", "'.$_POST['priority'].'", "'.$file.'", "'.$file2.'", "'.$link.'", "'.$_POST['featuretitle'].'", "'.$type.'", "'.$desc.'")';
echo $query;
mysql_query($query ) or die (mysql_error());

 

try and tell us what happen  ;D

desc is a reserved word in sql. You need to escape reserved words using `backticks`. Also, you should always check your queries for success. Try...

 

<?php

  $sql = "INSERT INTO vg_features (
              category, game, priority, limage, simage, link, title, type, `desc`
            ) VALUES (
              '$cats', '$games', '{$_POST['priority']}', '$file', '$file2', '$link', '{$_POST['featuretitle']}', '$type', '$desc'
            );";

  if (mysql_query($sql)) {
    echo "insert success!";
  } else {
    echo mysql_error() . "<br />$sql";
  }

?>

 

You really ought to be checking the data from $_POST prior to insert aswell.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.