-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdatecontent.php
More file actions
66 lines (60 loc) · 1.97 KB
/
updatecontent.php
File metadata and controls
66 lines (60 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<script src='https://unpkg.com/tesseract.js@v2.0.2/dist/tesseract.min.js'></script>
<?php
if (!empty($_GET["getid"])) {
$getid=$_GET['getid'];
$image=$_GET['source'];
?>
<form name="contentupdate" id="contentupdate" method="post" action="updatecontent.php?updated=1">
<input name="id" value="<?php echo $getid;?>" hidden>
<br><input type="text" name="content" id="getimage" value="">
<button type="submit" name="dataupdate"> Submit</button>
</form>
<script>
Tesseract.recognize(
'<?php echo $image;?>',
'eng',
{ logger: m => console.log(m) }
).then(({ data: { text } }) => {
console.log(text);
var x = text;
document.getElementById('getimage').value = x;
var input = document.getElementById('getimage');
if (input && input.value) {
document.getElementById('contentupdate').submit();
}
})
</script>
<?php }
if (!empty($_GET["updated"])) {
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$dbname = 'mathtipun';
$conn = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$id=$_POST['id'];
$content=$_POST['content'];
$content=str_replace(' ', '-', $content);
$content=preg_replace('/[^A-Za-z0-9\-]/', ' ', $content);
$content=preg_replace('/-+/', '-', $content);
$content=str_replace('-', ' ', $content);
$sql = "UPDATE content SET content='".$content."' WHERE id='".$id."'";
if ($conn->query($sql) === TRUE) {
echo "Record updated successfully";
} else {
echo "Error updating record: " . $conn->error;
}
$idplus=$id+1;
$sql = "SELECT * FROM content WHERE id='".$idplus."'";
$retval = $conn->query($sql);
If (mysqli_num_rows($retval) == 1){
$row = mysqli_fetch_array($retval, MYSQLI_ASSOC);
$source= $row['wheretopic'].$row['image'];
echo "<script>window.open('updatecontent.php?getid=".$idplus."&source=".$source."', '_blank');</script>";
echo "<script>window.close();</script>";
}
$conn->close();
}
?>