0

im a beginner and a diploma student... i dont have a clue what is the error... please help me solve the error...

<?php 
$servername="localhost";
$username="root";
$password="";
$dbname="slr";

$conn = new mysqli($servername, $username, $password, $dbname);

if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

$sql = "INSERT INTO software (soft_id, soft_name, installed_date, expiry_date, product_key) 
VALUES ('2', 'Dhurga', '2016-01-01', '2016-04-30', 'stevenreega@gmail.com')";

if (mysqli_query($conn, $sql)) {
    echo "New record created successfully";
} else {
    echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}


<input type="button"value="Finish"onclick="history.go(-2);return true;">
</table>
mysqli_close($conn);
?>
Steven Surain
  • 51
  • 3
  • 3
  • 5

3 Answers3

0

You can't use HTML statement directly inside PHP tag. You have to use echo.

Write your two HTML statement as follow

 echo '<input type="button"value="Finish"onclick="history.go(-2);return true;">';
 echo '</table>';

You can check how to write HTML inside PHP Here

Community
  • 1
  • 1
Divyesh Savaliya
  • 2,692
  • 2
  • 18
  • 37
0

Use below code:

<?php 
ini_set('display_errors', 1);
$servername="localhost";
$username="root";
$password="";
$dbname="slr";

$conn = new mysqli($servername, $username, $password, $dbname);

if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

$sql = "INSERT INTO software (soft_id, soft_name, installed_date, expiry_date, product_key) 
VALUES ('2', 'Dhurga', '2016-01-01', '2016-04-30', 'stevenreega@gmail.com')";

if (mysqli_query($conn, $sql)) {
    echo "New record created successfully";
} else {
    echo "Error: " . $sql . "<br>" . mysqli_error($conn);
} ?>

<!-- you can not use html inside php tag-->
<input type="button"value="Finish"onclick="history.go(-2);return true;">
</table>
<?php
mysqli_close($conn);
?>
Prashant Valanda
  • 480
  • 8
  • 19
0

You cannot use HTML code in PHP, thus there's 2 methods. PHP is not able to parse the HTML code, resulting in a syntax error.


First method: Close the PHP with ?>, and reopen the tag <?php after the HTML.

if (mysqli_query($conn, $sql)) {
    echo "New record created successfully";
} else {
    echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}

?>

<input type="button"value="Finish"onclick="history.go(-2);return true;">
</table>

<?php
mysqli_close($conn);
?>

Second method: Echo the HTML using PHP echo().

echo '<input type="button"value="Finish"onclick="history.go(-2);return true;"';
echo '</table>';
Panda
  • 6,955
  • 6
  • 40
  • 55