7 Replies - 286 Views - Last Post: 07 June 2011 - 10:57 PM Rate Topic: -----

#1 dangmnx  Icon User is offline

  • D.I.C Regular

Reputation: -1
  • View blog
  • Posts: 387
  • Joined: 10-April 09

UPDATE function

Posted 07 June 2011 - 09:35 PM

It's not giving me an error, but it's also not doing what i assigned it to do, It isn't locking the topic... every time i click submit it takes me back to generalforum_lock.php

<?php
error_reporting (E_ALL);
include("connect.php");

$id = $_POST['id'];
$lock = $_POST['lock'];

$query = mysql_query("UPDATE forum_question SET `lock`='$lock' WHERE `id`='$id'") or die(mysql_error());
header("Location: generalforum_lock.php");
?>




Is This A Good Question/Topic? 0
  • +

Replies To: UPDATE function

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 3872
  • View blog
  • Posts: 11,405
  • Joined: 18-April 07

Re: UPDATE function

Posted 07 June 2011 - 09:57 PM

Well of course it takes you back to generalforum_lock.php, you have a header statement there sending you to that page no matter what your code is doing. What you need to do is currently comment the header() call out and then echo out the values of $id and $lock to see if they equal what you expect. Then you can also see if mysql_error is giving you a message to what is wrong. You won't know because header keeps redirecting you. So take that out for now and see what the page prints.

:)
Was This Post Helpful? 1
  • +
  • -

#3 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 2894
  • View blog
  • Posts: 7,541
  • Joined: 08-June 10

Re: UPDATE function

Posted 07 June 2011 - 10:13 PM

if lock and id are integer fields, they must not be quoted.

and you’re open to SQL Injection Attacks.
Was This Post Helpful? 1
  • +
  • -

#4 dangmnx  Icon User is offline

  • D.I.C Regular

Reputation: -1
  • View blog
  • Posts: 387
  • Joined: 10-April 09

Re: UPDATE function

Posted 07 June 2011 - 10:27 PM

<?php
error_reporting (E_ALL);
include("connect.php");

$id = mysql_real_escape_string($_POST[id]);
$lock = mysql_real_escape_string($_POST['lock']);

$query = mysql_query("UPDATE forum_question SET `lock`='$lock' WHERE id='$id'") or die(mysql_error());
header("Location: generalforum_lock.php");
?>


So like that??

This post has been edited by dangmnx: 07 June 2011 - 10:27 PM

Was This Post Helpful? 0
  • +
  • -

#5 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 2894
  • View blog
  • Posts: 7,541
  • Joined: 08-June 10

Re: UPDATE function

Posted 07 June 2011 - 10:30 PM

depends on whether lock and id are integers or not.
Was This Post Helpful? 1
  • +
  • -

#6 dangmnx  Icon User is offline

  • D.I.C Regular

Reputation: -1
  • View blog
  • Posts: 387
  • Joined: 10-April 09

Re: UPDATE function

Posted 07 June 2011 - 10:32 PM

id is set as INT 11 and lock is VARCHAR 11
Was This Post Helpful? 0
  • +
  • -

#7 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 2894
  • View blog
  • Posts: 7,541
  • Joined: 08-June 10

Re: UPDATE function

Posted 07 June 2011 - 10:43 PM

wasn’t lock an integer last time? as for id:
// either
$id = (int) $_POST['id'];
// or
$id = filter_input(INPUT_POST, "id", FILTER_VALIDATE_INT);

// and then an appropriate check, whether $id is a sensible value

Was This Post Helpful? 1
  • +
  • -

#8 dangmnx  Icon User is offline

  • D.I.C Regular

Reputation: -1
  • View blog
  • Posts: 387
  • Joined: 10-April 09

Re: UPDATE function

Posted 07 June 2011 - 10:57 PM

Thank you :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1