ginginca 0 Report post Posted January 3, 2007 (edited) I am writing a new submit page for one of my sites and am doing a few things to stretch my experience. I am getting an error (naturally.) Here is part pf the page where the error might be: //Check to see if the web page called itself if (strtoupper($action) == "CHECK") { //The web page called itself, so run the error checking code //Declare a variable to hold the error messages $error = ''; // variable names: name, cat, sub_cat, url, date, status, email, other, area_code, city $name = $_POST['name']; $cat = $_POST['cat']; $sub_cat = $_POST['sub_cat']; $url = $_POST['url']; $date = $_POST['today']; $status = $_POST['0']; $email = $_POST['email']; $other = $_POST['0']; $area_code = $_POST['area_code']; $city = $_POST['city']; //begin error checking in fields //Are Required fields blank? if ((empty($name)) or (empty($cat)) or (empty($sub_cat)) or (empty($url)) or (empty($email)) or (empty($area_code)) or (empty($city))) { //required field is blank $error .= 'One or more required fields are blank.<BR>'; echo $error; } //Is area code 3 characters? if ((strlen($area_code)) <3) { //required length too small $error .= 'Area code is not the required length.<BR>'; echo $error; } } if (($error == '') and (isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "myform")) { $insertSQL = sprintf("INSERT INTO links (name, cat, sub_cat, url, email, area_code, city) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($name, "text"), GetSQLValueString($cat, "text"), GetSQLValueString($sub_cat, "text"), GetSQLValueString($url, "text"), GetSQLValueString($date, "text"), GetSQLValueString($status, "text"), GetSQLValueString($email, "text"), GetSQLValueString($other, "text"), GetSQLValueString($area_code, "text") GetSQLValueString($city, "text")); mysql_select_db($database_database, $database); date, status, and other are not filled in by the user. I'm thinking this is likely where I messed it up. The error message I get is: Parse error: parse error, unexpected T_STRING Edited January 3, 2007 by ginginca (see edit history) Share this post Link to post Share on other sites
faulty.lee 0 Report post Posted January 4, 2007 Parse error: parse error, unexpected T_STRING It's a parse error, meaning something wrong with the source code, not even able to execute. At which line is the error. Normally a line number is show, and that's important to help locate the error. unexpected T_STRING means that there shouldn't be a string followed by the whatever line of code. Maybe you miss out a semi colon, or a bracket or something else Share this post Link to post Share on other sites
ginginca 0 Report post Posted January 4, 2007 It says line 88.Line 88 is right after: GetSQLValueString($city, "text")); Share this post Link to post Share on other sites
faulty.lee 0 Report post Posted January 4, 2007 It says line 88.Line 88 is right after: GetSQLValueString($city, "text")); You forgot your comma at the line before that (87)GetSQLValueString($area_code, "text") <-- missing comma Share this post Link to post Share on other sites
TavoxPeru 0 Report post Posted January 4, 2007 Hi, i notice that you are using dreamweaver Well i see that you have 2 errors in the last part of your code: You forgot to close the if statement }, it is true only if you don't post the complete source code. You forgot to put a comma between the area code and the city fields in your variable $insertSQL. GetSQLValueString($area_code, "text") , GetSQLValueString($city, "text")); And check the line before the line number given by the error message. Best regards, Share this post Link to post Share on other sites
vizskywalker 0 Report post Posted January 4, 2007 As the above people said, the problem is just minor typos in your code.T_STRING stands for (I believe) Text String, which means a string of random text, as opposed to code. Parse Error means that the parser, which runs before the compiler to replace variable names and things like that, didn't understand what you wanted to happen. And please, when providing an error message, please provide the entire message (for instance, the line number, which you left out in the initial post). and if the line number is given, place line numbers in the provided code so we don't have to ask which line of code is that line.~Viz Share this post Link to post Share on other sites
ginginca 0 Report post Posted January 4, 2007 (edited) You forgot your comma at the line before that (87) GetSQLValueString($area_code, "text") <-- missing comma Yes that in fact was the problem ... thank you! A few years ago someone wrote a script for me for this site when I knew nothing about php. I am re-writing everything with some new features. For the most part I'm doing it from scratch because his style is very different than mind and I don't necessarily follow his logic. His style was to number all the fields which I have never done mysql that way. In my form there are fields that need to dynamically populate (category and sub category). He did it this way: Category*</span>:</td> <td colspan="2" class="TitleColor"><span class="style4"> <select name="Category1" onChange="document.thisform.submit()"> <option value="">Select</option> <? $ll_sql="select * from category order by name"; $ll_res=mysql_db_query("londonlink", $ll_sql, $ll_conn)or die('Could not connect: ' . mysql_error()); for ($i=0; $i<mysql_num_rows($ll_res); $i++) { $ll_info=mysql_fetch_row($ll_res); if ($ll_info[0] == $HTTP_POST_VARS[Category1]) { print "<option value=\"$ll_info[0]\" selected>".$ll_info[1]."</option>"; } else { print "<option value=\"$ll_info[0]\">".$ll_info[1]."</option>"; } } ?> </select> <? if (!$HTTP_POST_VARS[Category1]) { } else { ?> <select name="Category2"> <? $ll_sql="select * from sub_category where cat='$HTTP_POST_VARS[Category1]' order by name"; $ll_res=mysql_db_query("londonlink", $ll_sql, $ll_conn)or die('Could not connect: ' . mysql_error()); for ($i=0; $i<mysql_num_rows($ll_res); $i++) { $ll_info=mysql_fetch_row($ll_res); print "<option value=\"$ll_info[0]\">".$ll_info[2]."</option>"; } ?> </select> When I said "numbering" I'm referring to syntax like this: $ll_info[0] I copied this section of the script, and inserted it into my php page and voila ... the form stops displaying right at this point. There's a select box for this field (with no data) and nothing thereafter. No error is displaying on the page. When I do a VIEW SOURCE, I can see this: <b>Warning</b>: mysql_db_query(): supplied argument is not a valid MySQL-Link resource in <b>filename</b> on line <b>176</b><br /> Could not connect: I also don't get why he is calling his fields category1 and category2. Doesn't it make more sense to name them what they actually are? (cat and sub_cat) Here's the line 176: $ll_res=mysql_db_query("londonlink", $ll_sql, $ll_conn)or His connect variables are different than mine? Edited January 4, 2007 by ginginca (see edit history) Share this post Link to post Share on other sites
faulty.lee 0 Report post Posted January 4, 2007 Here's the line 176: $ll_res=mysql_db_query("londonlink", $ll_sql, $ll_conn)or Did you call mysql_connect() for $ll_conn?if (!$ll_conn = mysql_connect('mysql_host', 'mysql_user', 'mysql_password')) { echo 'Could not connect to mysql'; exit;} Sounds like you miss the above coding Share this post Link to post Share on other sites
ginginca 0 Report post Posted January 4, 2007 Did you call mysql_connect() for $ll_conn? if (!$ll_conn = mysql_connect('mysql_host', 'mysql_user', 'mysql_password')) { echo 'Could not connect to mysql'; exit;} Sounds like you miss the above coding I have this line on my page for the database details:$database = mysql_pconnect($hostname_database, $username_database, $password_database) or trigger_error(mysql_error(),E_USER_ERROR); Share this post Link to post Share on other sites
faulty.lee 0 Report post Posted January 4, 2007 I have this line on my page for the database details: $database = mysql_pconnect($hostname_database, $username_database, $password_database) or trigger_error(mysql_error(),E_USER_ERROR); How you relate $database to $ll_conn??? You can try $ll_res=mysql_db_query("londonlink", $ll_sql)without the $ll_sql, that way the function will just use the last mysql connection of that session Description resource mysql_db_query ( string database, string query [, resource link_identifier] ) mysql_db_query() selects a database, and executes a query on it. Parameters database The name of the database that will be selected. query The MySQL query. link_identifier The MySQL connection. If the link identifier is not specified, the last link opened by mysql_connect() is assumed. If no such link is found, it will try to create one as if mysql_connect() was called with no arguments. If by chance no connection is found or established, an E_WARNING level warning is generated. Share this post Link to post Share on other sites
ginginca 0 Report post Posted January 4, 2007 (edited) I think what's happening is that it isn't getting my user name.The error message is this:Could not connect: Access denied for user: '@localhost' to database 'the name of my database'Looks to me like I am telling it that my user name is @localhost ?I have done this:I added code above my select statement:$database = mysql_pconnect(all the details here without using variables) or trigger_error(mysql_error(),E_USER_ERROR); Now my script will go one line further than before.It lists the categories but not the subcategories. Edited January 4, 2007 by ginginca (see edit history) Share this post Link to post Share on other sites