Jump to content

Problem with UPDATE


MasksMaster

Recommended Posts

Hello, Everybody!

I'm new to PHP/MySQL. For some strange reason I can get the UPDATE part to work. I even tried checking if $other, $ud_id, $ud_received were submitted and they were and show when I use echo.

<?php
$other=$_COOKIE['other'];
$ud_received=$_POST['ud_received'];
$ud_id=$_POST['ud_id'];

echo $other;

echo $ud_received." "."ud_received";

echo $ud_id." "."ud_id";


//this part I replace with needed values
$user="username";
$password="password";
$database="database";

//This is where my problem is
mysql_connect(localhost,$user,$password);
$query="UPDATE $other SET received='$ud_received' WHERE id='$ud_id'";
mysql_query($query);
mysql_close();

echo "Record Updated";

?>
Link to comment
Share on other sites

Your rconnection would be failing because you don't have a constant defined called localhost. Try...

[code=php:0]
mysql_connect("localhost",$user,$password);
[/code]

notice the word localhost is a string and thus needs to be within quotes.

You really should also check that your query worked before stating a success message.

[code=php:0]
mysql_connect(localhost,$user,$password);
$query="UPDATE $other SET received='$ud_received' WHERE id='$ud_id'";
if (mysql_query($query)) {
  echo "Record Updated";
} else {
  // query failed.
  echo mysql_error();
}
mysql_close();
[/code]
Link to comment
Share on other sites

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.