I am trying to upload to SQL database the name of the uploaded image (for example : test.png) using DW Server behaviors
I am getting this error message:
** Notice: Undefined index: upload in C:\xampp\htdocs\Foglalo\pages\addRooms.php on line 95 Column 'img' cannot be null" **
<?php
if (!fun
ction_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($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"] == "addRooms")) {
$insertSQL = sprintf("INSERT INTO rooms (RoomName, City, Street, Postcode, RoomType, img) VALUES (%s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['roomname'], "text"),
GetSQLValueString($_POST['city'], "text"),
GetSQLValueString($_POST['street'], "text"),
GetSQLValueString($_POST['postcode'], "text"),
GetSQLValueString($_POST['roomtype'], "text"),
GetSQLValueString($_POST['upload'], "text"));
mysql_select_db($database_Foglalo, $Foglalo);
$Result1 = mysql_query($insertSQL, $Foglalo) or die(mysql_error());
}
mysql_select_db($database_Foglalo, $Foglalo);
$query_addRoom = "SELECT * FROM rooms";
$addRoom = mysql_query($query_addRoom, $Foglalo) or die(mysql_error());
$row_addRoom = mysql_fetch_assoc($addRoom);
$totalRows_addRoom = mysql_num_rows($addRoom);
?>
my form
<form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" name="addRooms" id="addRooms">
<table width="600" align="center" class="TableRightBorder">
<tbody>
<tr>
<td width="119">Room name</td>
<td width="200"><input type="text" name="roomname" id="roomname" /></td>
<td width="265"> </td>
</tr>
<tr>
<td height="20"> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td height="20">City</td>
<td><input type="text" name="city" id="city" /></td>
<td> </td>
</tr>
<tr>
<td height="20"> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td height="20">Street</td>
<td><input type="text" name="street" id="street" /></td>
<td> </td>
</tr>
<tr>
<td height="20"> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td height="20">Postcode</td>
<td><input type="text" name="postcode" id="postcode" /></td>
<td> </td>
</tr>
<tr>
<td height="20"> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td height="20">Room type</td>
<td><select name="roomtype" id="roomtype">
<option value="room">Room</option>
<option value="office">Office</option>
</select></td>
<td> </td>
</tr>
<tr>
<td height="20"> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td height="20">Room image</td>
<td><input type="file" name="img" id="upload" /></td>
<td> </td>
</tr>
<tr>
<td height="20"> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td height="20">Description</td>
<td><textarea name="textarea" id="textarea" cols="30" rows="5"></textarea></td>
<td> </td>
</tr>
<tr>
<td height="20"> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td height="20"> </td>
<td><input name="submit" type="submit" class="right" id="submit" value="Add room" /></td>
<td> </td>
</tr>
</tbody>
</table>
<input type="hidden" name="MM_insert" value="addRooms" />
</form>
Aucun commentaire:
Enregistrer un commentaire