I have a simple form and I run my script without any errors. I click my btn and I would like to see my echo errors but no errors show up when I have no value in textboxes. I have tried if(isset($_Post["submit"])) and if($_SERVER["REQUEST_METHOD"] == "post") What I think is nether of there ifs are becoming valid on my btn click.
<?php
$nameerror = $twoerror = $errormsg = "";
$servername = "localhost";
$username = "root";
$password = "password";
$dbname = "test";
$connection = new mysqli($servername, $username, $password, $dbname);
if($_SERVER["REQUEST_METHOD"] == "post")
{
if(empty(trim($_Post["name"]))) {
$nameerror = "Name is required";
}
else {
$namesafe = mysqli_real_escape_string($connection, $_Post["name"]);
}
if(empty(trim($_Post["two"]))) {
$twoerror = "Two is required";
}
else {
$twosafe = mysqli_real_escape_string($connection, $_Post["two"]);
}
if($namesafe != "" && $twosafe != "") {
$sqlInsert = "INSERT INTO tester(name, two) " .
"VALUES('". $namesafe ."','". $twosafe ."')";
if(mysqli_query($connection, $sqlInsert)) {
echo "Successfully entered.";
} else {
echo "NOT successful error: " . $sqlInsert . "<br>" . mysqli_error($connection);
}
}
}
mysqli_close($connection);
?>
<?php
if(!$connection) {
die("Connection Failed! " . mysqli_connect_error());
}
echo "Connected Successfully@!";
?>
<section class="text-align" id="section-content">
<div id="alertMessages" class="container rounded"></div>
<div id="contentdiv" class="container rounded">
<form id="formtest" class="rounded" method="post" >
<!--
<h3>PHP Create</h3>
<?php
if(isset($errormsg)) {
echo $errormsg;
}
?>
<div>
<div class="form-group">
<input type="text" class="form-control" id="txtName" name="name" />
<label for="txtName">Name </label>
<?php if(isset($nameerror)) { echo '<span class="error">' . $nameerror . '</span>'; } ?>
<!--
<!--
</div>
<div>
<input type="text" class="form-control" id="txttwo" name="two" />
<label for="txttwo">Text Two </label>
<?php if(isset($twoerror)) { echo '<span class="error">' . $twoerror . '</span>'; } ?>
</div>
</div>
<button type="submit" class="btn btn-lg btn-primary btn-block" name="submit">Click</button>
</form>
</div>
</section>
What I have tried:
I have been trying with internal php files and external php I just want to ...
This is basically my whole file without the bootstrap CDNs
I can run my page and I get no errors I tried to setup php-debug and xdebug on atom and chrome I cant count how many tutorials I have used and tried but for some reason my breakpoints will not turn green on atom. and stop to the IDE when i run the page.
I would refresh the page and in the network tab I would see my .php file and if i had somekind of error like at first it says no function mysql_connect so i realized i needed to use mysqli_connect
I use xampp with myphpadmin to connect to mysql.
I just want to do these simple check if row exists in db and create in db then ill do a login and crud and shopping cart etc.. but i been having troubles just setting up the debugger if i had that i know everything would be easier so i can see exactly whats going on