Jump to content

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


Gingechilla

Recommended Posts

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
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

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 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'");
}
[/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 :)
Link to comment
Share on other sites

[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.
Link to comment
Share on other sites

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?
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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=''");
Link to comment
Share on other sites

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

[code]
mysql_query("UPDATE userinfo SET LastOn='2006000000000000' WHERE ID='$mid'")or die("Create table Error: ".mysql_error());
[/code]
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

[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 timestamp

try something like

2006-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! :)
Link to comment
Share on other sites

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 :)
Link to comment
Share on other sites

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"
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.