Hier is de code die je moet gebruiken:
<?php
include("/connections/db_conx.php");
if(isset($_POST['submit'])) {
$title = mysqli_real_escape_string($db_conx, $_POST['title']);
$text = mysqli_real_escape_string($db_conx, $_POST['text']);
$picture = mysqli_real_escape_string($db_conx, $_POST['picture']);
$sql = "INSERT INTO news (`title`, `text`, `picture`) VALUES('$title','$text','$picture');";
if(!$result = $db_conx->query($sql)){
die('There was an error running the query [' . $db_conx->error . ']');
}
echo 'Entered into the news table';
}
?>
<html>
<head>
</head>
<body>
<form method="post" action="index.php" id="tech">
<table border="0">
<tr>
<td>Title</td>
<td> <input type="text" name="title"></td>
</tr>
<tr>
<td>Text</td>
<td><textarea rows="4" name="text" cols="50" name="comment" form="tech"> </textarea></td>
</tr>
<tr>
<td>Picture</td>
<td> <input type="varchar" name="picture"></td>
</tr>
<tr>
<td><input id="button" type="submit" name="submit" value="Submit"></td>
</tr>
</table>
</form>
</body>
</html>
Uw probleem is dat de mysqli_real_escape_string()
functie vereist 2 parameters:de databaseverbinding en de tekenreeks om te ontsnappen.
Ik heb ook volledig opnieuw geformatteerde code toegevoegd en ook foutcontrole.