Jump to content

Error with UPDATE and INSERT


Recommended Posts

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

?>

Link to comment
https://forums.phpfreaks.com/topic/2835-error-with-update-and-insert/
Share on other sites

  • 4 weeks later...

[!--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) 325266[/snapback][/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.

 

 

THX

 

 

Prob solved

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.