boompa
Members-
Posts
305 -
Joined
-
Last visited
-
Days Won
1
Everything posted by boompa
-
Parse error: syntax error, unexpected P_LNUMBER
boompa replied to BTIconnect's topic in PHP Coding Help
The colon is an alternative syntax for the if(), there's nothing wrong with it as long as there's a matching endif;, which is what I was concerned about (and the terminating } of the function there). I can't help but wonder if there's some unprintable control character in there that's causing an issue. Like kicken said above, there are no syntax errors in the pasted code. Perhaps you could upload and attach the file, and someone can look at it in a hex editor. -
Parse error: syntax error, unexpected P_LNUMBER
boompa replied to BTIconnect's topic in PHP Coding Help
Is that the entirety of the PHP code here? -
Parse error: syntax error, unexpected P_LNUMBER
boompa replied to BTIconnect's topic in PHP Coding Help
Could you please tell us what line is number 64? -
Ah yes, you're right. I saw the box right below, but failed to realize that this API *is* the feed API: My apologies for misleading you.
-
Always Display Child Pages on Parent Pages and Child Pages PHP MySQL
boompa replied to FishSword's topic in PHP Coding Help
Does AND here really make sense? SELECT * FROM db.pages WHERE parent = '.$parents['id'].' AND parent = '.$_GET['id'] -
https://developers.facebook.com/docs/reference/api/publishing/ Seeing as they're using cURL -- a command-line tool -- as an example, it's safe to say there's no dialog involved.
-
Unexpected end: usually means you've forgotten a } In other words, the parser, reading from top-to-bottom, encountered an opening { but never found the matching } to close it. Hence...unexpected end.
-
That error usually means you're missing something on the line right before the reported line. I don't know what comes before your else but this is generally bad form. $province = @$_GET["Province"]; Suppressing the error notice is a bad idea. You should be using isset($_GET['province']), and only running the code you've given if that is true. You also have no SQL error checking, another bad idea. And you're open to SQL injection because $_GET is easily manipulated by users and you're not sanitizing it prior to using it in your query.
-
You need to start telling us what the errors are! If it's what I think, then it's really the same answer as your last question, so read this and understand it: If you try to access an element of an array and that element doesn't exist, you will get a notice from PHP (not truly an error). The way to prevent this is to check if the element of the array exists by calling isset($array['index']) before you try to access the element. Just like I wrote in the last question about your SESSION variable.
-
$_SESSION['cart'] = array(); or if (isset($_SESSION['cart'])) $cartItemCount = count($_SESSION['cart']); else $cartItemCount = 0; or, using the ternary operator $cartItemCount = (isset($_SESSION['cart']) ? count($_SESSION['cart']) : 0;
-
You have more than 50 posts now. How about using them If you're sending them by the POST method, then you, you use $_POST. However you are just entering two numbers, no operation. In the receiving page you pass the numbers to the constructor of a new object, then once you fix the problem noted in the previous sentence, you call the appropriate function on your new object. $myObject = new MyObject($arg1, $arg2); $myObject->doThisWithObject()
-
You don't run your function and output anything unless a REQUEST variable named "value" is set. Do you have a form element with a name of "value"? What's this doing in there? <?php echo form_close();?>
- 4 replies
-
- calculator
- php
-
(and 1 more)
Tagged with:
-
How do I change where my php file saves a file?
boompa replied to HeyAwesomePeople's topic in PHP Coding Help
Add the path here, before the file name: $finalName = $ip."(".$port.").html"; Make sure the directory to which you intend to write already exists, and the user under which PHP/the webserver is running has write permissions on that directory. -
Nothing showing, what am I doing wrong here?
boompa replied to nicoscodes's topic in PHP Coding Help
What editor are you using on your Mac to create the PHP files? -
Nothing showing, what am I doing wrong here?
boompa replied to nicoscodes's topic in PHP Coding Help
Somewhere, maybe in your "include/konnect.php" file, you have phpinclude() instead of just include(). -
Nothing showing, what am I doing wrong here?
boompa replied to nicoscodes's topic in PHP Coding Help
$sql=mysql_query("SELECT * FROM ask") or die("MySQL Failure: " . mysql_error()); if (mysql_num_rows($sql) == 0) die("There were no rows returned"); while($row=mysql_fetch_array($sql)) Add that to your code and what do you find? -
importing multiple files into different mysql tables
boompa replied to richei's topic in PHP Coding Help
You really should look into using indentation as an aid in writing code. This is what your code should look more like: foreach(glob(APP_PATH."files/*.txt") as $file) { $filen = basename($file); if(left($filen, 12) == "S_W_80045583") { $tables = 'venzo_itunes_trends'; $ReportFile = APP_PATH."files/".$filen; if(!is_file(MUSIC."/$filen")) { $data[] = array("path"=>MUSIC, "table"=>$tables, "file"=>$ReportFile); } else { echo "$filen already exists<br />"; } } elseif(left($filen, 12) == "S_D_80045583") { $tables = 'venzo_itunes_dtrends'; $ReportFile = APP_PATH."files/".$filen; if(!is_file(MUSIC."/$filen")) { $data[] = array("path"=>MUSIC, "table"=>$tables, "file"=>$ReportFile); } else { echo "$filen already exists<br />"; } } elseif(left($filen, 12) == "S_W_85409067") { $tables = 'venzo_app_trends'; $ReportFile = APP_PATH."files/".$filen; if(!is_file(APP."/$filen")) { $data[] = array("path"=>APP, "table"=>$tables, "file"=>$ReportFile); } else { echo "$filen already exists<br />"; } } elseif(left($filen, 12) == "S_D_85409067") { $tables = 'venzo_app_dtrends'; $ReportFile = APP_PATH."files/".$filen; if(!is_file(APP."/$filen")) { $data[] = array("path"=>APP, "table"=>$tables, "file"=>$ReportFile); } else { echo "$filen already exists<br />"; } } } foreach($data as $key => $value) { echo "<pre>"; print_r($value); echo "</pre>"; $report = $value['file']; $companyTbl = $value['table']; $path = $value['path']; $filen = basename($report); $fcontents = file($report, FILE_IGNORE_NEW_LINES); /*check the table exists*/ $qry = current(mysql_fetch_row(mysql_query("SELECT DATABASE()"))); $qry = mysql_query("SHOW TABLES FROM `{$qry}` LIKE '{$companyTbl}'") or die(mysql_error()); if(mysql_num_rows($qry) < 1) { //unlink($path."/".$file); die("Table `{$companyTbl}` for '{$company}' does not exist!"); } /*pull the field list out of the DB*/ $qry = mysql_query("SHOW FIELDS FROM `{$companyTbl}`") or die(mysql_error()); $sqlFieldNum = mysql_num_rows($qry); while($field = mysql_fetch_assoc($qry)) { $sqlFields[] = strtolower($field['Field']); } /*check the field list in the report and the field list in the database match*/ if($sqlFieldNum != count($fieldArr = explode("\t", $fcontents[0]))) { foreach($fieldArr as $key => $value) { $fields[0][$key] = trim(str_replace('/', '_', strtolower($value))); $fields[1][$key] = trim(str_replace(array('/', ' '), '_', strtolower($value))); $fields[2][$key] = trim(str_replace(array('/', ' '), array('_', ''), strtolower($value))); } $tfields = $fields[0]; /*check for fields in the DB that are not in the report*/ for($a = 0; $a < count($sqlFields); $a++) { if($sqlFields[$a] != $fields[0][$a] && $sqlFields[$a] != $fields[1][$a] && $sqlFields[$a] != $fields[2][$a]) { $error = true; } else { unset($tfields[$a]); } } /*check for fields in the report that are not in the DB*/ if(count($tfields) > 0) { $error = true; } } /*if there is an error, stop here and delete the file*/ // this should be deleting it out of the destination folder if($error == true) { unlink($path."/".$filen); die(); } /*for each record in the report...*/ for($i = 1; $i < count($fcontents); $i++) { $line = $fcontents[$i]; $arr = explode("\t", $line); /*santitise the values*/ foreach($arr as $key => $value) { $arr[$key] = trim(mysql_real_escape_string($value)); } if(strtolower($arr[0]) != "total") { /*number of fields in the DB exceeds number of fields in the record*/ if($sqlFieldNum > count($arr)) { $error[$i] = true; for($a = 0; $a < count($sqlFields); $a++) { echo "{$a}) MYSQL: {$a} => {$sqlFields[$a]} - Report: {$a} => {$arr[$a]}"; } echo "# of fields in the table (" . $sqlFieldNum . ") is greater than the # of fields in the report (" . count($arr) . ")!"; /*number of fields in the record exceeds number of fields in the DB*/ } else if($sqlFieldNum < count($arr)) { $error[$i] = true; for($a = 0; $a < count($arr); $a++) { echo "{$a}) MYSQL: {$a} => {$sqlFields[$a]} - Report: {$a} => {$arr[$a]}"; } echo "# of fields in the report (" . count($arr) . ") is greater than the # of fields in the table (" . $sqlFieldNum . ")!"; } /*if there is no error insert the record into the table else continue onto the next record*/ if(isset($error[$i]) != true) { $sql = "INSERT INTO {$companyTbl}(" . implode(', ', $sqlFields) . ") VALUES ('" . implode("', '", $arr) . "')"; $ins = mysql_query($sql) or die(mysql_error()); if($ins) { echo "$filen has been imported<br>"; copy($report, $path."/".$filen); if(is_file($file)) { unlink($file); } } else { echo "Problem with $filen<br>"; } } else { echo "Record {$i} not inserted!"; } } } /*if there is an error, stop here and delete the file*/ if(count($error) > 0) { unlink($path."/".$file); die(); } unset($sqlFields, $fcontents, $line); unset($process, $report, $companyTbl, $path, $filen, $file); } What's the current problem, and can you attach a sample of your data file thast preserves the tabs that are separating the fields? Looks like what you pasted in here lost those. -
Wouldn't logic dictate that if you're seeing "exec importspreadsheet" on each row, and you only want to see it once, that that part of the string doesn't belong in the loop? SMH
-
Nothing showing, what am I doing wrong here?
boompa replied to nicoscodes's topic in PHP Coding Help
Either your query is failing (you don't check), the query's not returning any rows, or you have a syntax error. -
If you're trying to store an array to MySQL, chances are you're doing it wrong, and your database schema is incorrect. If you'd like to tell us your schema and what you're trying to do, we may be able to suggest a different schema and how to leverage it.
-
Help with database multiple record entry with php
boompa replied to ezeuba's topic in PHP Coding Help
See if this helps you with what you need to do: <?php $emails = 'joe@example.com,fred@example.com,betty@example.net'; $values = ''; foreach(explode(',', $emails) as $email) $values .= "('$email'),"; $query = "INSERT INTO emails VALUES " . rtrim($values, ','); echo "$query\n"; -
Just noticed this: if (!filter_has_var(INPUT_POST, "fName"));{ All your if statements have ; after them, rendering them useless. You could combine filter_has_var() and empty() also.
-
What are the symptoms that make you think you're doing something wrong?