Jump to content


Photo

It won't insert user input!


  • Please log in to reply
3 replies to this topic

#1 Doomflame

Doomflame
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 13 May 2003 - 12:44 AM

The code below enters the values $title, $id, and $value into the database, not their values. All of them are set.


$sql = \'INSERT INTO `stocks` (`Title`, `ID`, `Value`) VALUES (\'$title\', \'$id\', \'$value\');\'; 

$query = mysql_query($sql);

if ($query) {

 echo "Success!";

} else {

 echo "ERROR!";

}

Can anyone help me?

#2 gizmola

gizmola
  • Administrators
  • Advanced Member
  • 4,664 posts
  • LocationLos Angeles, CA USA

Posted 13 May 2003 - 01:33 AM

WHen you start a string with a single tic it\'s interpreted to be a string literal by php. Use a double quote around the assignment instead, and php will do the variable replacement you expect.

[php:1:501ca3e94d]<?php
$sql = \"INSERT INTO `stocks` (`Title`, `ID`, `Value`) VALUES (\'$title\', \'$id\', \'$value\');\";
$query = mysql_query($sql);
if ($query) {
echo \"Success!\";
} else {
echo \"ERROR!\";
}
?>[/php:1:501ca3e94d]

#3 shivabharat

shivabharat
  • Members
  • PipPipPip
  • Advanced Member
  • 371 posts
  • LocationChennai, India

Posted 13 May 2003 - 06:34 AM

Do the strip slash when u initally get the variable

$sql = "INSERT INTO `stocks` (`Title`, `ID`, `Value`) VALUES ($title, $id, $value)";

Knowledge --- Reading Enriches Mind But Sharing Enhances It.[br][br]Note: Before you request help enusre that you have had a look at the tutorials @phpfreaks

#4 Doomflame

Doomflame
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 13 May 2003 - 02:58 PM

I got it to work, I remembered that mysql_error() shows error info, and I just did stripslashes and took the slashes out of that mysql code.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users