GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 18-Nov-2006, 19:51
Richardknox Richardknox is offline
Junior Member
 
Join Date: Nov 2006
Location: Michigan
Posts: 83
Richardknox is on a distinguished road

Parse error: parse error, unexpected T_STRING in /home/content/R/i/c/RichardAKnox/htm


Hello,

I am slowly learning to use PHP for the website that I am putting together. So, please understand that I am a newbee to PHP, and MySql.


I am also creating this script from other bits and pieces from other scripts, so that might be part of my problem.

What I am attempting to accomplish here, is to update a variable by adding one to it, and then sending it back to the database to be updated there, before going to the website that the user selected.


This is the error that I am getting...

Parse error: parse error, unexpected T_STRING in /home/content/R/i/c/RichardAKnox/html/ace.php on line 43


This is my script:

PHP Code:

<?php
//Connect To Database
$hostname="mysql247.secureserver.net";
$username="RichardAKnox";
$password="password";
$dbname="maindatabase";
$usertable="wcdatabase";

$dblink = mysql_connect($hostname,$username, $password) OR DIE ("Unable to connect to database! Please try again later.");

mysql_select_db($dbname, $dblink);


$id=$_GET['id'];

$query = "SELECT * FROM wcdatabase WHERE id = ($id) LIMIT 0, 30 ";


$result = mysql_query($query,$dblink);

$row = mysql_fetch_assoc($result);

$viewed = $row["viewed"];
                         
$row["viewed"]++;
    
$viewed = $row["viewed"];


Line 43 error ---->>>  $query = UPDATE wcdatabase SET viewed = $viewed;




// Redirect to the link URL

Header("Location: $link");
exit();

?>


I used to have a few echo statements in this script to verify that certain aspects of the script worked. But, as soon as I added the Line 43 portion, then the script stopped working, and gave me the errors listed.


Thanks for any help,

Richard
Last edited by LuciWiz : 19-Nov-2006 at 08:46. Reason: Please insert your Php code between [php] & [/php] tags
  #2  
Old 18-Nov-2006, 19:54
TurboPT's Avatar
TurboPT TurboPT is offline
Regular Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 926
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: Parse error: parse error, unexpected T_STRING in /home/content/R/i/c/RichardAKnox/htm


Missing the quotes for the string. Change that line to look like this:
PHP Code:

$query = "UPDATE wcdatabase SET viewed = $viewed"; 


__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
  #3  
Old 18-Nov-2006, 20:28
Richardknox Richardknox is offline
Junior Member
 
Join Date: Nov 2006
Location: Michigan
Posts: 83
Richardknox is on a distinguished road

Re: Parse error: parse error, unexpected T_STRING in /home/content/R/i/c/RichardAKnox


Great, that corrected the error. But now that I finished the rest of the coding. I am seeing that it is not updating the database.

I am trying to update a record by locating it in the database with a unique 'ID' number, and placing the update into the 'viewed' location.

--> viewed <--- is the name of the field in the database that I am wanting to update.

Here is the code again.

PHP Code:

<?php
//Connect To Database
$hostname="mysql247.secureserver.net";
$username="RichardAKnox";
$password="password";
$dbname="database";
$usertable="wcdatabase";

$dblink = mysql_connect($hostname,$username, $password) OR DIE ("Unable to connect to database! Please try again later.");

mysql_select_db($dbname, $dblink);

$id=$_GET['id'];

$query = "SELECT * FROM wcdatabase WHERE id = ($id) LIMIT 0, 30 ";


$result = mysql_query($query,$dblink);

$row = mysql_fetch_assoc($result);

$row["viewed"]++;
                
$query = "UPDATE wcdatabase SET viewed = $viewed where id = $id";



// Redirect to the link URL

Header("Location: $link");
exit();

?>

Last edited by LuciWiz : 19-Nov-2006 at 08:46. Reason: Please insert your Php code between [php] & [/php] tags
  #4  
