将数据插入MySQL [英] inserting data into mysql

查看:90
本文介绍了将数据插入MySQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我插入和更新页面(通过我的管理员)到mysql的工作停止了.当我尝试插入/更新详细信息时,它会停留在同一页面上,而不会在数据库表中添加或更新任何内容.

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?

感激 弗朗切斯科

如果可以帮助插入一些代码:

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);
?>

推荐答案

它停留在同一页面上而不添加或更新任何内容"是非常常见的问题,并且可能由成千上万个错误引起.找不到遇到相同问题的人"来解决这个问题.

"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.

如果您自己想当程序员,则必须学习如何debug您的应用程序.调试代表查找错误的位置.尽管只有在您知道的情况下调试才有帮助,但是您的代码会做什么.您仍然可以尝试.

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

这篇关于将数据插入MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