Jump to content

why isn't this working


desithugg

Recommended Posts

function updateme($table,$field,$value,$where)
{
if($table == "") { $table = "rpg_users"; }
if($field == "") { $field = "promo"; }
if($value == "") { $value = "yes"; }
if($where == "") { $where = "id"; }
$query = mysql_query("update $table set $field = '$value' where $where = '$user_id'") or die(mysql_error()); 
}
updateme("rpg_users","promo","yes","id");

how come that doesn't work and the fallowing does

$query = mysql_query("update rpg_users set promo = 'yes' where id = '$user_id'") or die(mysql_error()); 

I'm not sure what the problem is the database connection is fine but it just doesn't seem to be working.

Link to comment
https://forums.phpfreaks.com/topic/43760-why-isnt-this-working/
Share on other sites

umm no luck

include("/home/pcaworld/public_html/config.php");
function updateme($table,$field,$value,$where)
{
$query = mysql_query("update $table set $field = '$value' where $where = '$user_id'") or die(mysql_error()); 
}
updateme("rpg_users","promo","no","id");

Link to comment
https://forums.phpfreaks.com/topic/43760-why-isnt-this-working/#findComment-212464
Share on other sites

Do you get any errors? Have you put any debugging code into your function to see what is going on?

 

Try this and tell us the results:

<?php
function updateme($table,$field,$value,$where)
{
     if($table == "")
        $table = "rpg_users";
     if($field == "")
        $field = "promo";
     if($value == "")
        $value = "yes";
     if($where == "")
        $where = "id";
    $query = "update $table set $field = '$value' where $where = '$user_id'";
    echo 'In updateme, generated query = <pre>' . $query . '</pre>';  // debug statement
    $rs = mysql_query($query) or die("Problem with the query: <pre>$query</pre><br>" . mysql_error());
}
updateme("rpg_users","promo","yes","id");
?>

 

Ken

Link to comment
https://forums.phpfreaks.com/topic/43760-why-isnt-this-working/#findComment-212489
Share on other sites

<?php
function updateme2($table,$field,$value,$where)
{
     if($table == "")
        $table = "rpg_users";
     if($field == "")
        $field = "promo";
     if($value == "")
        $value = "yes";
     if($where == "")
        $where = "id";
    $query = "update $table set $field = '$value' where $where = '$user_id'";
    echo 'In updateme, generated query = <pre>' . $query . '</pre>';  // debug statement
    $rs = mysql_query($query) or die("Problem with the query: <pre>$query</pre><br>" . mysql_error());
}
updateme2("rpg_users","promo","aah","id");
?>

aah i got the problem thanx to you ken, you were right i didn't have any debugging/errors to tell me what was wrong but this is what the it echoed

 

In updateme, generated query =

 

update rpg_users set promo = 'aah' where id = ''

so the $user_id variable was empty for some reason im gonna check that out

 

which is quite strange because i did echo $user_id; right after and it worked

but i changed the code to

<?php
function updateme2($table,$field,$value,$where,$my_id)
{
     if($table == "")
        $table = "rpg_users";
     if($field == "")
        $field = "promo";
     if($value == "")
        $value = "yes";
     if($where == "")
        $where = "id";
    $query = "update $table set $field = '$value' where $where = '$my_id'";
    echo 'In updateme, generated query = <pre>' . $query . '</pre>';  // debug statement
    $rs = mysql_query($query) or die("Problem with the query: <pre>$query</pre><br>" . mysql_error());
}
updateme2("rpg_users","promo","aah","id",$user_id);
?>

So i had to input the id into the function too...no idea why

Link to comment
https://forums.phpfreaks.com/topic/43760-why-isnt-this-working/#findComment-212513
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.