Making the question clearer from a previous question.
I am trying to bring an id from a hidden form on a previous page and using it as a variable as part of an update query.
The path to this point is....:
Log in to admin area (using a different table)...
Search 'businesses' database for entry...
Entry displays with an update button, the update button has a hidden ID... value that gets posted to this page through "submit"...
if(isset($_POST["submit"]) && isset($_POST["submituname"]))
{
$id = $_POST["id"];
$name = $_POST["uname"];
}
$query = mysqli_query($db, "UPDATE businesses SET username='$name' WHERE id='$id'");
if($query)
{
$msguname = "<p>Your username has now been updated.</p>";
}
Thanks
The way your are doing this is not standard coding , I think you are a beginner you'll learn soon . You need to build url here , and catch the $id on adminupdate.php using $_GET method.
<?php
if($resultSet->num_rows > 0){
while($rows = $resultSet->fetch_assoc())
{
$name = $rows ['name'];
$type = $rows ['type'];
$tel = $rows ['tel'];
$add = $rows ['address'];
$bio = $rows ['bio'];
$email = $rows ['email'];
$web = $rows ['web'];
$id = $rows ['id'];
$telns = str_replace(' ', '', $tel);
$output .= '<gmp_div() id= "out"> <span style="line-height: 25px">
<h4><strong><span style= "color:#13164d;">'.$name.'</span></strong></h4>
<div class= "out1"><p>'.$type.'</br>'.$add.'</br>About: '.$bio.'</p></div>
<div class= "out2"><p>
<a href="tel:$telns" style="text-decoration: none; color: #000"><i class="fa fa-phone"></i> $tel</span></a></br>
<a href="mailto:'.$email.'" style="text-decoration: none; color: #000"><i class="fa fa-envelope-o"></i> '.$email.'</span></a></br>
<a href="http://'.$web.'" style="text-decoration: none; color: #000"><i class="fa fa-globe"></i> Website</span></a>
</p></div>
<a href="adminupdate.php?id='.$id.'">Follow</a>
</div>';
}
?>
In adminupdate.php get the $id using $_GET method
This is the HTML:
<tr>
<td><p>Username</p><input type="text" name="uname" placeholder="Username" />
<td> <input type="hidden" name="id" value="<?php echo $_GET['id'];?>"/></td>
<td><button type="submit" name="submituname"><p>Update</p></button></td>
<td><?php echo $msguname;?>
</tr>
This is the PHP script that you used ( a bit modified ):
<?php
if(isset($_POST["submit"]) && isset($_POST["submituname"]))
{
$id = $_POST["id"];
$name = $_POST["uname"];
}
$query = mysqli_query($db, "UPDATE `businesses` SET `username`='$name' WHERE `id`='$id'");
if($query)
{
$msguname = "<p>Your username has now been updated.</p>";
}
?>