-1

A link to my previous thread

This is my PHP code

<?php
$dbh = new PDO("mysql:host=$host;dbame=$dbname",$user,$pass);
$UserN = mysqli_real_escape_string($con, $_POST['UserN']);
$FullN = mysqli_real_escape_string($con, $_POST['FullN']);
$Adrs = mysqli_real_escape_string($con, $_POST['Adrs']);
$Email = mysqli_real_escape_string($con, $_POST['Email']);
$PhoneN = mysqli_real_escape_string($con, $_POST['PhoneN']);
$stmt = $dbh->prepare("INSERT INTO UserIn (UserN, FullN, Adrs, Email, 
PhoneN) VALUES ('$UserN','$FullN','$Adrs','$Email','$PhoneN')"); //Insert 
query $stmt->execute($UserN, $FullN, $Adrs, $Email, $PhoneN);



?>

And this is my form code

 <div class="form-con">
         <form action="insert.php" method="POST">
             <label>Username</label><br>
             <input type="text" name="UserN" placeholder="Your Username" ><br>
             <label>Full Name</label><br>
             <input type="text" name="FullN" placeholder="Full Name"><br>
             <label>Full Address</label><br>
             <textarea type="text" rows="4" cols="50" name="Adrs" placeholder="Address"></textarea><br> 
                  <label>Email Address</label><br>
                  <input type="text" name="Email" placeholder="Email Address"><br>
                  <label>Phone Number</label><br>
                  <input type="text" name="PhoneN" placeholder="Phone Number"><br>
                   <div class="btn">
                     <a href="#"><button type="submit">Submit</button></a>
                   </div>
         </form>
      </div>

Upon clicking on the submit button I am provided with a and it provides me with This page isn’t working

xxxxxxxx.com is currently unable to handle this request. HTTP ERROR 500

RebornXD
  • 7
  • 5
  • 1
    It means you have error on page so put this two line in top of page to on the debug mode `ini_set("display_errors", "On"); error_reporting(E_ALL);` – JYoThI Sep 15 '17 at 04:13
  • in the php files correct? I put it right after the first line and it still made no difference. – RebornXD Sep 15 '17 at 04:24
  • First of all your form page is loading or not ? – JYoThI Sep 15 '17 at 04:26
  • yes it is loading correctly do you think it would be wise to post a link to my site? – RebornXD Sep 15 '17 at 04:27
  • Remove everything in `insert.php` page just put this line `` - For testing purpose – JYoThI Sep 15 '17 at 04:40
  • it echoes back page working upon click on submit button – RebornXD Sep 15 '17 at 04:55
  • So problem is with your php code try to debug it . Your mixing mysqli with pdo . take some good tutorial and then code it . did you noticed that there is no `$con` variable at all in your code . – JYoThI Sep 15 '17 at 05:14
  • Why are you attempting to use both PDO and `mysqli_real_escape_string`? Where is `$con` coming from? Why aren't you binding parameters to your SQL statement? Why are you passing multiple arguments to `execute()`? – Phil Sep 15 '17 at 05:21

1 Answers1

0

Firstly try to rename your ".htaccess" to".htaccess-test" and then try to submit, OR use CHMOD 644 for the file and CHMOD 755 on folder(directories), if it continue, try this:

mysqli_real_escape_string doesn't work perfectly with Pdo and when you are using "pdo prepare execute ou Query prepare", mysqli_real_escape_string is not important!!!

USE THIS CODE:

<?php
$dbh = new PDO("mysql:host=$host;dbame=$dbname",$user,$pass);
extract($_POST);
$UserN =strip_tags($_POST['UserN']);
$FullN = strip_tags($_POST['FullN']);
$Adrs = strip_tags($_POST['Adrs']);
$Email = strip_tags($_POST['Email']);
$PhoneN = strip_tags($_POST['PhoneN']);
$stmt = $dbh->prepare('INSERT INTO UserIn (UserN, FullN, Adrs, Email, PhoneN) VALUES(:UserN, :FullN, :Adrs, :Email, :PhoneN)');
$stmt->execute(array(
             'UserN' => $UserN,
             'FullN' => $FullN,
             'Adrs' => $Adrs,
             'Email' => $Email,
             'PhoneN' => $PhoneN,  
));

?>
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Sylarman5
  • 110
  • 1
  • 6
  • so this is how I would implement the second line correctly right $dbh = new PDO("mysql:host=$locahost;dbame=$idxxxx84_foxxxn",$idxxxx84_fxxxml,$xxxxx); – RebornXD Sep 15 '17 at 06:05