i have this error and i dont know why. please help...thanks!

Webpage error details


Message: Unterminated string constant
Line: 19
Char: 45
Code: 0
URI: http://localhost/itams/user/checkIfReported.php?a=5

the codes in checkIfReported.php is this

<?php
session_start();

include "../configdb.php";
include "../opendb.php";

$_SESSION['a'] = $_GET['a'];               

$result = mysql_query("SELECT _status
    FROM assets
    WHERE _id='$_SESSION[a]'") or die('Could not Get Id: '.mysql_error());
    $row=mysql_fetch_array($result);
    $status=$row['_status'];
    
    switch($status)
    {
        case 'Under Maintenance' :
                                    echo "<script type='text/javascript'>location.href='userReport_Reported.php';</script>";
                                    break;
        case 'In Use':
                        echo "<script type='text/javascript'>location.href='userReport_Create_Ticket.php;</script>"; 
                        break;
        default: break;
    }

include "../opendb.php";
?>

the first case works, it redirects to the right page. but the second case gives that error.

Dani AI

Generated

Good catch by — the browser error is a JavaScript parse error caused by an unclosed string in the generated <script> tag. The browser reports the line/char where the JS stops parsing, so even though the PHP ran fine, the client-side script was malformed. That explains why the first branch worked and the second produced "Unterminated string constant."

For a more robust solution use a server-side redirect instead of printing client-side JS. Do this before any output (includes can send output), and follow with exit:

header('Location: /user/userReport_Create_Ticket.php');
exit;

If you must emit JavaScript, build the URL safely so you never accidentally break quoting. One safe pattern is to let PHP produce a JSON string for JS:

$url = '/user/userReport_Create_Ticket.php';
echo '<script>location.href=' . json_encode($url) . ';</script>';

Also check two common pitfalls in the posted code: do not trust raw GET values in SQL, and avoid accidentally including the same DB file twice. At minimum cast the input to an integer before using it in a query:

$id = (int) $_GET['a'];
// use $id in query instead of raw $_GET

Long-term, move to prepared statements (mysqli or PDO) to prevent SQL injection, and use include_once for shared files to avoid double includes. To debug similar issues: view page source or copy the printed <script> into the browser console — the unterminated string will be obvious and the console will point to the exact character.

Recommended Answers

All 2 Replies

i got it :)

you forgot the closing single quote

echo "<script type='text/javascript'>location.href='userReport_Create_Ticket.php;</script>";

to

echo "<script type='text/javascript'>location.href='userReport_Create_Ticket.php';</script>";
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.