Forum Moderators: coopster

Message Too Old, No Replies

SQL Update problem

sql updating to 0

         

DJcool

4:51 pm on Oct 4, 2004 (gmt 0)

10+ Year Member



hi there i hav a problem with mysql when updating from a text field. the text field is in text but when updating , it comes up as numerical as in it only accepts only numerical format!

here is the code for the html

[edit: code snipped to show only form fields]


<form action="{S_CONFIG_ACTION}" method="post">
<input type="hidden" name="forum" value="{FORUM_ID}" />
<select size="1" name="topic_control">
<option value="1">ON</option>
<option value="2">OFF</option>
</select>
<input class="field" type="text" size="25" name="topic_message" value="{FORUM_TOPIC_MESSAGE}" />
<input type="submit" value="{L_UPDATE}">
</form>

========================================

here is the code from php

[edit: error checking snipped]


if( isset($HTTP_GET_VARS['topic_message']) ¦¦ isset($HTTP_POST_VARS['topic_message']) )
{
$topic_message = ( isset($HTTP_POST_VARS['forum']) )
? intval($HTTP_POST_VARS['topic_message'])
: intval($HTTP_GET_VARS['topic_message']);
}
else
{
$topic_message = '';
}

$sql = "UPDATE " . FORUMS_TABLE . "
SET topic_control = '$topic_control' , topic_controlmsg = " . intval($HTTP_POST_VARS[topic_message]) . "
WHERE forum_id = '$forum_id'";

if (!($db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Error updating forum control', '', __LINE__, __FILE__, $sql);
}

can u guys please tell me what is wrong so that i can fix it ... i would really appreciate it .. y will the field only save numerical formats and y not text ..

[edited by: ergophobe at 9:13 pm (utc) on Oct. 4, 2004]
[edit reason] Code dump snipped - see forum charter [/edit]

ergophobe

9:17 pm on Oct 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



$topic_message = ( isset($HTTP_POST_VARS['forum']) )
? intval($HTTP_POST_VARS['topic_message'])
: intval($HTTP_GET_VARS['topic_message']);

You are converting your text to integer.

For example, this script

$str = "This is a string to be converted to integer";
echo "The integer value of the string <i>$str</i> is: " . intval($str);

Creates this output

The integer value of the string This is a string to be converted to integer is: 0

Tom

DJcool

10:48 pm on Oct 4, 2004 (gmt 0)

10+ Year Member



then how do i stop it from converting into integer? that wud prob solve my problem :) thanx

ergophobe

12:08 am on Oct 5, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



instead of

: intval($HTTP_GET_VARS['topic_message']);

just use

$HTTP_GET_VARS['topic_message']

As a side note, the $HTTP_GET_VARS are deprecated. You should be using $_GET instead.

Tom