Gingechilla Posted April 7, 2006 Share Posted April 7, 2006 Hi I am trying to get the string to work: [code]mysql_query("UPDATE userinfo SET LastOn='2006000000000000' WHERE ID='$mid'");[/code]Even when I when I submit: UPDATE userinfo SET LastOn='2006000000000000' WHERE ID='1' via the MySQL, no rows are affected :--/You may also ask why I have 2006000000000000 - that is just me testing to see if I can update it - which I cannot :([b]Table Name:[/b]userinfo[b]Rows:[/b]ID - int(11) LastOn - timestamp(14) uCat1 - varchar(15) uCat2 - varchar(15) uCat3 - varchar(15) uCat4 - varchar(15) uCat5 - varchar(15) [b]Other Info:[/b]$mid - A number in the page depending on the members id. E.g. 1 Quote Link to comment https://forums.phpfreaks.com/topic/6772-mysql_queryupdate-set-where-id/ Share on other sites More sharing options...
JustinK101 Posted April 7, 2006 Share Posted April 7, 2006 Try:[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--]$sql [color=orange]=[/color] [color=red]"[span style=\'color:blue;font-weight:bold\']UPDATE[/color] userinfo SET LastOn [color=orange]=[/color] '[/span]2006000000000000[color=red]' [span style=\'color:green\']WHERE[/color] ID [color=orange]=[/color] '[/span][color=red]" . $mid . "[/color]';mysql_query($sql);[!--sql2--][/div][!--sql3--]Cheers[!--quoteo(post=362414:date=Apr 6 2006, 06:52 PM:name=Gingechilla)--][div class=\'quotetop\']QUOTE(Gingechilla @ Apr 6 2006, 06:52 PM) [snapback]362414[/snapback][/div][div class=\'quotemain\'][!--quotec--]Hi I am trying to get the string to work: [code]mysql_query("UPDATE userinfo SET LastOn='2006000000000000' WHERE ID='$mid'");[/code]Even when I when I submit: UPDATE userinfo SET LastOn='2006000000000000' WHERE ID='1' via the MySQL, no rows are affected :--/You may also ask why I have 2006000000000000 - that is just me testing to see if I can update it - which I cannot :([b]Table Name:[/b]userinfo[b]Rows:[/b]ID - int(11) LastOn - timestamp(14) uCat1 - varchar(15) uCat2 - varchar(15) uCat3 - varchar(15) uCat4 - varchar(15) uCat5 - varchar(15) [b]Other Info:[/b]$mid - A number in the page depending on the members id. E.g. 1[/quote] Quote Link to comment https://forums.phpfreaks.com/topic/6772-mysql_queryupdate-set-where-id/#findComment-24645 Share on other sites More sharing options...
Gingechilla Posted April 7, 2006 Author Share Posted April 7, 2006 Thanks, but that did not work :-/ created an error:[code]Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/??????/public_html/??????????.php on line 56[/code]Line 56+ is:[code]if(!isset($_GET['page'])){ $page = 1; } else { $page = $_GET['page']; } [/code]Heres the actual bit of code if it helps:[code]//userinfo table checker and updaterif(mysql_result(mysql_query("SELECT COUNT(*) as Num FROM youritems WHERE USER = '$mid'"),0) == 0){ $result=MYSQL_QUERY("INSERT INTO userinfo (ID,LastOn,uCat1,uCat2,uCat3,uCat4,uCat5)". "VALUES ('$mid', 'NULL', 'Category1', 'Category2', 'Category3', 'Category4', 'Category5')");} else { mysql_query("UPDATE userinfo SET LastOn='2006000000000000' WHERE ID='$mid'");}[/code]Note: I'm one of these people who start learning languages by putting bits of stuff from all over together so if any of the stuff above looks messy, sorry - however it works :) Quote Link to comment https://forums.phpfreaks.com/topic/6772-mysql_queryupdate-set-where-id/#findComment-24654 Share on other sites More sharing options...
JustinK101 Posted April 7, 2006 Share Posted April 7, 2006 [code]if(!isset($_GET['page'])){ $page = 1; } else { $page = $_GET['page']; }[/code]That should be fine. The following code you have is VERY VERY hard for me to read, so I tried and re-write it.[code]$sql = "SELECT user FROM youritems WHERE user = '" . $mid . "'";$result = mysql_query($sql);$num_rows = mysql_count_rows($result);if($num_rows == 0){ $sql = "INSERT INTO userinfo (ID, LastOn, uCat1, uCat2, uCat3, uCat4, uCat5) VALUES ('$mid', 'NULL', 'Category1', 'Category2', 'Category3', 'Category4', 'Category5')"; mysql_query($sql);}else { $sql = "UPDATE userinfo SET LastOn = '2006000000000000' WHERE ID=" . $mid . ""; mysql_query($sql);}[/code]I didnt test this, so there may be small errors, but the overall logic should be right. Quote Link to comment https://forums.phpfreaks.com/topic/6772-mysql_queryupdate-set-where-id/#findComment-24657 Share on other sites More sharing options...
Gingechilla Posted April 7, 2006 Author Share Posted April 7, 2006 Thanks, no errors on the page, however the field still won't change :--/Could it be the type of field?-----------------------------Also, I could replace it?Import the current field value then variable that into a replace - Would this work? If so how would I do this? Quote Link to comment https://forums.phpfreaks.com/topic/6772-mysql_queryupdate-set-where-id/#findComment-24659 Share on other sites More sharing options...
JustinK101 Posted April 7, 2006 Share Posted April 7, 2006 DO me a favor:$sql = "SELECT user FROM youritems WHERE user = '" . $mid . "'";$result = mysql_query($sql);$num_rows = mysql_count_rows($result); ---> RIGHT AFTER THESE THREE LINES PUTecho "SQL = " . $sql . "<br>";echo "Numb Rows = " . $num_rows . "<br>";---- > REST OF CODE AFTERThen paste the results here, of when you view the page. Quote Link to comment https://forums.phpfreaks.com/topic/6772-mysql_queryupdate-set-where-id/#findComment-24668 Share on other sites More sharing options...
Gingechilla Posted April 7, 2006 Author Share Posted April 7, 2006 The page looks the same, no changes or errors...Are you looking at the wrong table? I wish to change things on the userinfo table not youritems table.I tried this on my other table and it worked:mysql_query("UPDATE youritems SET uCat='Testing' WHERE uCat=''"); Quote Link to comment https://forums.phpfreaks.com/topic/6772-mysql_queryupdate-set-where-id/#findComment-24690 Share on other sites More sharing options...
JackJack Posted April 7, 2006 Share Posted April 7, 2006 The problem is is that your LastOn - timestamp(14) Is only 14 long the number your using is 15 or 16 :Sedit:Adding 'or die("Create table Error: ".mysql_error());' would tell you what is wrong[code]mysql_query("UPDATE userinfo SET LastOn='2006000000000000' WHERE ID='$mid'")or die("Create table Error: ".mysql_error());[/code] Quote Link to comment https://forums.phpfreaks.com/topic/6772-mysql_queryupdate-set-where-id/#findComment-24694 Share on other sites More sharing options...
Gingechilla Posted April 7, 2006 Author Share Posted April 7, 2006 Thanks, however still no change:I just ran: [code]mysql_query("UPDATE youritems SET LastOn='20060000000000' WHERE LastOn='00000000000000'");[/code]and that did nothing.Corrects Error:[code]mysql_query("UPDATE userinfo SET LastOn='20060000000000' WHERE LastOn='00000000000000'");[/code]Still no change. Quote Link to comment https://forums.phpfreaks.com/topic/6772-mysql_queryupdate-set-where-id/#findComment-24695 Share on other sites More sharing options...
JackJack Posted April 7, 2006 Share Posted April 7, 2006 [code]mysql_query("UPDATE userinfo SET LastOn='2006000000000000' WHERE ID='$mid'")or die("Create table Error: ".mysql_error());[/code]edit:May its the format of the timestamptry something like2006-04-07 Quote Link to comment https://forums.phpfreaks.com/topic/6772-mysql_queryupdate-set-where-id/#findComment-24696 Share on other sites More sharing options...
Gingechilla Posted April 7, 2006 Author Share Posted April 7, 2006 [code]mysql_query("UPDATE userinfo SET LastOn='2006000000000000' WHERE ID='$mid'")or die("Create table Error: ".mysql_error());[/code]Still nothing, no errors no change.[!--quoteo(post=362467:date=Apr 7 2006, 10:28 AM:name=JackJack)--][div class=\'quotetop\']QUOTE(JackJack @ Apr 7 2006, 10:28 AM) [snapback]362467[/snapback][/div][div class=\'quotemain\'][!--quotec--][code]mysql_query("UPDATE userinfo SET LastOn='2006000000000000' WHERE ID='1'")or die("Create table Error: ".mysql_error());[/code]edit:May its the format of the timestamptry something like2006-04-07[/quote]That worked![code]mysql_query("UPDATE userinfo SET LastOn='2006-04-07' WHERE ID='1'")or die("Create table Error: ".mysql_error());[/code]I just need to get $mid to display.EDIT:$mid did work I was in the wrong account.THANK YOU SOOOOOOOOO MUCH BOTH OF YOU FOR YOUR HELP! :) Quote Link to comment https://forums.phpfreaks.com/topic/6772-mysql_queryupdate-set-where-id/#findComment-24697 Share on other sites More sharing options...
Gingechilla Posted April 7, 2006 Author Share Posted April 7, 2006 Sorry, one other thing, does anyone know how I can achieve the $CurrentDateTime variable?[code]$CurrentDateTime = date('YmdHis');echo "$CurrentDateTime";mysql_query("UPDATE userinfo SET LastOn='$CurrentDateTime' WHERE ID='$mid'")or die("Create table Error: ".mysql_error());[/code]I changed the LastOn from TIMESTAMP to INT, and I used[code]$timestamp = strtotime("now");mysql_query("UPDATE userinfo SET LastOn='$timestamp' WHERE ID='$mid'")or die("Create table Error: ".mysql_error());[/code]Now it all works, thanks people for all your help once again :) Quote Link to comment https://forums.phpfreaks.com/topic/6772-mysql_queryupdate-set-where-id/#findComment-24698 Share on other sites More sharing options...
JackJack Posted April 7, 2006 Share Posted April 7, 2006 Maybe this link will help [a href=\"http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html\" target=\"_blank\"]http://dev.mysql.com/doc/refman/5.0/en/dat...-functions.html[/a] I cant understand it but you probaly can :-DJJedit "sorry didnt see you were finished" Quote Link to comment https://forums.phpfreaks.com/topic/6772-mysql_queryupdate-set-where-id/#findComment-24705 Share on other sites More sharing options...
Gingechilla Posted April 7, 2006 Author Share Posted April 7, 2006 Thank you :) Quote Link to comment https://forums.phpfreaks.com/topic/6772-mysql_queryupdate-set-where-id/#findComment-24706 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.