HTML
<form action="../php/get_uploaded_wall.php" method="POST" enctype="multipart/form-data">
<label for="desktop_dimension_id">Desktop dimensions:</label>
<span class="checkbox">
<span class="checkbox_value">
<input id="dc1280_800" type="checkbox" name="1280x800"> 1280x800</span>
<input id="db1280_800" class="desktop_disabled" type="file" name="desktop_path_1280x800" size="100" />
<span class="checkbox_value">
<input id="dc1366_768" type="checkbox" name="1366x768"> 1366x768</span>
<input id="db1366_768" class="desktop_disabled" type="file" name="desktop_path_1366x768" size="100" />
</span>
PHP
$connectDB = mysqli_connect(HOST, USERNAME, PASSWORD, DATABASENAME);
//rename desktop walls & take out empty paths
if(!empty($_FILES[$desktop_fieldname_1280x800]['name'])){
file_exists($desktop_filename_1280x800 = strtolower($desktop_dir_1280x800 . 'wall_desktop_1280x800_' .
$_FILES[$desktop_fieldname_1280x800]['name']));
}
if(!empty($_FILES[$desktop_fieldname_1366x768]['name'])){
file_exists($desktop_filename_1366x768 = strtolower($desktop_dir_1366x768 . 'wall_desktop_1366x768_' .
$_FILES[$desktop_fieldname_1366x768]['name']));
}
SQL
//insert into SQL code here
$insert_sql = "INSERT INTO walls(d_1280x800_path, d_1366x768_path) VALUES( '{$desktop_filename_1280x800}', '{$desktop_filename_1366x768}');";
//insert into database
mysqli_query($connectDB, $insert_sql);
TABLES
以下是我的d_dimensions
表格。
d_dimension_id d_dimensions
1 1280x800
2 1366x768
和我的desktop_sizes
表。
wall_id (P,F) d_dimension_id (P,F)
我想做的是检查我的墙(未图示)表中是否上传了某个路径/ wallpapaper。因此,如果列d_1280x800_path
包含我想将其存储在desktop_sizes
表中的路径。例如,wall_id
为21
,而d_dimension_id
的{{1}}为1280x800
,1
表将成为:
desktop_sizes
另外,如果wall_id (P,F) d_dimension_id (P,F)
21 1
wall_id=21
的相同壁纸的1366x768
表格大小为desktop_sizes
,那么:
wall_id (P,F) d_dimension_id (P,F)
21 1
21 2
总结一下,如果另一个表的列包含某个值,我想更新表。在我的情况下,根据wall和d_dimensions表中的值更新desktop_sizes表。我能清楚解释一下吗?我怎么能用上面给出的代码和表格来做到这一点?