gpt4 book ai didi

php - 我也尝试使用图像更新来更新我的数据,但是图像 isset 在 php 中不起作用

转载 作者:行者123 更新时间:2023-11-29 20:18:14 25 4
gpt4 key购买 nike

嘿伙计们,我也创建了一个带有图像上传的注册表单,但是当我尝试更新此表单时,我尝试获取 ID,但我的图像的 isset 不起作用,所以它不会运行我的更新查询,请检查它出

这是更新表单,其中将显示所有值以供编辑,现在我可以在提交按钮的 isset 条件下运行更新功能,然后更新数据

    <title>Register Update</title>
<?php
//error_reporting(0);
$id=$_GET['id'];

function __autoload($classname)
{
include "$classname.php";
}
$obj = new connect();
$st=$obj->con();

if (isset($_POST['sub']))
{
$upd= new update();
$upd->updatedata($_POST);
}





$qry = "select * from register ";
$run = mysqli_query($st,$qry);
$row = mysqli_fetch_assoc($run);
{
$g = $row['gen'];
$l = $row['lang'];
}


$query=mysqli_query($st,"select * from register where id='$id'");
//echo "<ul>";
while($query2=mysqli_fetch_assoc($query))
{
//print_r($query2);
echo "<form method='POST' action='RegisterRetrieve.php'>";
echo "<table>";
?>

<p><input type="hidden" name="sid" value="<?php echo $query2['id']; ?>"></p>
<tr>
<td>
First Name:
</td>
<td><input type="text" name="uname" value="<?php echo $query2['uname']; ?>"></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="pwd" value="<?php echo $query2['pwd']; ?>"></td>
</tr>
<tr>
<td>Email Id:</td>
<td><input type="text" name="emailid" value="<?php echo $query2['emailid']; ?>"
</td>
</tr>
<tr>
<td>Radio Button: Are you male or female?</td>
<?php
if ($g == "male"){
echo "<td><input type='radio' name='gen' value='Male' id='gen' checked> Male <input type='radio' name='gen' value='Female' id='gen'> Female </td>";
}
else
{
echo "<td><input type='radio' name='gen' value='Male' id='gen'> Male <input type='radio' name='gen' value='Female' id='gen' checked> Female </td>";
}
?>
</tr>
<tr>
<td>Check Box: Check the languages you know?</td>
<td><?php
$lang=explode(',',$l);
//print_r($lang);
if(in_array('Cricket', $lang))
echo '<input type="checkbox" name="lang[0]" value="Cricket" checked>Cricket';
else
echo '<input type="checkbox" name="lang[0]" value="Cricket">Cricket';
if(in_array('Basketball', $lang))
echo '<input type="checkbox" name="lang[1]" value="Basketball" checked>Basketball';
else
echo '<input type="checkbox" name="lang[1]" value="Basketball">Basketball';

if(in_array('Hockey', $lang))
echo '<input type="checkbox" name="lang[2]" value="Hockey" checked>Hockey';
else
echo '<input type="checkbox" name="lang[2]" value="Hockey">Hockey'."<br>";
?>
</td>
</tr>
<tr>
<td>Mobile No:</td>
<td><input type="text" name="mobile" value="<?php echo $query2['mobile']; ?>"
</td>
</tr>
<tr>
<td>10th Marks:</td>
<td><input type="text" name="marks_10" value="<?php echo $query2['10marks'];?>"
</td>
</tr>
<tr>
<td>
12th Marks:</td>
<td><input type="text" name="marks_12" value="<?php echo $query2['12marks'];?>"</td>
</tr>
<tr>
<td>
Browse Image:</td>
<td><input type="file" name="file1"></td>
<td><img src='img/<?php echo $query2['name'];?>' width='150px' height='150px'></td>
</tr>
<tr>
<td>
<select name="priority">
<option value="admin">
admin
</option>
<option value="<?php echo $query2['priority']; ?>"><?php echo $query2['priority']; ?>
</option>
<option value="superadmin">
superadmin
</option>

</select>
</td>
</tr>
<tr>
<td></td>
<td>
<input type="submit" value="submit" name="sub"><br>
</td>
</tr>
<?php

echo "<table>";
echo "</form>";
}
//echo "</ul>";



?>

现在我正在使用我的更新查询,但是当我尝试设置我的图像时,它不会处于这种情况

    <?php

class update extends connect
{

function updatedata($rel)
{
$obj= new connect();
$obj->con();


extract($_POST);

$id=$_GET['id'];

$line = implode("," ,$lang);
print_r($_POST);


if(isset($_FILES["file1"]))
{

extract($_POST);
echo "hello";
$name = $_FILES['file1']['name'];

$type = $_FILES['file1']['type'];

$size = $_FILES['file1']['size'];

$tmp_name = $_FILES['file1']['tmp_name'];

$loc = 'img/';

$ext = substr($name,strpos($name,'.')+1);

if($_FILES['file1']['size']>= '10000' || $_FILES['file1']['size']<="23000000")
{
//echo $size;
}
else{
// echo "size is not supported";
}
$val = $_FILES['file1']['size'];

if($ext == 'jpg' || $ext == 'png')
{
//echo $lang;
//print_r($_POST);
//exit;
$val =("update register set uname='$uname',pwd='$pwd',emailid='$emailid',gen='$gen',lang='$line',mobile='$mobile',10marks='$marks_10',12marks='$marks_12' file1='$name' where id=$sid");
//print_r($qry);

$res=mysqli_query($this->con(),$val);
//print_r($run);
if($res)
{
move_uploaded_file($tmp_name,$loc.$name);
//echo "data saved";
//echo "Data inserted";

}
else
{
//echo "Data Not Inserted";

}

}
}
}


//print_r($val);

// return $res;
}
?>

最佳答案

您的 html 已损坏:

</tr>
<?php

echo "<table>"; <--shouldn't this be </table>?
echo "</form>";
}

关于php - 我也尝试使用图像更新来更新我的数据,但是图像 isset 在 php 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39622541/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com