I am trying to set up a json object.array to retrieve the data from this mysql query. the data required is posted from java and that seems to work fine, but I get parsing errors. I tried testing the php file and I get the "Parse error: syntax error, unexpected T_VARIABLE in C:\wamp\www\GetVerse.php on line 8" . previously I had a ';' at the end of the sql query and it said unexpected ';' at the end of line 7. now it i get the error message for line 8: $row = mysql_fetch_array($result); . What seems to be the problem?

<?php
mysql_connect("localhost","root","password");
mysql_select_db("hftwmvirtualdb");
$Booknum = mysql_real_escape_string($_POST['Booknum']); 
$Chapternum = mysql_real_escape_string($_POST['Chapternum']); 
$Versenum = mysql_real_escape_string($_POST['Versenum']); 
$result = mysql_query("SELECT VERSETEXT FROM booktable WHERE BIBLEID = '".$Booknum."' AND CHAPTERID = '".$Chapternum."' AND VERSENO = '".$Versenum."' LIMIT 0,1"
$row = mysql_fetch_array($result);
echo json_encode($row); 
mysql_close();  
?>

You missed a semi-colon at the end of line 7.

Is it possible to check whether the php script is correct without the running of the java code to post the required data?

You're missing a closing bracket too. );

ahh, can't believe i missed that. I will check if it runs now.

Is it possible to check whether the php script is correct

If you use a smart IDE, then you can prevent such typos easily. See this thread.

I corrected that error & After checking the script through a browswer I'm now receiving the following warning messages:


    1. Notice: Undefined index: Booknum in C:\wamp\www\GetVerse.php on line 4

    1. Notice: Undefined index: Chapternum in C:\wamp\www\GetVerse.php on line 5

    1. Notice: Undefined index: Versenum in C:\wamp\www\GetVerse.php on line 6

    1. Notice: Undefined variable: sql in C:\wamp\www\GetVerse.php on line 8

    1. Warning: mysql_fetch_assoc() expects parameter 1 to be resource, null given in C:\wamp\www\GetVerse.php on line 8

    1. Notice: Undefined variable: output in C:\wamp\www\GetVerse.php on line 9

I assume, 1-3 are because I did not submit the post data but does is the same reason for messages 4-6?

1 - 3, you're correct.

5, will be because your query's incorrect due to the missing $_POST parameter values.

4 and 6 do not seem to appear to correspond with the code you have posted, so it's not possible to tell. I cannot see variables called $sql or $output.

I have corrected a table name in the sql and updated the PHP code. I have previously created a similar php script that gets all data in a table & encodes in Json; with line 8-11 the same. Why is is causing so trivial when i'm trying to mysql query to select a cell. The new PHP Code as stated:

<?php
mysql_connect("localhost","root","password");
mysql_select_db("hftwmvirtualdb");
$Booknum = mysql_real_escape_string($_POST['Booknum']); 
$Chapternum = mysql_real_escape_string($_POST['Chapternum']); 
$Versenum = mysql_real_escape_string($_POST['Versenum']); 
$sql = mysql_query("SELECT 'VERSETEXT' FROM 'booktable' WHERE 'BOOKID' = $Booknum AND 'CHAPTERID' = $Chapternum AND 'VERSENO' = $Versenum");
while($row=mysql_fetch_assoc($sql)) $output[]=$row;
  print(json_encode($output));
  mysql_close();
?>

I thought output was defined in line 8: "while($row=mysql_fetch_assoc($sql)) $output[]=$row;" so that it can be encoded by Json array/object. If this code is incorrect, How do I get the result of the query for parsing?

ok so after adding echo mysql_error(); before the while statement. I recieved:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''booktable' WHERE 'BOOKID' = '' AND 'CHAPTERID' = AND 'VERSEID' =' at line 1
Which means the $sql didn't read the post data. I thought that was the correct syntax

$sql = mysql_query("SELECT 'VERSETEXT' FROM 'booktable' WHERE 'BOOKID' = $Booknum AND 'CHAPTERID' = $Chapternum AND 'VERSENO' = $Versenum");

Should be:

$sql = mysql_query("SELECT `VERSETEXT` FROM `booktable` WHERE `BOOKID` = $Booknum AND `CHAPTERID` = $Chapternum AND `VERSENO` = $Versenum");

In short, replace the single quotes with backticks. Use single quotes around values, backticks around tables and columns.

Since the POST is empty, show us your form or ajax call too.

            [02-Aug-2018 04:37:37 Etc/GMT] PHP Parse error:  syntax error, unexpected '$merchant_data' (T_VARIABLE) in /home/turiyavilla/public_html/pay/ccavRequestHandler.php on line 11
[23-Dec-2019 06:19:03 Etc/GMT] PHP Parse error:  syntax error, unexpected '/', expecting end of file in /home/turiyv6z/public_html/pay/ccavRequestHandler.php on line 11
[23-Dec-2019 06:22:05 Etc/GMT] PHP Parse error:  syntax error, unexpected '/', expecting end of file in /home/turiyv6z/public_html/pay/ccavRequestHandler.php on line 11

                <html>
                <head>
                <title> Non-Seamless-kit</title>
                </head>
                <body>
                <center>

                <?php include('Crypto.php')?>
                <?php 
                    error_reporting(0);
                    $merchant_data='';
                    $working_key=' ';//Shared by CCAVENUES
                    $access_code=' ';//Shared by CCAVENUES

                    foreach ($_POST as $key => $value){
                        $merchant_data.=$key.'='.$value.'&';
                    }

                    $encrypted_data=encrypt($merchant_data,$working_key); // Method for encrypting the data.

                ?>
                <form method="post" name="redirect" action="https://secure.ccavenue.com/transaction/transaction.do?command=initiateTransaction"> 
                <?php
                echo "<input type=hidden name=encRequest value=$encrypted_data>";
                echo "<input type=hidden name=access_code value=$access_code>";
                ?>
                </form>
                </center>
                <script language='javascript'>document.redirect.submit();</script>
                </body>
                </html>
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.