PDA

View Full Version : Wont UPDATE for some reason


Odium
01-31-2006, 07:52 PM
For some odd reason I cannot get this script to update the sql database. I have one that inserts and deletes records with no problem, but i must be missing something here. I added the variable's at the bottom to make sure the correct data is being submited correctly, and it looks correct as far as I can tell.

Sorry, im very new at this.

Any word of advise, or an easier way to perform an update would be great.

Thanks.


<?
$ud_id=$_POST['id'];
$ud_mob=$_POST['mob'];
$ud_lockout=$_POST['lockout'];
$ud_tier=$_POST['tier'];

$DBuser = "user";
$DBpass = "pass";
$DBName = "dbname";
$table = "dbtable";
mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database");

$sqlquery="UPDATE '$table' SET mob='$ud_mob', lockout='$ud_lockout', tier='$ud_tier' WHERE id='$ud_id'";

$results = mysql_query($sqlquery);

mysql_close();

echo "Record Updated";
echo "<br>";
echo "$ud_id";
echo "<br>";
echo "$ud_mob";
echo "<br>";
echo "$ud_lockout";
echo "<br>";
echo "$ud_tier";
echo "<br>";

?>

Brandoe85
01-31-2006, 08:03 PM
Try this:

<?php

$ud_id=$_POST['id'];
$ud_mob=$_POST['mob'];
$ud_lockout=$_POST['lockout'];
$ud_tier=$_POST['tier'];

$DBuser = "user";
$DBpass = "pass";
$DBName = "dbname";
$table = "dbtable";
mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database");

$sqlquery="UPDATE $table SET mob='$ud_mob', lockout='$ud_lockout', tier='$ud_tier' WHERE id='$ud_id'";

// echo out the query for debuging
echo $sqlquery;

$results = mysql_query($sqlquery) or die(mysql_error());

if($results)
{
echo 'Updated' . "<br>";
}
else
{
echo 'Error' . "<br>";
}

mysql_close();

?>


I took out the quotes around your table name and added in a or die(mysql_error()) statement.

Good luck;

Odium
01-31-2006, 08:18 PM
Thank you very much, Your code didnt necessary fix the issue, but it gave me the clue to what I was missing, and thats all that matters.

Thank you for your time.


mysql_select_db("DATABASE") or die(mysql_error());