Old 18-Nov-2006, 20:42
TurboPT's Avatar
TurboPT TurboPT is offline
Regular Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 926
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: Parse error: parse error, unexpected T_STRING in /home/content/R/i/c/RichardAKnox/htm


Where is $viewed set? Does $id have a value?

Try placing an echo after each one to see if you get a value, for example:
PHP Code:

echo "ID is: " . $id 


__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
  #5  
Old 18-Nov-2006, 21:02
Richardknox Richardknox is offline
Junior Member
 
Join Date: Nov 2006
Location: Michigan
Posts: 83
Richardknox is on a distinguished road

Re: Parse error: parse error, unexpected T_STRING in /home/content/R/i/c/RichardAKnox


http://www.thisismywebsite.net/ace.php?id=1

ID is set from above, when through the link.

viewed is the field from inside the database, and I want to increment it by one.

I have been placing echo within the script, I just have been removing them to prevent confusion. Here is the complete script.

PHP Code:

<?php
//Connect To Database
$hostname="mysql247.secureserver.net";
$username="RichardAKnox";
$password="password";
$dbname="database";
$usertable="wcdatabase";

$dblink = mysql_connect($hostname,$username, $password) OR DIE ("Unable to connect to database! Please try again later.");
mysql_select_db($dbname, $dblink);


$id=$_GET['id'];

$query = "SELECT * FROM wcdatabase WHERE id = ($id) LIMIT 0, 30 ";

$result = mysql_query($query,$dblink);

$row = mysql_fetch_assoc($result);

$viewed = $row["viewed"];
       echo "First Viewed: ".$viewed;
       echo "Name: ".$row["camname"];
       echo "ID#:  ".$id;
       echo "Link: ".$row["link"];
       echo "Viewed: ".$row["viewed"];
                 
        $row["viewed"]++;
                
       echo "Viewed: ".$row["viewed"];
    

    
 $viewed = $row["viewed"];

       echo "Second Viewed: ".$viewed;


    
$query = "UPDATE wcdatabase PUT viewed = ($viewed) where id = ($id)";

$result = mysql_query($query, $dblink); 

echo "Viewed: ".$viewed;

echo "ID:    ".$id;


// Redirect to the link URL

Header("Location: link");
exit();

?>


I had placed echo in a couple of areas to see that I am retrieving data, and updating the viewed count. But, I am uncertain why I am not updating the count in the database.

Richard

PS:

Here is the output. I know that its not formated and pretty. I was just looking to see that it was updating.

First Viewed: 0Name: Soo Locks Cam 1ID#: 1Link: https://webcam.crrel.usace.army.mil/soo/Viewed: 0Viewed: 1Second Viewed: 1Viewed: 1ID: 1
Last edited by LuciWiz : 19-Nov-2006 at 08:47. Reason: Please insert your Php code between [php] & [/php] tags
  #6  
Old 18-Nov-2006, 21:20
Richardknox Richardknox is offline
Junior Member
 
Join Date: Nov 2006
Location: Michigan
Posts: 83
Richardknox is on a distinguished road

Re: Parse error: parse error, unexpected T_STRING in /home/content/R/i/c/RichardAKnox/htm


I figured it out.

I changed this:

$query = "UPDATE wcdatabase SET viewed = $viewed where id = $id";

to this:

$query = "UPDATE wcdatabase SET viewed = ($viewed) where id = ($id)";

And it started to work.

Thanks for the help.

Richard
 
 

Recent GIDBlogFirst week of IA training by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Parse error: parse error, unexpected T_STRING Richardknox PHP Code Library 3 19-May-2007 14:42
Apologies In Advance Parse error: parse error, unexpected T_STRING, expecting T_VARI sph2005 MySQL / PHP Forum 11 17-Jul-2006 09:28
Parse Error vigilantweather MySQL / PHP Forum 3 21-Feb-2006 12:24
Parse Error vigilantweather MySQL / PHP Forum 6 04-Feb-2006 13:15

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 20:28.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.