Jump to content


Photo

mysql_query("UPDATE ?????? SET ??????='??????????????' WHERE ID='??????'");


  • Please log in to reply
13 replies to this topic

#1 Gingechilla

Gingechilla
  • Members
  • PipPipPip
  • Advanced Member
  • 34 posts

Posted 07 April 2006 - 01:52 AM

Hi I am trying to get the string to work:

mysql_query("UPDATE userinfo SET LastOn='2006000000000000' WHERE ID='$mid'");

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 :(


Table Name:

userinfo


Rows:

ID - int(11)
LastOn - timestamp(14)
uCat1 - varchar(15)
uCat2 - varchar(15)
uCat3 - varchar(15)
uCat4 - varchar(15)
uCat5 - varchar(15)


Other Info:

$mid - A number in the page depending on the members id. E.g. 1

#2 JustinK101

JustinK101
  • Members
  • PipPipPip
  • Advanced Member
  • 503 posts
  • LocationSan Diego, California, US

Posted 07 April 2006 - 02:16 AM

Try:

[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--]$sql = "[span style=\'color:blue;font-weight:bold\']UPDATE userinfo SET LastOn = '[/span]2006000000000000' [span style=\'color:green\']WHERE ID = '[/span]" . $mid . "';
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) View Post[/div][div class=\'quotemain\'][!--quotec--]
Hi I am trying to get the string to work:

mysql_query("UPDATE userinfo SET LastOn='2006000000000000' WHERE ID='$mid'");

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 :(
Table Name:

userinfo
Rows:

ID - int(11)
LastOn - timestamp(14)
uCat1 - varchar(15)
uCat2 - varchar(15)
uCat3 - varchar(15)
uCat4 - varchar(15)
uCat5 - varchar(15)
Other Info:

$mid - A number in the page depending on the members id. E.g. 1
[/quote]

#3 Gingechilla

Gingechilla
  • Members
  • PipPipPip
  • Advanced Member
  • 34 posts

Posted 07 April 2006 - 03:03 AM

Thanks, but that did not work :-/ created an error:

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

Line 56+ is:

if(!isset($_GET['page'])){ 
    $page = 1; 
} else { 
    $page = $_GET['page']; 
}

Heres the actual bit of code if it helps:

//userinfo table checker and updater

if(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'");
}

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 :)

#4 JustinK101

JustinK101
  • Members
  • PipPipPip
  • Advanced Member
  • 503 posts
  • LocationSan Diego, California, US

Posted 07 April 2006 - 03:12 AM

if(!isset($_GET['page'])){ 
    $page = 1; 
} else { 
    $page = $_GET['page']; 
}

That should be fine. The following code you have is VERY VERY hard for me to read, so I tried and re-write it.

$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);
}

I didnt test this, so there may be small errors, but the overall logic should be right.

#5 Gingechilla

Gingechilla
  • Members
  • PipPipPip
  • Advanced Member
  • 34 posts

Posted 07 April 2006 - 03:23 AM

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?

#6 JustinK101

JustinK101
  • Members
  • PipPipPip
  • Advanced Member
  • 503 posts
  • LocationSan Diego, California, US

Posted 07 April 2006 - 04:23 AM

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 PUT

echo "SQL = " . $sql . "<br>";
echo "Numb Rows = " . $num_rows . "<br>";

---- > REST OF CODE AFTER

Then paste the results here, of when you view the page.

#7 Gingechilla

Gingechilla
  • Members
  • PipPipPip
  • Advanced Member
  • 34 posts

Posted 07 April 2006 - 09:05 AM

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=''");

#8 JackJack

JackJack
  • Members
  • PipPipPip
  • Advanced Member
  • 38 posts

Posted 07 April 2006 - 09:23 AM

The problem is is that your

LastOn - timestamp(14)


Is only 14 long the number your using is 15 or 16 :S



edit:

Adding
'or die("Create table Error: ".mysql_error());'
would tell you what is wrong

mysql_query("UPDATE userinfo SET LastOn='2006000000000000' WHERE ID='$mid'")or die("Create table Error: ".mysql_error());


#9 Gingechilla

Gingechilla
  • Members
  • PipPipPip
  • Advanced Member
  • 34 posts

Posted 07 April 2006 - 09:26 AM

Thanks, however still no change:

I just ran:
mysql_query("UPDATE youritems SET LastOn='20060000000000' WHERE LastOn='00000000000000'");

and that did nothing.

Corrects Error:
mysql_query("UPDATE userinfo SET LastOn='20060000000000' WHERE LastOn='00000000000000'");
Still no change.

#10 JackJack

JackJack
  • Members
  • PipPipPip
  • Advanced Member
  • 38 posts

Posted 07 April 2006 - 09:28 AM

mysql_query("UPDATE userinfo SET LastOn='2006000000000000' WHERE ID='$mid'")or die("Create table Error: ".mysql_error());


edit:
May its the format of the timestamp

try something like

2006-04-07





#11 Gingechilla

Gingechilla
  • Members
  • PipPipPip
  • Advanced Member
  • 34 posts

Posted 07 April 2006 - 09:35 AM

mysql_query("UPDATE userinfo SET LastOn='2006000000000000' WHERE ID='$mid'")or die("Create table Error: ".mysql_error());

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) View Post[/div][div class=\'quotemain\'][!--quotec--]
mysql_query("UPDATE userinfo SET LastOn='2006000000000000' WHERE ID='1'")or die("Create table Error: ".mysql_error());
edit:
May its the format of the timestamp

try something like

2006-04-07
[/quote]

That worked!

mysql_query("UPDATE userinfo SET LastOn='2006-04-07' WHERE ID='1'")or die("Create table Error: ".mysql_error());

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! :)

#12 Gingechilla

Gingechilla
  • Members
  • PipPipPip
  • Advanced Member
  • 34 posts

Posted 07 April 2006 - 09:52 AM

Sorry, one other thing, does anyone know how I can achieve the $CurrentDateTime variable?

$CurrentDateTime = date('YmdHis');
echo "$CurrentDateTime";
mysql_query("UPDATE userinfo SET LastOn='$CurrentDateTime' WHERE ID='$mid'")or die("Create table Error: ".mysql_error());

I changed the LastOn from TIMESTAMP to INT, and I used

$timestamp = strtotime("now");
mysql_query("UPDATE userinfo SET LastOn='$timestamp' WHERE ID='$mid'")or die("Create table Error: ".mysql_error());

Now it all works, thanks people for all your help once again :)

#13 JackJack

JackJack
  • Members
  • PipPipPip
  • Advanced Member
  • 38 posts

Posted 07 April 2006 - 10:26 AM

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 :-D

JJ

edit "sorry didnt see you were finished"

#14 Gingechilla

Gingechilla
  • Members
  • PipPipPip
  • Advanced Member
  • 34 posts

Posted 07 April 2006 - 10:27 AM

Thank you :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users