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
https://forums.phpfreaks.com/topic/27349-problem-with-update/
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
https://forums.phpfreaks.com/topic/27349-problem-with-update/#findComment-125042
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.