PHP secured code no longer working

Hello, so i made a php forum that worked perfectly. However i wanted to make it more secure and now when i to view a topic it doesn’t show the description of the topic any-one . Can someone help ?

view_topic.php

[php]<?php

$tbl_name=“fquestions”; // Table name

try {
$dbh = new PDO(‘mysql:host=localhost;dbname=simpleFourm’,‘root’,‘linux’);
} catch (PDOException $e) {
print "Error!: " . $e->getMessage() . “
”;
die();
}
// get value of id that sent from address bar
$id=$_GET[‘id’];
$sql=“SELECT * FROM $tbl_name WHERE id=’$id’”;

$stmt = $dbh->prepare($sql);
$stmt->execute();

?>

<?php echo $rows['topic']; ?>
<?php echo $rows['detail']; ?>
By : <?php echo $rows['name']; ?> Email : <?php echo $rows['email'];?>
Date/time : <?php echo $rows['datetime']; ?>

<?php $tbl_name2="fanswer"; // Switch to table "forum_answer" $sql2="SELECT * FROM $tbl_name2 WHERE question_id='$id'"; $stmt = $dbh->prepare($sql2); $stmt->execute(); while ($rows = $stmt->fetch()) { ?>
ID : <?php echo $rows['a_id']; ?>
Name : <?php echo $rows['a_name']; ?>
Email : <?php echo $rows['a_email']; ?>
Answer : <?php echo $rows['a_answer']; ?>
Date/Time : <?php echo $rows['a_datetime']; ?>

<?php } $sql3="SELECT view FROM $tbl_name WHERE id='$id'"; $stmt = $dbh->prepare($sql3); $stmt->execute(); $rows = $stmt->fetch(PDO::FETCH_ASSOC); $view=$rows['view']; // if have no counter value set counter = 1 if(empty($view)){ $view=1; $sql4="INSERT INTO $tbl_name(view) VALUES('$view') WHERE id='$id'"; $stmt = $dbh->prepare($sql4); $stmt->execute(); } // count more value $addview=$view+1; $sql5="update $tbl_name set view='$addview' WHERE id='$id'"; $stmt = $dbh->prepare($sql5); $stmt->execute(); $dbh = null ; ?>
Name :
Email :
Answer :
 
[/php]

add_new_topic.php

[php]<?php

$tbl_name=“fquestions”; // Table name

try {
$dbh = new PDO(‘mysql:host=localhost;dbname=simpleFourm’,‘root’,‘linux’);
} catch (PDOException $e) {
print "Error!: " . $e->getMessage() . “
”;
die();
}

// get data that sent from form
$topic=$_POST[‘topic’];
$detail=$_POST[‘detail’];
$name=$_POST[‘name’];
$email=$_POST[‘email’];

$datetime=date(“d/m/y h:i:s”); //create date time

$sql=“INSERT INTO $tbl_name(topic, detail, name, email, datetime)VALUES(’$topic’, ‘$detail’, ‘$name’, ‘$email’, ‘$datetime’)”;

$stmt = $dbh->prepare($sql);
$stmt->execute();

if($stmt){
echo “Successful
”;
echo “View your topic”;
}
else {
echo “ERROR”;
}
die();
?>
[/php]

You are going to have to be more specific. I see several issues including improperly used prepared statements, rendering them useless; using die in a try catch, and undefined variables.

My first guess would be to turn on all error reporting and see what shows.

One thing about programming is that you should be using source control.

If you can post the version that worked, then the current version, that’s not working. It would be helpful in trying to determine what change you made that cause it to stop working properly.

Well, I do 100% agree with both Topcoder and Astonecipher!

But, also, you have two prepare’s and two table displays. Only, in the first one, you did not
“fetch” anything, so the $rows[]'s will be empty…

Sponsor our Newsletter | Privacy Policy | Terms of Service