Breana
08-22-2007, 03:21 PM
I got the update to work once, the user points went from 15 to 20 after i submited the code form.
But now it wont... tried 40 times!
$sql = INSERT INTO 'users' SET 'points'=[+5] WHERE 'userid'= '$userid';
$result = mysql_query($sql ,$db);
Is there an easy way to do this?
BrainDonor
08-22-2007, 03:47 PM
I got the update to work once, the user points went from 15 to 20 after i submited the code form.
But now it wont... tried 40 times!
Is there an easy way to do this?
try changing "insert into" to "update".
Znupi
08-22-2007, 03:59 PM
$sql = "UPDATE `users` SET `points`=[+5] WHERE `userid`= '$userid'";
Try that :)
Breana
08-22-2007, 05:19 PM
Im being told on another forum i dident set the table up right thats why it wont update?
How do i set it up so the default is 0 and max unlimited.
So evet time i add 5+ it goes up....:confused:
Stephen Philbin
08-23-2007, 02:57 AM
You can't set an integer column to have no upper limit, but the highest upper limit allowed is still pretty high. Try to use the update query the others have suggested. Insert only works once. Once you have a row of data in your database, you can only update it. You can not overwrite an old row of data with another insert.
If the update query still doesn't work, post back here with the query you used to create the table and an queries you're using to insert and update the row with.
Breana
08-23-2007, 10:57 AM
Nope it still wont save it....
It saves the game title content photo but when it gets to the update points it don't seem to do anything?
So i will post the full code + the sql i used to creat the table.
Save.php
<?php
if (logincheck($uid, $upwd)) {
$error = false;
$errormessage = "";
if (strlen($itemtitle) < 1) {
$error = true;
$errormessage .= "<li><b>Sorry. You did not enter a <?php printf($itemlower); ?> title.</b><br>\n";
}
if (strlen($directions) < 1) {
$error = true;
$errormessage .= "<li><b>Sorry. You did not enter any directions.</b><br>\n";
}
if ($catid == "") {
$error = true;
$errormessage .= "<li><b>Sorry. You did not chose a category.</b><br>\n";
}
IF ($_FILES['frmpicture']['type'] != "") {
if (($_FILES['frmpicture']['type'] == "image/gif") || ($_FILES['frmpicture']['type'] == "image/jpeg") || ($_FILES['frmpicture']['type'] == "image/jpg") || ($_FILES['frmpicture']['type'] == "image/pjpeg")) {
printf("<br /><img src=\"icons/Checked_OK.gif\" width=\"19\" height=\"18\" /> <font face='Arial, Helvetica, sans-serif' size=2>Box Art Uploaded<br><br>");
printf("<img src=\"images/view_profile.png\" width=\"24\" height=\"24\" />" . $_FILES['frmpicture']['name']);
if ($_FILES['frmpicture']['type'] == "image/gif") {
$imageext = "gif";
} else {
$imageext = "jpg";
}
} else {
$error = true;
$errormessage .= "file: " . $filetest . "<li><b> Sorry. You did not enter a valid picture.</b><br>\n";
}
} else {
printf ("<br><img src=\"icons/Error_NotOK.gif\" width=\"18\" height=\"18\" /> <b>No Box Art Uploaded<br></b>");
}
if ($error) {
printf("<font face='Arial, Helvetica, sans-serif' size=2>There was a problem creating the <?php printf($itemlower); ?>. Please click on back in your browser to fix the problems listed below.<br><br>");
printf($errormessage);
} else {
$sql = "select approve_content from admin_control";
$result = mysql_query($sql ,$db);
if ($myrow = mysql_fetch_array($result)) {
do {
$approve = $myrow["approve_content"];
} while ($myrow = mysql_fetch_array($result));
}
if ($approve == "Y") {
$status = "W";
} else {
$status = "L";
}
$itemid = nextid("items", "itemid");
$date = dbdate();
$newdirections = ereg_replace("\n", "<BR>\n", $directions);
$sql = "INSERT INTO items (
`itemid`,
`title`,
`directions`,
`rating`,
`categoryid`,
`date`,
`status`,
`gameinfo`,
`gamerating`,
`publisher`,
`genar`,
`userid`
) VALUES (
'".(int)$itemid."',
'".mysql_real_escape_string($itemtitle)."',
'".mysql_real_escape_string($newdirections)."',
'0',
'".(int)$catid."',
'".mysql_real_escape_string($date)."',
'".mysql_real_escape_string($status)."',
'".mysql_real_escape_string($gameinfo)."',
'".mysql_real_escape_string($gamerating)."',
'".mysql_real_escape_string($publisher)."',
'".mysql_real_escape_string($genar)."',
'".(int)$uid."'
)";
$result = mysql_query($sql ,$db);
$sql = "UPDATE `users` SET `points`=`points`+5 WHERE `userid`='$userID' LIMIT 1";
$result = mysql_query($sql ,$db);
if (($_FILES['frmpicture']['type'] == "image/gif") || ($_FILES['frmpicture']['type'] == "image/jpeg") || ($_FILES['frmpicture']['type'] == "image/pjpeg")) {
if ($_FILES['frmpicture']['type'] == "image/gif") {
$imageext = "gif";
} else {
$imageext = "jpg";
}
copy ($_FILES['frmpicture']['tmp_name'], "boxart/" . $itemid . "." . $imageext);
}
if ($approve == "Y") {
printf("<p><img src=\"icons/Checked_OK.gif\" width=\"18\" height=\"18\" /> <font face=arial size=-1>The <?php printf($itemlower); ?> has been added and is waiting approval.</font><br /><br />Once your game is added you'll recive your points</p>");
} else {
printf("<p><font face=arial size=-1>The <?php printf($itemlower); ?> has been added to the database.</font></b</p>");
}
printf("<p><font face=arial size=-1><a href=additem.php>Add another <?php printf($itemlower); ?></a></font></p>");
}
?>
SQL users, Points table..
--
-- Table structure for table `users`
--
CREATE TABLE `users` (
`userid` int(10) unsigned NOT NULL default '0',
`login` varchar(50) NOT NULL default '',
`password` varchar(50) NOT NULL default '',
`email` varchar(255) default NULL,
`newsletter` int(1) unsigned default NULL,
`gender` varchar(50) default NULL,
`aboutme` text,
`points` int(11) NOT NULL default '0',
PRIMARY KEY (`userid`),
UNIQUE KEY `userid` (`userid`,`login`),
KEY `userid_2` (`userid`,`login`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
On another note, i was told i don't need the "UNIQUE KEY `userid` (`userid`,`login`),
KEY `userid_2` (`userid`,`login`)" its usless and slows the site down is that true?