Hai... I am new on PHP & Mysql,,,
please help me, I'm trying to follow this tutorial using xampp, and I get errors like this;
Warning: mysqli_real_escape_string () expects exactly 2 parameters, 1 given in C: \ xampp \ htdocs \ go \ edit.php on line 62
Deprecated: mysql_real_escape_string (): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in C: \ xampp \ htdocs \ go \ edit.php on line 63
and code
<?php
/*
EDIT.PHP
Allows user to edit specific entry in database
*/
// creates the edit record form
// since this form is used multiple times in this file, I have made it a function that is easily reusable
function renderForm($id, $date, $website1, $linkwebsite1, $website2, $linkwebsite2, $error)
{
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Edit Record</title>
</head>
<body>
<?php
// if there are any errors, display them
if ($error != '')
{
echo '<div style="padding:4px; border:1px solid red; color:red;">'.$error.'</div>';
}
?>
<form action="" method="post">
<input type="hidden" name="id" value="<?php echo $id; ?>"/>
<div>
<p><strong>ID:</strong> <?php echo $id; ?></p>
<strong>Date *: </strong> <input type="text" name="date" value="<?php echo $date; ?>"/><br/>
<strong>website 1 *: </strong> <input type="text" name="website1" value="<?php echo $website1; ?>"/><br/>
<strong>Link to website 1 *: </strong> <input type="text" name="linkwebsite1" value="<?php echo $linkwebsite1; ?>"/><br/>
<strong>website 2 *: </strong> <input type="text" name="website2" value="<?php echo $website2; ?>"/><br/>
<strong>Link to website 2 *: </strong> <input type="text" name="linkwebsite2" value="<?php echo $linkwebsite2; ?>"/><br/>
<p>* Required</p>
<input type="submit" name="submit" value="Submit">
</div>
</form>
</body>
</html>
<?php
}
// connect to the database
$con=mysqli_connect("localhost","root","","buat");
// Connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// check if the form has been submitted. If it has, process the form and save it to the database
if (isset($_POST['submit']))
{
// confirm that the 'id' value is a valid integer before getting the form data
if (is_numeric($_POST['id']))
{
// get form data, making sure it is valid
$id = $_POST['id'];
$date = mysqli_real_escape_string(htmlspecialchars($_POST['date']));
$website1 = mysql_real_escape_string(htmlspecialchars($_POST['website1']));
$linkwebsite1 = mysql_real_escape_string(htmlspecialchars($_POST['linkwebsite1']));
$website2 = mysql_real_escape_string(htmlspecialchars($_POST['website2']));
$linkwebsite2 = mysql_real_escape_string(htmlspecialchars($_POST['linkwebsite2']));
// check that firstname/lastname fields are both filled in
if ($date == '' || $website1 == '' || $linkwebsite1 == '' || $website2 == '' || $linkwebsite2 == '')
{
// generate error message
$error = 'ERROR: Please fill in all required fields!';
//error, display form
renderForm($id, $date, $website1, $linkwebsite1, $website2, $linkwebsite2, $error);
}
else
{
// save the data to the database
mysqli_query($con,"UPDATE proof SET date='$date', website1='$website1', linkwebsite1='$linkwebsite1', website2='$website2', linkwebsite2='$linkwebsite2' WHERE id='$id'")
or die(mysqli_connect_error());
// once saved, redirect back to the view page
header("Location: edit.php");
}
}
else
{
// if the 'id' isn't valid, display an error
echo 'Error!';
}
}
else
// if the form hasn't been submitted, get the data from the db and display the form
{
// get the 'id' value from the URL (if it exists), making sure that it is valid (checing that it is numeric/larger than 0)
if (isset($_GET['id']) && is_numeric($_GET['id']) && $_GET['id'] > 0)
{
// query db
$id = $_GET['id'];
$result = mysqli_query($con,"SELECT * FROM site WHERE id=$id")
or die(mysql_error());
$row = mysqli_fetch_array($result);
// check that the 'id' matches up with a row in the databse
if($row)
{
// get data from db
$date = $row['date'];
$website1 = $row['website1'];
$linkwebsite1 = $row['linkwebsite1'];
$website2 = $row['website2'];
$linkwebsite2 = $row['linkwebsite2'];
// show form
renderForm($id, $date, $website1, $linkwebsite1, $website2, $linkwebsite2, '');
}
else
// if no match, display result
{
echo "No results!";
}
}
else
// if the 'id' in the URL isn't valid, or if there is no 'id' value, display an error
{
echo 'Error!';
}
}
?>
and how to remove Required form and view-paginated.php ?