Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 23
  1. #1
    Regular Coder
    Join Date
    May 2005
    Posts
    235
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Parse error: syntax error, unexpected T_VARIABLE ??

    Hi,
    With the help of Nightfire i was able to get a script working that created a new table in my database. I have now been working on a script to update or add values to this table. I thought i was about there but i just got this

    Parse error: syntax error, unexpected $end in C:\sokkit\site\phptestarea\new\add_biog.php on line 42

    Line 42 is

    ?>

    Surley that just closes the script? so i presume in this case there is something missing. An unecpected variable end ?
    Heres the code
    Code:
    <? 
    //this is th script to add new Biogger information to mysql 
    //after you have created the biogger tables
    
    
    $ht =  mysql_real_escape_string($_POST['ht']); 
    $user =  mysql_real_escape_string($_POST['user']); 
    $pw =  mysql_real_escape_string($_POST['pw']); 
    $dbn =  mysql_real_escape_string($_POST['dbn']);
     
    
    if($_POST['submit']) 
    {
       //then connect as user
       //change user and password to your mySQL name and password
       mysql_connect("$ht","$user","$pw"); 
    	
       //select which database you want to edit
       mysql_select_db("test"); 
    
       //convert all the fields into variables:
       $title = $_POST['title'];
       $name = $_POST['name'];
       $age = $_POST['age'];
       $email = $_POST['email'];
       $bio = $_POST['bio'];
       $www = $_POST['www'];
      
       
       //Insert the values into the correct database with the right fields
       //mysql table = biogger
       //table columns = id, title, message, who, date, time
       //post variables = $title, $message, '$who, $date, $time
       $insert_query = "INSERT INTO `biogger`
          ( `title`, `name` , `age`, `email` , `bio`, `www`) VALUES
          ( $title , $name, $age, $email, $bio, $www ) ";
    
       if( mysql_query( $insert_query ) )
          echo( "Values inserted successfully." );
       else
          die( "Error! Could not insert values: " . mysql_error() );
    ?>
    What am i missing out?
    Crowds

  • #2
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    You missed your ending curly brace
    Code:
    <? 
    //this is th script to add new Biogger information to mysql 
    //after you have created the biogger tables
    
    
    $ht =  mysql_real_escape_string($_POST['ht']); 
    $user =  mysql_real_escape_string($_POST['user']); 
    $pw =  mysql_real_escape_string($_POST['pw']); 
    $dbn =  mysql_real_escape_string($_POST['dbn']);
     
    
    if($_POST['submit']) 
    {
       //then connect as user
       //change user and password to your mySQL name and password
       mysql_connect("$ht","$user","$pw"); 
    	
       //select which database you want to edit
       mysql_select_db("test"); 
    
       //convert all the fields into variables:
       $title = $_POST['title'];
       $name = $_POST['name'];
       $age = $_POST['age'];
       $email = $_POST['email'];
       $bio = $_POST['bio'];
       $www = $_POST['www'];
      
       
       //Insert the values into the correct database with the right fields
       //mysql table = biogger
       //table columns = id, title, message, who, date, time
       //post variables = $title, $message, '$who, $date, $time
       $insert_query = "INSERT INTO `biogger`
          ( `title`, `name` , `age`, `email` , `bio`, `www`) VALUES
          ( $title , $name, $age, $email, $bio, $www ) ";
    
       if( mysql_query( $insert_query ) )
          echo( "Values inserted successfully." );
       else
          die( "Error! Could not insert values: " . mysql_error() );
    }
    ?>
    Good luck

  • #3
    Regular Coder
    Join Date
    May 2005
    Posts
    235
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks brando...
    Now i get this
    Error! Could not insert values: Unknown column 'gh' in 'field list'
    I kind of presume that means the 'id' field in my table' but i thought that would br filled in automaticaly as its an autoincrement. If this is the case then what do i need to add to do this ? and would i need to add a hidden foem element to the page that i fill in the details to be added ?
    Cheers
    Crowds

  • #4
    Regular Coder
    Join Date
    May 2005
    Posts
    235
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ahhh hold on
    the 'gh' it refers to is what i inputted into the first element of my form
    <INPUT TYPE='TEXT' NAME='title' VALUE='Enter Nick Name up to 30 charecters' size=60></TD>

    oo er
    Help

  • #5
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    it means you're trying to insert something into a column called 'gh' that doesn't exist in the table.
    Try putting the strings inside the query (title for one...) inside quotes, and if that doesn't work, echo out the query and post it here

  • #6
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    Yep, if they are string datatypes in your db, you have to put them in quotes when you insert:
    Code:
    ( '$title' , ect... )

  • #7
    Regular Coder
    Join Date
    May 2005
    Posts
    235
    Thanks
    0
    Thanked 0 Times in 0 Posts
    well with the strings inside quotes i get
    Parse error: syntax error, unexpected T_STRING in C:\sokkit\site\phptestarea\new\add_biog.php on line 37

    Line 37 being the last line here
    [CODE $insert_query = "INSERT INTO `biogger`
    ( `title`, `name` , `age`, `email` , `bio`, `www`) VALUES
    ( "$title" , "$name", "$age", "$email", "$bio", "$www" ) ";[/CODE]
    and without the quotes i get the old

    Error! Could not insert values: Unknown column 'gh' in 'field list'

    ???

  • #8
    Regular Coder
    Join Date
    May 2005
    Posts
    235
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Silly me
    i put "" instead of ''
    I t works fine now
    thank you all
    Crowds

  • #9
    Senior Coder
    Join Date
    Apr 2005
    Posts
    1,051
    Thanks
    0
    Thanked 0 Times in 0 Posts
    your last if statement is wrong


    the syntax is

    if(some crap){
    some crap
    } else {
    some more crap
    }
    public string ConjunctionJunction(string words, string phrases, string clauses)
    {
    return (String)(words + phrases + clauses);
    }
    <--- Was I Helpfull? Let me know ---<

  • #10
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    Quote Originally Posted by rlemon
    your last if statement is wrong


    the syntax is

    if(some crap){
    some crap
    } else {
    some more crap
    }
    Nah. As long as theres only one statement below the if or else, it'll execute:
    PHP Code:
    if(this == that)
       
    //just doing one thing here
    if(this == that)
    {
       
    //do this;
       //do this too;

    Get it?

  • #11
    Senior Coder
    Join Date
    Apr 2005
    Posts
    1,051
    Thanks
    0
    Thanked 0 Times in 0 Posts
    cool, i didn't know that! :P
    public string ConjunctionJunction(string words, string phrases, string clauses)
    {
    return (String)(words + phrases + clauses);
    }
    <--- Was I Helpfull? Let me know ---<

  • #12
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by rlemon
    your last if statement is wrong


    the syntax is

    if(some crap){
    some crap
    } else {
    some more crap
    }
    Technically its not wrong. While I prefer to use curly braces for readability, what is there is perfectly good PHP code.

  • #13
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Whoops, beat me to it Brandoe

  • #14
    Regular Coder
    Join Date
    May 2005
    Posts
    235
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well its all working fine now..
    I just got to work out a way of including the information gained here

    $ht = mysql_real_escape_string($_POST['ht']);
    $user = mysql_real_escape_string($_POST['user']);
    $pw = mysql_real_escape_string($_POST['pw']);
    $dbn = mysql_real_escape_string($_POST['dbn']);

    To a new page called db_config.php I know i have to use fopen and flock some how but i need it to write the data in the middle of something like
    $ht ="datahere"
    And i hane not the foggiest idea

  • #15
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Quote Originally Posted by missing-score
    Technically its not wrong. While I prefer to use curly braces for readability, what is there is perfectly good PHP code.
    I wouln't ever suggest someone writing it that way. It's one of those things you can do but shouldn't.
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •