Forum Moderators: coopster

Message Too Old, No Replies

columns skipped when inserting into mysql

php newbie - stuck for 2 days

         

yowza

7:46 am on Jan 17, 2004 (gmt 0)

10+ Year Member



I'm having trouble with a script. I am uploading two images and inserting the image names, and other form fields, into a database.

The problem is, is that some columns are being skipped over and data is being inserted in the wrong place.

Here's the corresponding code.

<?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["MM_insert"])) && ($_POST["MM_insert"] == "addPoster")) {
$insertSQL = sprintf("INSERT INTO products (title, prodnum, price, `size`, description, fileup1, fileup2, imagealt, metakey, metatitle, metadesc, artistfirst, genre, theme) VALUES (%s, %s, %s, %s, %s, '$realname', '$realname2', %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['title'], "text"),
GetSQLValueString($_POST['prodnum'], "text"),
GetSQLValueString($_POST['price'], "double"),
GetSQLValueString($_POST['size'], "text"),
GetSQLValueString($_POST['description'], "text"),
GetSQLValueString($_POST['fileup1'], "text"),
GetSQLValueString($_POST['fileup2'], "text"),
GetSQLValueString($_POST['imagealt'], "text"),
GetSQLValueString($_POST['metakey'], "text"),
GetSQLValueString($_POST['metatitle'], "text"),
GetSQLValueString($_POST['metadesc'], "text"),
GetSQLValueString($_POST['artistfirst'], "text"),
GetSQLValueString($_POST['genre'], "text"),
GetSQLValueString($_POST['theme'], "text"));

mysql_select_db($database_connTrue, $connTrue);
$Result1 = mysql_query($insertSQL, $connTrue) or die(mysql_error());

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

It appears that the variables $realname and $realname2 are causing all trailing data to skip two columns.

Any help would be greatly appreciated.
Thanks!

Timotheos

11:04 am on Jan 17, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Shouldn't you take out
GetSQLValueString($_POST['fileup1'], "text"),
GetSQLValueString($_POST['fileup2'], "text"),

yowza

5:55 pm on Jan 17, 2004 (gmt 0)

10+ Year Member



Timotheos,

Thanks.

Worked like a charm!