Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 10th, 2005, 06:25 AM
Registered User
 
Join Date: Nov 2005
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default UPDATE and INSERT on same page - ERROR

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

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert/Update problem soheil BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 5 November 15th, 2007 11:18 AM
T-SQL statement causing error with insert/update saf SQL Language 0 September 7th, 2007 04:48 PM
insert and/or update statement carswelljr SQL Language 3 September 28th, 2006 10:03 AM
INSERT, UPDATE, DELETE dagad ASP.NET 2.0 Professional 0 September 27th, 2006 01:22 AM
Help With INSERT + UPDATE Trigger HenryE SQL Server 2000 1 December 11th, 2003 06:26 PM



All times are GMT -4. The time now is 07:02 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.