Code: Select all
UPDATE bleh SET foo = bar WHERE bleh ....
Moderator: General Moderators
Code: Select all
UPDATE bleh SET foo = bar WHERE bleh ....
Code: Select all
<?php
$sql = "UPDATE settings SET
`title`= '$title',
`username`= '$name',
`email`= '$email',
`tablewidth`= '$width',
`menubar`= '$menubar',
`postorder`= '$postorder',
`posting`= '$posting',
`kwikpost`= '$kwikpost',
`maxshow`= '$maxshow',
`im`= '$im',
`links`= '$links',
`logo`= '$logo',
`menubarlocation`= '$menubarlocation',
`kwikpostlocation`= '$kwikpostlocation'
WHERE `somefield` = $somevalue";
?>Code: Select all
Warning: mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource in /home/adamb10/public_html/ub2/sources/admin/savesettings.php on line 14Code: Select all
$r = mysql_query($sql);
print mysql_affected_rows($r);
$sql = "UPDATE settings WHERE `title`='".$title."', `username`='".$name."', `email`='". $email."', `tablewidth`='".$width."', `menubar`='".$menubar."', `postorder`='".$postorder."', `posting`='".$posting."', `kwikpost`='".$kwikpost."', `maxshow`='".$maxshow."', `im`='".$im."', `links`='".$links."', `logo`='".$logo."', `menubarlocation`='".$menubarlocation."', `kwikpostlocation`='".$kwikpostlocation."' or print(mysql_error())";Your code flow and syntax have problems. Try this...adamb10 wrote:Anyway this is what comes up...
Heres the code...Code: Select all
Warning: mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource in /home/adamb10/public_html/ub2/sources/admin/savesettings.php on line 14
Code: Select all
$r = mysql_query($sql); print mysql_affected_rows($r); $sql = "UPDATE settings WHERE `title`='".$title."', `username`='".$name."', `email`='". $email."', `tablewidth`='".$width."', `menubar`='".$menubar."', `postorder`='".$postorder."', `posting`='".$posting."', `kwikpost`='".$kwikpost."', `maxshow`='".$maxshow."', `im`='".$im."', `links`='".$links."', `logo`='".$logo."', `menubarlocation`='".$menubarlocation."', `kwikpostlocation`='".$kwikpostlocation."' or print(mysql_error())";
Code: Select all
<?php
$sql = "UPDATE settings SET
`title`= '$title',
`username`= '$name',
`email`= '$email',
`tablewidth`= '$width',
`menubar`= '$menubar',
`postorder`= '$postorder',
`posting`= '$posting',
`kwikpost`= '$kwikpost',
`maxshow`= '$maxshow',
`im`= '$im',
`links`= '$links',
`logo`= '$logo',
`menubarlocation`= '$menubarlocation',
`kwikpostlocation`= '$kwikpostlocation'
WHERE `somefield` = $somevalue";
if (!$r = mysql_query($sql))
{
die('Could not run the query ' . $sql . ': ' . mysql_error());
}
if (!mysql_affected_rows($r))
{
echo 'There was not changes to the record';
}
else
{
echo 'The record updated successfully!';
}
?>Ok, here is the entire file...<?php
$sql = "UPDATE settings SET
`title`= '$title',
`username`= '$name',
`email`= '$email',
`tablewidth`= '$width',
`menubar`= '$menubar',
`postorder`= '$postorder',
`posting`= '$posting',
`kwikpost`= '$kwikpost',
`maxshow`= '$maxshow',
`im`= '$im',
`links`= '$links',
`logo`= '$logo',
`menubarlocation`= '$menubarlocation',
`kwikpostlocation`= '$kwikpostlocation'
WHERE `somefield` = $somevalue";
if (!$r = mysql_query($sql))
{
die('Could not run the query ' . $sql . ': ' . mysql_error());
}
if (!mysql_affected_rows($r))
{
echo 'There was not changes to the record';
}
else
{
echo 'The record updated successfully!';
}
?>
Code: Select all
<?
//savesettings.php
//essential functions to life
db_connect();
//user logged in?
if(session_is_registered('ub2')){
if(empty($password) && empty($password2)){
$r = mysql_query($sql);
print mysql_affected_rows($r);
$sql = "UPDATE settings WHERE `title`='".$title."', `username`='".$name."', `email`='". $email."', `tablewidth`='".$width."', `menubar`='".$menubar."', `postorder`='".$postorder."', `posting`='".$posting."', `kwikpost`='".$kwikpost."', `maxshow`='".$maxshow."', `im`='".$im."', `links`='".$links."', `logo`='".$logo."', `menubarlocation`='".$menubarlocation."', `kwikpostlocation`='".$kwikpostlocation."' or print(mysql_error())";
success('Settings saved.<br> Click <a href = "?action=admin">here</a> to go back to the admin panel.');
}
if($password != "") {
if($password == $password2){
mysql_query ("UPDATE settings WHERE `title`='".$title."', `username`='".$name."', `email`='". $email."', `tablewidth`='".$width."', `menubar`='".$menubar."', `postorder`='".$postorder."', `posting`='".$posting."', `kwikpost`='".$kwikpost."', `maxshow`='".$maxshow."', `im`='".$im."', `links`='".$links."', `logo`='".$logo."', `menubarlocation`='".$menubarlocation."', `kwikpostlocation`='".$kwikpostlocation."', `password`='".$password."'") or print(mysql_error());
success('Settings saved.<br> Click <a href = "?action=admin">here</a> to go back to the admin panel.');
} else {
error('The following error was returned:<br>
<b>The 2 passwords did not match</b>');
}
}
} else {
error('You do not have permission to access this page because:<br>
<b>You are not logged in</b>');
}
?>Code: Select all
<?
//savesettings.php
//essential functions to life
db_connect();
//user logged in?
if(session_is_registered('ub2')){
if(empty($password) && empty($password2)){
$r = mysql_query($sql);
print mysql_affected_rows($r);
mysql_query("UPDATE settings SET `title`='".$title."', `username`='".$name."', `email`='". $email."', `tablewidth`='".$width."', `menubar`='".$menubar."', `postorder`='".$postorder."', `posting`='".$posting."', `kwikpost`='".$kwikpost."', `maxshow`='".$maxshow."', `im`='".$im."', `links`='".$links."', `logo`='".$logo."', `menubarlocation`='".$menubarlocation."', `kwikpostlocation`='".$kwikpostlocation."'");
success('Settings saved.<br> Click <a href = "?action=admin">here</a> to go back to the admin panel.');
}
if($password != "") {
if($password == $password2){
mysql_query ("UPDATE settings SET `title`='".$title."', `username`='".$name."', `email`='". $email."', `tablewidth`='".$width."', `menubar`='".$menubar."', `postorder`='".$postorder."', `posting`='".$posting."', `kwikpost`='".$kwikpost."', `maxshow`='".$maxshow."', `im`='".$im."', `links`='".$links."', `logo`='".$logo."', `menubarlocation`='".$menubarlocation."', `kwikpostlocation`='".$kwikpostlocation."', `password`='".$password."'") or print(mysql_error());
success('Settings saved.<br> Click <a href = "?action=admin">here</a> to go back to the admin panel.');
} else {
error('The following error was returned:<br>
<b>The 2 passwords did not match</b>');
}
}
} else {
error('You do not have permission to access this page because:<br>
<b>You are not logged in</b>');
}
?>Substitute, not remove. Look at your code flow and read it logically to yourself. Doing that will make it stand out a little bit what jamiel is trying to tell you.Everah wrote:Please reread the last two posts I've made regarding the query, substitute the WHERE clause field and comparison value for your own, then report your code.
Code: Select all
<?php
/**
* What is the value of $sql in this statement...
**/
$r = mysql_query($sql);
/**
* Without a valid $r, this will error on you
**/
print mysql_affected_rows($r);
/**
* Update SQL syntax is UPDATE `table` SET `fieldname` = 'value' WHERE `searchfield` = 'searchvalue'
**/
mysql_query("UPDATE settings SET `title`='".$title."', `username`='".$name."', `email`='". $email."', `tablewidth`='".$width."', `menubar`='".$menubar."', `postorder`='".$postorder."', `posting`='".$posting."', `kwikpost`='".$kwikpost."', `maxshow`='".$maxshow."', `im`='".$im."', `links`='".$links."', `logo`='".$logo."', `menubarlocation`='".$menubarlocation."', `kwikpostlocation`='".$kwikpostlocation."'");
?>