Reputation: 47
I'm having a hard time on how to update/edit my code.
PHP:
<?php
require("config.php");
$link =mysqli_connect($h,$u,$p,$db)OR die(mysql_error());
if ( isset($_POST['newhotel']));
{
$newhotel = $_POST['newhotel'];
//$BIL = $_POST['BIL'];
$query = "UPDATE hotels set hotel='$_POST[newhotel]' where hotel='$hotel'";
$result = mysqli_query($link,$query);
header( "refresh:0; url=view.php" );
}
?>
HTML:
<form action="edit.php" method="post">
New Hotel: <br />
<input type="text" name="newhotel"/><BR />
Address: <br />
<textarea name="address" cols="50" rows="10"></textarea><BR />
<input require name="" type="submit" value="Update "/><input name="" type="reset" value="Clear" />
<p></p>
</form>
I know that my code is wrong. Can someone provide me a hint so that i can rectify my problem. thank you
Upvotes: 1
Views: 105
Reputation: 1285
This is your HTML form:
<form action="edit.php" method="post">
New Hotel: <br />
<input type="text" name="newhotel"/><BR />
Address: <br />
<textarea name="address" cols="50" rows="10"></textarea><BR />
<input name="sub" type="submit" value="Update "/>
<input name="" type="reset" value="Clear" />
<p></p>
</form>
Here method is post. When the user fills in this form and hits the submit button, the action.php page is called.so you code will be
edit.php
<?php
if(isset($_POST['sub']))
{
echo '<pre>';
print_r($_POST);
}
output would be like
Array
(
[newhotel] => asasa
[address] => sasa
[sub] => Submit
)
here you have only post values and there is no field for edit so below code is wrong.from where you get this $_GET values
if( isset ( $_GET['edit']))
{
$BIL = $_GET['edit'];
$query = "SELECT * from hotels where hotel='$hotel'";
$row = mysqli_fetch_array($query);
}
Upvotes: 1