Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8882093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:29:28+00:00 2026-06-14T20:29:28+00:00

I have decided for security to convert my simple php with mysql code to

  • 0

I have decided for security to convert my simple php with mysql code to PDO,since it will tighten my security.My old code:

$host = "localhost"; 
$user = "username"; 
$pass = "pass"; 
$database = "mydatabase"; 

$linkID = mysql_connect($host, $user, $pass) or die("Could not connect to host."); 
mysql_select_db($database, $linkID) or die("Could not find database."); 
$name=$_POST['name'];
$message=$_POST['message'];
$ip = $_SERVER['REMOTE_ADDR'];
$query="INSERT INTO table (date_time, name, message,ip) VALUES     (NOW(),'$name','$message','$ip')";
If (mysql_query($query,$linkID)){
    //Success
    }else{
    //Failure
    }

My new code is:

$hostname = 'localhost';
$username = 'username';
$password = 'pass';
$dbname = 'mydatabase';

$dbh = new PDO("mysql:host=$hostname;dbname=$dbname", $username, $password);
if($_POST['name'] && $_POST['message']) {
    $name = $_POST['name'];
    $message = $_POST['message'];
    $ip = $_SERVER['REMOTE_ADDR']; 
    $sql = "INSERT INTO table (date_time, name, message,ip)VALUES (NOW(), :name, :message,'$ip')";
    $stmt = $dbh->prepare($sql);
    $stmt->bindParam(':name', $name, PDO::PARAM_STR);
    $stmt->bindParam(':message', $message, PDO::PARAM_STR);
    if ($stmt->execute()) {
      echo "OK";
    }
}

It’s very strange that when i point my browser to index.php?name=someName&message=someMessage my PDO code won’t echo a single thing(even echo "ok" ) or an error so i can fugure out where is the problem.

I can confirm that no data is inserted to the database.

I’ve even added try catch but nothing changed. My php is supporting PDO and the simple Mysql code is working.
Any ideas? Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T20:29:30+00:00Added an answer on June 14, 2026 at 8:29 pm

    In your case,

    if($_POST['name'] && $_POST['message']) {
    

    Should be:

    if($_GET['name'] && $_GET['message']) {
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have decided to start using unit testing in PL/SQL, since it could be
I have decided to start coding using OOP and a PHP framework. I have
I have recently decided to switch all my current plain mysql queries performed with
I wrote not so simple app, and decided to make applet. I have the
I have taken the decrypt code from http://msdn.microsoft.com/en-us/library/system.security.cryptography.cryptostream.aspx and modified it as follows below.
I've never used PDO before, but decided finally that security is the primary concern
I'm researching a security model for our web portal, we have decided to use
I have decided to add some validation to my combobox, what I'm trying to
I have decided to develop a (Unicode) spell checker for my final year project
We have decided to work with the Insert Framework Here We'll most likely update

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.