Jump to content


Photo

Error with UPDATE and INSERT


  • Please log in to reply
2 replies to this topic

#1 frankriedel

frankriedel
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 09 November 2005 - 11:06 AM

Hi All - Please take a moment to help me !

I have a page with 2 table with 2 forms, one for UPDATE and one for INSERT
the update works fine - but when there is no record in the DB and i then use the insert form the error - QUERY IS EMPTY comes up???

What do i do ???

<?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 = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING'];
}
if ((isset($HTTP_POST_VARS["MM_update"])) && ($HTTP_POST_VARS["MM_update"] == "form2")) {
$updateSQL = sprintf("UPDATE userbuy SET bruger=%s, WHERE uge=%s",
GetSQLValueString($HTTP_POST_VARS['bruger'], "text"),
mysql_select_db($database_DBZ, $DBZ);
$Result1 = mysql_query($updateSQL, $DBZ) or die(mysql_error());
$updateGoTo = "tak.php";
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $HTTP_SERVER_VARS['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}
$editFormAction1 = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$editFormAction1 .= "?" . $HTTP_SERVER_VARS['QUERY_STRING'];
}
if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO userbuy (bruger) VALUES (%s)",
GetSQLValueString($HTTP_POST_VARS['bruger'], "text"),

mysql_select_db($database_DBZ, $DBZ);
$Result1 = mysql_query($insertSQL, $DBZ) or die(mysql_error());
$insertGoTo = "tak.php";
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $HTTP_SERVER_VARS['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
$colname_Recordset1 = "1";
if (isset($HTTP_SESSION_VARS['aktuel_uge'])) {
$colname_Recordset1 = (get_magic_quotes_gpc()) ? $HTTP_SESSION_VARS['aktuel_uge'] : addslashes($HTTP_SESSION_VARS['aktuel_uge']);
}
mysql_select_db($database_DBZ, $DBZ);
$query_Recordset1 = sprintf("SELECT * FROM kokken WHERE k_uge = '%s'", $colname_Recordset1);
$Recordset1 = mysql_query($query_Recordset1, $DBZ) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
$colname_Recordset2 = "1";
if (isset($HTTP_SESSION_VARS['userN'])) {
$colname_Recordset2 = (get_magic_quotes_gpc()) ? $HTTP_SESSION_VARS['userN'] : addslashes($HTTP_SESSION_VARS['userN']);
}
mysql_select_db($database_DBZ, $DBZ);
$query_Recordset2 = sprintf("SELECT * FROM userbuy WHERE uge = '%s'", $colname_Recordset2);
$Recordset2 = mysql_query($query_Recordset2, $DBZ) or die(mysql_error());
$row_Recordset2 = mysql_fetch_assoc($Recordset2);
$totalRows_Recordset2 = mysql_num_rows($Recordset2);
?>

#2 morpheus.100

morpheus.100
  • Members
  • PipPipPip
  • Advanced Member
  • 145 posts

Posted 07 December 2005 - 10:26 AM

$query_Recordset2 = sprintf("SELECT * FROM userbuy WHERE uge = '%s'", $colname_Recordset2);

Your SQL is for a select here not an insert.

#3 frankriedel

frankriedel
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 07 December 2005 - 06:41 PM

[!--quoteo(post=325266:date=Dec 7 2005, 05:26 AM:name=morpheus.100)--][div class=\'quotetop\']QUOTE(morpheus.100 @ Dec 7 2005, 05:26 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
$query_Recordset2 = sprintf("SELECT * FROM userbuy WHERE uge = '%s'", $colname_Recordset2);

Your SQL is for a select here not an insert.
[/quote]


THX


Prob solved




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users