Jump to content

[SOLVED] Mysql will not update :S


jamesxg1

Recommended Posts

Here's my code:

 

<?php session_start(); 

require("../db/db.php"); //include database file
require("../db/config.php"); //include configuration file
require("../db/util.php");

isloggedin();
accessneeded("A");
?>
<?php
// some code
$sql = "SELECT `header`,`footer`,`title` FROM `settings`";
$query = mysql_query($sql);
while ($row = mysql_fetch_assoc($query)) {
$foot = $row['footer'];
$head = $row['header'];
$tit = $row['title'];
}

?>
<title>Update Site Settings</title>
<?php
if(isset($_POST['submit'])) {
  $footer = strip_tags(mysql_real_escape_string($_POST['footer']));
  $header = strip_tags(mysql_real_escape_string($_POST['header']));
  $title = strip_tags(mysql_real_escape_string($_POST['title']));
  $sql = "UPDATE settings SET footer = '$footer', header = '$header', title = '$title'";
  mysql_query($sql) or die(mysql_error());
  echo ("Update Complete");
  exit;
}
?>

<html>
<style type="text/css">

.progress{
width: 1px;
height: 14px;
color: white;
font-size: 12px;
  overflow: hidden;
background-color: orange;
padding-left: 5px;
}

</style>

<script type="text/JavaScript">

function textCounter(field,counter,maxlimit,linecounter) {
// text width//
var fieldWidth =  parseInt(field.offsetWidth);
var charcnt = field.value.length;        

// trim the extra text
if (charcnt > maxlimit) { 
	field.value = field.value.substring(0, maxlimit);
}

else { 
// progress bar percentage
var percentage = parseInt(100 - (( maxlimit - charcnt) * 100)/maxlimit) ;
document.getElementById(counter).style.width =  parseInt((fieldWidth*percentage)/100)+"px";
document.getElementById(counter).innerHTML="Limit: "+percentage+"%"
// color correction on style from CCFFF -> CC0000
setcolor(document.getElementById(counter),percentage,"background-color");
}
}

function setcolor(obj,percentage,prop){
obj.style[prop] = "rgb(80%,"+(100-percentage)+"%,"+(100-percentage)+"%)";
}

</script>
<script type="text/javascript">
function capitalize(input)
{
val = input.value;
newVal = '';
val = val.split(' ');
for(var i = 0; i < val.length; i++) 
{
newVal += val[i].substring(0,1).toUpperCase() +
val[i].substring(1).toLowerCase() + ' ';
}
input.value = newVal;
}
</script>
</head>
<title>Edit Profile</title>
<body><center>
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<h4>Level of used characters per textarea:
<div id="progressbar1" class="progress"></div>
<script>textCounter(document.getElementById("maxcharfield1"),"progressbar1",1000)</script>

<h2>Footer</h2>
<textarea rows="5" cols="40" name="footer" id="$footer" 
onKeyDown="textCounter(this,'progressbar1',100)" 
onKeyUp="textCounter(this,'progressbar1',100)" 
onFocus="textCounter(this,'progressbar1',100)" onChange="capitalize(this);" value="<?php print $foot ?>"></textarea><br /><br>

<h2>Header</h2>
<textarea rows="5" cols="40" name="header" id="$header" 
onKeyDown="textCounter(this,'progressbar1',100)" 
onKeyUp="textCounter(this,'progressbar1',100)" 
onFocus="textCounter(this,'progressbar1',100)" onChange="capitalize(this);"></textarea><br /><br>

<h2>Title</h2>
<textarea rows="5" cols="40" name="title" id="$title" 
onKeyDown="textCounter(this,'progressbar1',100)" 
onKeyUp="textCounter(this,'progressbar1',100)" 
onFocus="textCounter(this,'progressbar1',100)" onChange="capitalize(this);"></textarea><br /><br>



<input type="submit" name="submit" value="Submit">
</form>
</center>
</body>
</html>

 

It will not update the tables :S

 

Any help here guys ?

Link to comment
Share on other sites

Are you getting an error message?

 

nope it does the echo and there is no data in the actuall DB i think it could be because i took out the WHERE section out of the query ?

yap but no

reading for your sql query.. imho... that query will change EVERYTHING in your table settings into what u update

 

forexample.. it there 4 rows.. ALL 4 rows will change all

 

i kinda curios about this

<?php
if(isset($_POST['submit'])) {
  $footer = strip_tags(mysql_real_escape_string($_POST['footer']));
  $header = strip_tags(mysql_real_escape_string($_POST['header']));
  $title = strip_tags(mysql_real_escape_string($_POST['title']));
  $sql = "UPDATE settings SET footer = '$footer', header = '$header', title = '$title'";
  mysql_query($sql) or die(mysql_error());
  echo ("Update Complete");
  exit;
}
?>

can you change

like this

<?php
print_r($_POST); //hmm i wan't to know what in this?
if(isset($_POST)) {
  $footer = strip_tags(mysql_real_escape_string($_POST['footer']));
  $header = strip_tags(mysql_real_escape_string($_POST['header']));
  $title = strip_tags(mysql_real_escape_string($_POST['title']));
  $sql = "UPDATE settings SET footer = '$footer', header = '$header', title = '$title'";
  mysql_query($sql) or die(mysql_error());
  echo ("Update Complete");
  exit;
}
?>

>>If there is no data in the table, what exactly is it supposed to be updating?

i assume there a data inside ^^

your answer are correct too ^^

Link to comment
Share on other sites

If there is no data in the table, what exactly is it supposed to be updating?  UPDATE modifies existing data.

 

Hiya!,

 

D.w fixed it was the java it was for some litrully unknown reason stopping it updating my db :)

 

Thanks guys

 

James.

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.