What potential pitfalls should be avoided when writing a newsscript in PHP?

One potential pitfall to avoid when writing a newsscript in PHP is not properly sanitizing user input, which can leave your script vulnerable to SQL injection attacks. To prevent this, always use prepared statements when interacting with a database to ensure that user input is properly escaped.

// Example of using prepared statements to prevent SQL injection
$stmt = $pdo->prepare('SELECT * FROM news WHERE id = :id');
$stmt->bindParam(':id', $id, PDO::PARAM_INT);
$stmt->execute();
```

Another pitfall to avoid is not validating input data, which can lead to unexpected behavior or security vulnerabilities. Always validate and sanitize user input to ensure that it meets the expected format and is safe to use in your script.

```php
// Example of validating input data
$title = filter_var($_POST['title'], FILTER_SANITIZE_STRING);
$author = filter_var($_POST['author'], FILTER_SANITIZE_STRING);
$content = filter_var($_POST['content'], FILTER_SANITIZE_STRING);
```

Lastly, avoid hardcoding sensitive information such as database credentials directly in your script. Instead, store these details in a separate configuration file outside of the web root and include it in your script securely.

```php
// Example of storing database credentials in a separate configuration file
$config = include('config.php');
$pdo = new PDO("mysql:host={$config['host']};dbname={$config['dbname']}", $config['username'], $config['password']);