The new forums will be named Coin Return (based on the most recent vote)! You can check on the status and timeline of the transition to the new forums here.
The Guiding Principles and New Rules document is now in effect.

PHP/MySQL problems

TwistedJesterTwistedJester Registered User regular
edited July 2007 in Help / Advice Forum
So I have an assignment due at midnight (creating a crude message board with PHP/MySQL), and it's pretty much all done, all it needs it commenting. However I'm trying to implement something for extra credit. Basically, it's a function that allows moderators to edit messages. However, when I go to update the database, it doesn't update it, although mysql_query() returns a true value. Here is my code :
elseif($action == "Submit Edit")
{
	$messageid = $_SESSION['editmessage'];
	$body = $_POST['body'];
	echo "$body and $messageid<br/>";
	$modid = $_SESSION['id'];
	$body = stripslashes(trim($body . " edited by $modid"));
	dbconnect();
	$query = "update Messages set body = '$body' where message_id = '$messsageid'";
	$result = mysql_query($query);
	echo "result = $result<br/>";
	unset($_SESSION['editmessage']);
	unset($_SESSION['edituser']);
}

TwistedJester on

Posts

  • JaninJanin Registered User regular
    edited July 2007
    Make sure messageid is set correctly - if it's empty, the query would succeed but do nothing.

    Janin on
    [SIGPIC][/SIGPIC]
  • TwistedJesterTwistedJester Registered User regular
    edited July 2007
    The message ID is set correctly in the echo statement.

    TwistedJester on
  • SeguerSeguer of the Void Sydney, AustraliaRegistered User regular
    edited July 2007
    Try and echo your query to see the result the variables have on it, so you can see what is actually being sent to SQL.

    Seguer on
  • JaninJanin Registered User regular
    edited July 2007
    You could also try calling mysql_affected_rows() after the query has been executed, to confirm that the database isn't updating the row. If it is, it's possible you've got some sort of caching issue.

    Janin on
    [SIGPIC][/SIGPIC]
  • TwistedJesterTwistedJester Registered User regular
    edited July 2007
    Ok, mysql_affected_rows is giving me a 0.

    Also, I'm not quite following you Seguer.

    TwistedJester on
  • JaninJanin Registered User regular
    edited July 2007
    He wants you to echo the value of $query after you define it, so we can see exactly what's being executed.

    Janin on
    [SIGPIC][/SIGPIC]
  • TwistedJesterTwistedJester Registered User regular
    edited July 2007
    Ok... when entering the code to do that, I realized that in the query, I had one too many s's in message_id. Wow. I feel really stupid. Thanks a lot for the help though duders.

    TwistedJester on
Sign In or Register to comment.