Jump to content

Not Updating


Lamez

Recommended Posts

The script below is suppose to see if there is any data in the MySQL table, and if there is it uses the MySQL update function, if not then it is suppose to add the new data.

 

It does not update or add, what am I doing wrong here?

 

<?php
include ("../../style/include/session.php");
include ("../../style/include/cons/head_2.php");
if($session->isAdmin()){
print '<div class="box"><h2>Point Value Settings</h2>';
?>
<SCRIPT TYPE="text/javascript">
function numbersonly(myfield, e, dec)
{
var key;
var keychar;

if (window.event)
   key = window.event.keyCode;
else if (e)
   key = e.which;
else
   return true;
keychar = String.fromCharCode(key);

// control keys
if ((key==null) || (key==0) || (key== || 
    (key==9) || (key==13) || (key==27) )
   return true;

// numbers
else if ((("0123456789").indexOf(keychar) > -1))
   return true;

// decimal point jump
else if (dec && (keychar == "."))
   {
   myfield.form.elements[dec].focus();
   return false;
   }
else
   return false;
}

//-->
</SCRIPT>
<?php
$getlink = $_GET["action"];
$link = md5("addpointstodb");
if ($getlink == $link) {
if(isset ($_POST['Submit'])){
  $a = $_POST['1'];
  $b = $_POST['2'];
  $c = $_POST['3'];
  $d = $_POST['4'];
  $e = $_POST['5'];
  $f = $_POST['6'];

  
   $q = "Select count(*) as row_count from `points`";
   $r = mysql_query($q) or die(mysql_error()."<br /><br />".$q);
  if(mysql_num_rows($r) >0){
$q = "UPDATE `points` SET `1`=$a WHERE `1`='$a', '$b', '$c'";

mysql_query($q)or die(mysql_error());
echo "Updated Points to Database";
echo '<br><br><a href="pinval.php">View Points</a>';
  }else{
    $q = "INSERT INTO `points` VALUES ('$a', '$b', '$c', '$d', '$e', '$f', '$g')";
mysql_query($q)or die(mysql_error());
echo "Added points to Database";
echo '<br><br><a href="pinval.php">View Points</a>';
  }  
}else{
echo "No data to enter";
echo '<br><br><a href="pinval.php">Try Again</a>';
}
}else{
$paid = "select * from points";
$q = mysql_query($paid) or die('Error: ' . mysql_error());
$rs=mysql_fetch_array($q);
?>


<form name="updatepoints" method="post" action="?action=<?php echo $link; ?>">
<table width="387" height="198" border="0">
  <tr>
    <td width="136"><strong>Round Name </strong></td>
    <td width="124"><strong>Point Value </strong></td>
    <td width="113"> </td>
  </tr>
  <tr>
    <td>1st Round </td>
    <td align="center"><input name="2" type="text" id="2" onkeypress="return numbersonly(this, event)" size="10" value="<?php echo $rs['2']; ?>" /></td>
    <td> </td>
  </tr>
  <tr>
    <td>2nd Round </td>
    <td align="center"><input name="3" type="text" id="3" onkeypress="return numbersonly(this, event)" size="10" value="<?php echo $rs['3']; ?>" /></td>
    <td> </td>
  </tr>
  <tr>
    <td>Sweet 16 </td>
    <td align="center"><input name="4" type="text" id="4" onkeypress="return numbersonly(this, event)" size="10" value="<?php echo $rs['4']; ?>" /></td>
    <td> </td>
  </tr>
  <tr>
    <td>Elite Eight </td>
    <td align="center"><input name="5" type="text" id="5" onkeypress="return numbersonly(this, event)" size="10" value="<?php echo $rs['5']; ?>" /></td>
    <td> </td>
  </tr>
  <tr>
    <td>Final Four </td>
    <td align="center"><input name="6" type="text" id="6" onkeypress="return numbersonly(this, event)" size="10" value="<?php echo $rs['6']; ?>" /></td>
    <td> </td>
  </tr>
  <tr>
    <td>Championship</td>
    <td align="center"><input name="7" type="text" id="7" onkeypress="return numbersonly(this, event)" size="10" value="<?php echo $rs['7']; ?>" /></td>
    <td> </td>
  </tr>
  <tr>
    <td> </td>
    <td align="left"><input type="submit" name="Submit" value="Submit" />
      <input name="Reset" type="reset" id="Reset" value="Reset" /></td>
    <td align="left"><label></label></td>
  </tr>
</table>
</form>
<p> </p>

<?php
}
}else{
header("Location: ../../index.php");
}
print '</div>';
include ("../../style/include/cons/foot.php");
?>

Link to comment
https://forums.phpfreaks.com/topic/92660-not-updating/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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