desithugg Posted March 22, 2007 Share Posted March 22, 2007 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 More sharing options...
shaunrigby Posted March 22, 2007 Share Posted March 22, 2007 Try removing your if statements for the purpose of debugging, so eg if($table == "") { $table = "rpg_users"; } would be: $table = "rpg_users"; If this works, then your if statement is not working, ie $table is not equal to "" Link to comment https://forums.phpfreaks.com/topic/43760-why-isnt-this-working/#findComment-212463 Share on other sites More sharing options...
desithugg Posted March 22, 2007 Author Share Posted March 22, 2007 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 More sharing options...
wilorichie Posted March 22, 2007 Share Posted March 22, 2007 This is not likely, but there is a slight chance that $where is your problem. Try changing the variable name to $id or whatever you like. I have not done the research to back this up, but its worth a try. Link to comment https://forums.phpfreaks.com/topic/43760-why-isnt-this-working/#findComment-212479 Share on other sites More sharing options...
kenrbnsn Posted March 22, 2007 Share Posted March 22, 2007 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 More sharing options...
desithugg Posted March 22, 2007 Author Share Posted March 22, 2007 <?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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.