unexpected T_STRING in (newbe)

Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default unexpected T_STRING in (newbe)

    Hi,

    I am trying to fill a database mysql with php.

    if (!$db){
    echo "Error: Could not connect to database. Please try again later.";
    exit;
    }
    mysql_select_db("pierredata");
    ===================== up tohere is ok
    I tried theese two lines and others

    INSERT INTO `commentaires`
    (`nom`,`courriel`,`sujet`,`commentaire`)VALUES('Mo i2', 'ss@eee.vv',
    'Bonjour', 'test');
    INSERT INTO `commentaires`
    (`nom`,`courriel`,`sujet`,`commentaire`)VALUES(\"M oi2\", \"ss\@eee.vv\",
    \"Bonjour\", \"test\");

    I get an error

    unexpected T_STRING



    Jean Pierre


    --

    --
    [url]http://web.jeanpierredaviau.com[/url]



    Québec Guest

  2. Similar Questions and Discussions

    1. #40790 [NEW]: List interface parsed as T_LIST instead of T_STRING
      From: markpk at gmail dot com Operating system: PHP version: 5.2.1 PHP Bug Type: Scripting Engine problem Bug description: ...
    2. PHP Parse error: parse error, unexpected t_string
      Thanks for your advice. It was a painstaking exercise and highly frustrating not being able to start Live data. Peter Kamstra
    3. unexpected T_STRING problem..
      hi with this function i get: function retournlisteartricle($nosection) { echo '<table>'; $requete = mysql_query("SELECT art_noarticle,...
    4. newbe THANKS
      Thanks to all with your help were up and running and looks good ! had to reload the program from the web, my new set of disks had a beta ver of...
    5. parse error, unexpected T_STRING
      in the line "include(sign.php);" the file name should be in quotes; like include("sign.php"); hth Kurt Milligan sky2070 wrote:
  3. #2

    Default Re: unexpected T_STRING in (newbe)

    In article <cX%Zc.55002$681.917031@weber.videotron.net>, [email]Once@WasEno.ugh[/email]
    says...
    > Hi,
    >
    > I am trying to fill a database mysql with php.
    >
    > if (!$db){
    > echo "Error: Could not connect to database. Please try again later.";
    > exit;
    > }
    > mysql_select_db("pierredata");
    > ===================== up tohere is ok
    > I tried theese two lines and others
    >
    > INSERT INTO `commentaires`
    > (`nom`,`courriel`,`sujet`,`commentaire`)VALUES('Mo i2', 'ss@eee.vv',
    > 'Bonjour', 'test');
    > INSERT INTO `commentaires`
    > (`nom`,`courriel`,`sujet`,`commentaire`)VALUES(\"M oi2\", \"ss\@eee.vv\",
    > \"Bonjour\", \"test\");
    >
    > I get an error
    >
    > unexpected T_STRING
    >
    >
    Assuming you've CREATE-d a TABLE named commentaires with 4
    columns/fields ...
    Try :
    INSERT INTO commentaires VALUES('Moi2','ss@eee.vv','Bonjour','test');

    Let's see the TABLE strucure as well.

    Rocky
    [url]http://www.rockymania.org.uk/[/url]
    Rocky Guest

  4. #3

    Default Re: unexpected T_STRING in (newbe)

    This line has been generated by the table.
    I will try your line
    Jean
    "Rocky" <admin@rockymania.org.uk> a écrit dans le message de
    news:MPG.1ba29ef6825e241098968f@text.news.ntlworld .com...
    > In article <cX%Zc.55002$681.917031@weber.videotron.net>, [email]Once@WasEno.ugh[/email]
    > says...
    > > Hi,
    > >
    > > I am trying to fill a database mysql with php.
    > >
    > > if (!$db){
    > > echo "Error: Could not connect to database. Please try again
    later.";
    > > exit;
    > > }
    > > mysql_select_db("pierredata");
    > > ===================== up tohere is ok
    > > I tried theese two lines and others
    > >
    > > INSERT INTO `commentaires`
    > > (`nom`,`courriel`,`sujet`,`commentaire`)VALUES('Mo i2', 'ss@eee.vv',
    > > 'Bonjour', 'test');
    > > INSERT INTO `commentaires`
    > > (`nom`,`courriel`,`sujet`,`commentaire`)VALUES(\"M oi2\", \"ss\@eee.vv\",
    > > \"Bonjour\", \"test\");
    > >
    > > I get an error
    > >
    > > unexpected T_STRING
    > >
    > >
    > Assuming you've CREATE-d a TABLE named commentaires with 4
    > columns/fields ...
    > Try :
    > INSERT INTO commentaires VALUES('Moi2','ss@eee.vv','Bonjour','test');
    >
    > Let's see the TABLE strucure as well.
    >
    > Rocky
    > [url]http://www.rockymania.org.uk/[/url]

    Québec Guest

  5. #4

    Default Re: unexpected T_STRING in (newbe)

    Same problem .

    > > Let's see the TABLE strucure as well.
    # phpMyAdmin SQL Dump
    # version 2.5.3
    # [url]http://www.phpmyadmin.net[/url]
    #
    # Serveur:
    # Généré le : Vendredi 03 Septembre 2004 à 15:30
    # Version du serveur: 4.0.15
    # Version de PHP: 4.3.3
    #
    # Base de données: `pierredata`
    #

    # --------------------------------------------------------

    #
    # Structure de la table `etudiants`
    #

    CREATE TABLE `etudiants` (
    `ID` int(11) NOT NULL auto_increment,
    `courriel` char(40) NOT NULL default '',
    `passe` char(15) NOT NULL default '',
    `nom` char(40) NOT NULL default '',
    `peinture` char(20) NOT NULL default '',
    `adresse` char(70) NOT NULL default '',
    `tel` char(15) NOT NULL default '',
    PRIMARY KEY (`ID`)
    ) TYPE=MyISAM COMMENT='premiere' AUTO_INCREMENT=3 ;

    #
    # Contenu de la table `etudiants`
    #

    INSERT INTO `etudiants` VALUES (1, 'foo@foot.ca', 'qWefoo76', 'Jean Pierre
    Daviau', '', '12 foo4ave Québec H1B 4N9', '51462');


    Québec Guest

  6. #5

    Default Re: unexpected T_STRING in (newbe)

    Sorry,

    =====================
    # phpMyAdmin SQL Dump
    # version 2.5.3
    # [url]http://www.phpmyadmin.net[/url]
    #
    # Serveur: localhost
    # Généré le : Vendredi 03 Septembre 2004 à 15:35
    # Version du serveur: 4.0.15
    # Version de PHP: 4.3.3
    #
    # Base de données: `pierredata`
    #

    # --------------------------------------------------------

    #
    # Structure de la table `commentaires`
    #

    CREATE TABLE `commentaires` (
    `nom` varchar(45) NOT NULL default '',
    `courriel` varchar(30) NOT NULL default '',
    `sujet` varchar(50) NOT NULL default '',
    `commentaire` mediumtext NOT NULL
    ) TYPE=MyISAM;

    #
    # Contenu de la table `commentaires`
    #

    INSERT INTO `commentaires` VALUES ('Jean Pierre Daviau', 'foo@foo.ca',
    'Bonjour', 'Un commentaire');


    Québec Guest

  7. #6

    Default Re: unexpected T_STRING in (newbe)

    In article <%J3_c.61015$Vx2.956264@wagner.videotron.net>,
    [email]Once@WasEno.ugh[/email] says...
    > Sorry,
    >
    > =====================
    > # phpMyAdmin SQL Dump
    > # version 2.5.3
    > # [url]http://www.phpmyadmin.net[/url]
    > #
    > # Serveur: localhost
    > # Généré le : Vendredi 03 Septembre 2004 à 15:35
    > # Version du serveur: 4.0.15
    > # Version de PHP: 4.3.3
    > #
    > # Base de données: `pierredata`
    > #
    >
    > # --------------------------------------------------------
    >
    > #
    > # Structure de la table `commentaires`
    > #
    >
    > CREATE TABLE `commentaires` (
    > `nom` varchar(45) NOT NULL default '',
    > `courriel` varchar(30) NOT NULL default '',
    > `sujet` varchar(50) NOT NULL default '',
    > `commentaire` mediumtext NOT NULL
    > ) TYPE=MyISAM;
    >
    > #
    > # Contenu de la table `commentaires`
    > #
    >
    > INSERT INTO `commentaires` VALUES ('Jean Pierre Daviau', 'foo@foo.ca',
    > 'Bonjour', 'Un commentaire');
    >
    >
    With a DataBase name of pierredata I ran the sql and all worked fine.

    Rocky
    Rocky Guest

  8. #7

    Default Re: unexpected T_STRING in (newbe)

    Thank you. The error must be somewhere else in the code and unrelated to
    that line ...

    Jean


    Québec Guest

  9. #8

    Default Re: unexpected T_STRING in (newbe)


    U¿ytkownik "Québec" <Once@WasEno.ugh> napisa³ w wiadomo¶ci
    news:cX%Zc.55002$681.917031@weber.videotron.net...
    > INSERT INTO `commentaires`
    > (`nom`,`courriel`,`sujet`,`commentaire`)VALUES('Mo i2', 'ss@eee.vv',
    > 'Bonjour', 'test');
    > INSERT INTO `commentaires`
    > (`nom`,`courriel`,`sujet`,`commentaire`)VALUES(\"M oi2\", \"ss\@eee.vv\",
    > \"Bonjour\", \"test\");
    >
    > I get an error
    >
    > unexpected T_STRING
    Did You put an sql query directly into PHP code? unexpected T_STRING is
    probably 'INSERT' word which is not
    an PHP function.:)
    Look like really newbie problem :) And all replies too...LOL
    Try:
    mysql_query("INSERT INTO `commentaires`
    (`nom`,`courriel`,`sujet`,`commentaire`)VALUES('Mo i2', 'ss@eee.vv',
    'Bonjour', 'test')");
    Read about:
    [url]http://www.php.net/manual/en/function.mysql-query.php[/url]

    Drizzt


    Drizzt Do'Urden Guest

  10. #9

    Default Re: unexpected T_STRING in (newbe)

    I have an autoincrement ID in column 1
    I have a Date in column 8
    Should this work and the first and last columns taken care by mySql
    automatically?

    mysql_query("INSERT INTO `etudiants` (`courriel`, `passe`, `nom`, `image`,
    `adresse`,`telephone`)VALUES($courrielty , $passe, $nomty, $imagety,
    $addressty, $telty)");

    Jean


    Québec Guest

  11. #10

    Default Re: unexpected T_STRING in (newbe)


    U¿ytkownik "Québec" <Once@WasEno.ugh> napisa³ w wiadomo¶ci
    news:cj2%c.7078$dd5.769719@weber.videotron.net...
    > I have an autoincrement ID in column 1
    > I have a Date in column 8
    > Should this work and the first and last columns taken care by mySql
    > automatically?
    >
    > mysql_query("INSERT INTO `etudiants` (`courriel`, `passe`, `nom`, `image`,
    > `adresse`,`telephone`)VALUES($courrielty , $passe, $nomty, $imagety,
    > $addressty, $telty)");
    >
    > Jean
    autoincrement - yes - will be do automatically
    Date - no - have to add `Date` to field list and NOW() to values list

    Drizzt


    Drizzt Do'Urden Guest

  12. #11

    Default Re: unexpected T_STRING in (newbe)

    > autoincrement - yes - will be do automatically
    > Date - no - have to add `Date` to field list and NOW() to values list
    I took off the ID and used
    mysql_query("INSERT INTO `commentaires`(`nom`, `courriel`, `sujet`,
    `commentaire`, `date`) VALUES ($nom, $courriel, $sujet, $commentaire,
    NOW())");

    The result is printed in a html page before the variables go thrue
    addslashes.
    nothing is written in the table commentaires
    I am using EasyPHP 1.7

    Jean

    -------------------php ------------

    $sujet = $_REQUEST['sujet'];
    $nom = $_REQUEST['nom'];
    $courriel = $_REQUEST['courriel'];
    $commentaire = $_REQUEST['commentaire'];

    $empty = array($nom, $courriel, $sujet, $commentaire);
    $empty2 = array("nom", "courriel", "sujet", "commentaire");
    $j = 0;
    $missing = "<p>";

    while($j < 4){
    if($empty[$j] == "")
    $missing = $missing.$empty2[$j]."<br>";
    $j++;
    }
    if($missing != "<p>") {
    printf("Formulaire incomplet: %s <br>manquant(s).", $missing);
    printf("<p><a
    href='http://127.0.0.1/JeanPierreDaviau/feedback.htm'>Complétez le
    formulaire.</a>");
    exit;
    }

    $db = mysql_pconnect("localhost", "root", "secret");
    if (!$db){
    echo "Error: Could not connect to database. Please try again later.";
    exit;
    }
    echo $db."<---<br>";
    mysql_select_db("pierredata");
    echo "<p>".$nom."<br>".$courriel."<br>".$sujet."<br>".$ commentaire."</p>";
    echo "<p>merci de votre attention.</p>";


    $nom = addslashes($nom);
    $courriel = addslashes($courriel);
    $sujet = addslashes($sujet);
    $commentaire = addslashes($commentaire);


    mysql_query("INSERT INTO `commentaires`(`nom`, `courriel`, `sujet`,
    `commentaire`, `date`) VALUES ($nom, $courriel, $sujet, $commentaire,
    NOW())");
    ?>
    ----------------


    Québec Guest

  13. #12

    Default Re: unexpected T_STRING in (newbe)

    I get It!
    variables must be in quotes '$name' etc

    thanks.


    Québec Guest

  14. #13

    Default Re: unexpected T_STRING in (newbe)

    Quote Originally Posted by Drizzt Do'Urden View Post
    U¿ytkownik "Québec" <Once@WasEno.ugh> napisa³ w wiadomo¶ci
    news:cX%Zc.55002$681.917031@weber.videotron.net...

    Did You put an sql query directly into PHP code? unexpected T_STRING is
    probably 'INSERT' word which is not
    an PHP function.:)
    Look like really newbie problem :) And all replies too...LOL
    Try:
    mysql_query("INSERT INTO `commentaires`
    (`nom`,`courriel`,`sujet`,`commentaire`)VALUES('Mo i2', 'ss@eee.vv',
    'Bonjour', 'test')");
    Read about:
    [url]http://www.php.net/manual/en/function.mysql-query.php[/url]

    Drizzt
    I had spent hours and hours trying to get my DB to allow records to be added via Web (MySQL and PHP). Many Website searches, reading wikis and tutorials/resources later I was getting closer but still blowing it up on the add part - it would connect just fine. Your instructions above had all the answers to my syntax problems - Thanks!
    Unregistered Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139