|
|
|
|
![]() ![]() |
Jan 3 2007, 10:03 PM
Post
#1
|
|
|
Premium Member Group: Members Posts: 250 Joined: 6-July 06 From: The net (or at least that's what my family says) Member No.: 14,330 |
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: CODE //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 This post has been edited by ginginca: Jan 3 2007, 10:04 PM |
|
|
|
Jan 4 2007, 12:43 AM
Post
#2
|
|
|
Premium Member Group: [HOSTED] Posts: 479 Joined: 5-November 06 Member No.: 17,016 |
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 |
|
|
|
Jan 4 2007, 01:14 AM
Post
#3
|
|
|
Premium Member Group: Members Posts: 250 Joined: 6-July 06 From: The net (or at least that's what my family says) Member No.: 14,330 |
It says line 88.
Line 88 is right after: CODE GetSQLValueString($city, "text")); |
|
|
|
Jan 4 2007, 01:51 AM
Post
#4
|
|
|
Premium Member Group: [HOSTED] Posts: 479 Joined: 5-November 06 Member No.: 17,016 |
|
|
|
|
Jan 4 2007, 02:10 AM
Post
#5
|
|
|
Super Member Group: [HOSTED] Posts: 750 Joined: 8-April 06 From: Lima - Peru Member No.: 12,579 |
Hi, i notice that you are using dreamweaver
Well i see that you have 2 errors in the last part of your code:
Best regards, |
|
|
|
Jan 4 2007, 04:36 AM
Post
#6
|
|
|
Techno-Necromancer Group: Members Posts: 1,018 Joined: 13-January 05 From: The Net Member No.: 2,127 |
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 |
|
|
|
Jan 4 2007, 01:51 PM
Post
#7
|
|
|
Premium Member Group: Members Posts: 250 Joined: 6-July 06 From: The net (or at least that's what my family says) Member No.: 14,330 |
You forgot your comma at the line before that (87) CODE 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: CODE 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> CODE <? 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? This post has been edited by ginginca: Jan 4 2007, 01:55 PM |
|
|
|
Jan 4 2007, 04:06 PM
Post
#8
|
|
|
Premium Member Group: [HOSTED] Posts: 479 Joined: 5-November 06 Member No.: 17,016 |
Here's the line 176: $ll_res=mysql_db_query("londonlink", $ll_sql, $ll_conn)or Did you call mysql_connect() for $ll_conn? CODE 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 |
|
|
|
Jan 4 2007, 05:21 PM
Post
#9
|
|
|
Premium Member Group: Members Posts: 250 Joined: 6-July 06 From: The net (or at least that's what my family says) Member No.: 14,330 |
Did you call mysql_connect() for $ll_conn? CODE 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: CODE $database = mysql_pconnect($hostname_database, $username_database, $password_database) or trigger_error(mysql_error(),E_USER_ERROR); |
|
|
|
Jan 4 2007, 05:42 PM
Post
#10
|
|
|
Premium Member Group: [HOSTED] Posts: 479 Joined: 5-November 06 Member No.: 17,016 |
I have this line on my page for the database details: CODE $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 CODE $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 QUOTE 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. |
|
|
|
![]() ![]() |
Similar Topics
| Topics | Topics | |
|---|---|---|
|
|
|
|