Jump to content

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


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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.