views:

59

answers:

2

Hi Guys,

My insert and update pages (through my admin forlder) into mysql stopped working. When I try to insert/update details it stays on the same page without adding or updating anything into the database table.

I really don't know what happened and don't know where start looking. I didn't make any change to the pages whatsoever.

Is there anyone who had the same problem and can kindly give me a clue?

Appreciated Francesco

Insertng some code if it can be of nay help:

    <?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if(isset($_POST['username'])) {
mysql_select_db($database_satsconn, $satsconn);
$query_rstUname = "SELECT members_ID FROM members WHERE username = '$_POST[username]'";
$rstUname = mysql_query($query_rstUname, $satsconn) or die(mysql_error());
$row_rstUname = mysql_fetch_assoc($rstUname);
$totalRows_rstUname = mysql_num_rows($rstUname);
if($totalRows_rstUname > 0){
$error['uname'] = 'That username is already in use. Please choose another.';
    }
}

if(isset($_POST['pwd']) && isset($_POST['pwd'])) {
 if($_POST['pwd'] != $_POST['con_pwd']) {
   $error['pwd'] = 'Your passwords don\'t match.';
   }
  else {
  $_POST['pwd'] =md5($_POST['pwd']);
  }
}

if(!isset($error)) {
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "addUser")) {
  $insertSQL = sprintf("INSERT INTO members (realname, username, pwd) VALUES (%s, %s, %s)",
                       GetSQLValueString($_POST['realname'], "text"),
                       GetSQLValueString($_POST['username'], "text"),
                       GetSQLValueString($_POST['pwd'], "text"));

  mysql_select_db($database_satsconn, $satsconn);
  $Result1 = mysql_query($insertSQL, $satsconn) or die(mysql_error());
   }
}

if ((isset($_POST['members_ID'])) && ($_POST['members_ID'] != "")) {
  $deleteSQL = sprintf("DELETE FROM members WHERE members_ID=%s",
                       GetSQLValueString($_POST['members_ID'], "int"));

  mysql_select_db($database_satsconn, $satsconn);
  $Result1 = mysql_query($deleteSQL, $satsconn) or die(mysql_error());

  $deleteGoTo = "add_member.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?";
    $deleteGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $deleteGoTo));
}

mysql_select_db($database_satsconn, $satsconn);
$query_rstAdmin = "SELECT * FROM members ORDER BY realname ASC";
$rstAdmin = mysql_query($query_rstAdmin, $satsconn) or die(mysql_error());
$row_rstAdmin = mysql_fetch_assoc($rstAdmin);
$totalRows_rstAdmin = mysql_num_rows($rstAdmin);
?>
+1  A: 

"it stays on the same page without adding or updating anything" is very common problem and can be caused by thousands of errors. There is noway to solve it by finding "anyone who had the same problem".

If you're just user of this code, it would be better to hire a programmer.

If you supposed to be a programmer yourself, you have to learn how to debug your application. Debugging stands for finding where the error is. Although debugging could help only if you know, what your code does. You can try it anyway.

There are many things to do. You have to be sure that you can see all possible errors. You can start from this useful article

Col. Shrapnel
When is said "anyone who had the same problem..." I meant when all worked fine and well and suddently for no reason it stopped working. Without making any changes to the pages and without giving any error.I am pretty sure the code is fine.Your comment is noted (sic!) but pretty useless.
francesco
@francesco no, it is not useless. You just don't understand programming basics :) There is no magic wand to tell you where is the problem and how to solve it. It's **hard work**. And you're going into it. But the information from the link in my post could ease it. Anyway, it is your duty to determine at least where the problem is - in the browser. or in the php or in the mysq. Noone can do it for you.
Col. Shrapnel
The problem (and also my question) is why all worked fine for a long while and now it stopped?Is not question of understanding programm basics, which I do, it is just how can some code work fine for a long while but suddently it doesn't? Code is not changed.What I am asking is a clue about how something like that can even happen. I can go deep into the code and try to find the problem but I would like to do it wiht come clues in mind.
francesco
@francesco your code runs not in the vacuum. It runs on the server, in the browser, on the PC. It is called environment and it can cause problems even while your code didn't change. Does this answer suit you?
Col. Shrapnel
I am not sure. If it is meant to be offensive, No. Still you are offending me assuming that I am an absolutely prick and don't know what I am doing. I think we better stop here. Your help was appreciated.
francesco
@francesco no, I am not offending but you don't know what you're doing. That's a fact. Facts cannot be offensive. And in this latter comment I merely answered your question and nothing more. Being too touchy won't help you to set your app to working. C'mon pal, lets go to the programming topics. Do you confirm it's client side problem?
Col. Shrapnel
The problem in only on my linux server. On my localhost all works fine.php 5 on both
francesco
@francesco no, no. every web application has 2 parts: server side and client side. even if your website runs on the linux server, you see your update form in your browser, on your PC. It is called "client side". If your form refuse to submit - it's client side problem. Does your admin folder use any AJAX features?
Col. Shrapnel
PS: are you a teacher? Your "no" sounds like a teacher speaking.
francesco
So we know that there is a problem with my code. How come the same code workd ok on my local server and not on the remote server?There is some ajax but not on those pages
francesco
A: 

I see there's a lot of if(isset($variable)) on the code. What happens if isset($_POST['MM_insert']) returns false? Put some error traps (a simple echo telling that the variable isn't set will do) to see where exactly the code stops working, and then you'll see why it stopped working.
Also, try using print_r() on the possible-problematic variable to see if you're getting exactly what you're expecting.
PS: I'd use only one db selection. I think there's no need to do it more than once in this case, except you explicitly need and want to use a different db.

Jorge