PHP - Error Offset 1 Database Error
okay this sounds strange I know but
but apart from html code in pure php the database values display correctly but when I combine with HTML code i get an offset error when retrieving certain values example results from database file no HTML coding: February10 2012 5pm MY EVENT NEW YORK ERROR when combined with HTML: February MYEVENT 2012 NewYork Similar TutorialsHello, I have this script that I have been running a long time that is included in my site with a php include. It reads data from a cached file in an array. I noticed last night something has happened and it won't load in my site anymore and causes my site not to load. I determined this through various troubleshooting. Through the various troubleshooting I was able to get an error "Fatal error: Cannot use string offset as an array in /home4/mesquiu0/public_html/nws_alerts_scroller.php on line 44". This is strange because nothing has changed on my server or with this script. Also if I run it by itself it runs fine. http://www.mesquitew...ts_scroller.php but, when I include it in my site it won't load and I get the error. I am not sure what is causing this. I have done some research and it appears to be cause by a key as though it were an array of arrays. I just don't see it though.
Here is the portion of the code it is referring to.
// IF there are alerts if(!empty($atomAlerts)) { // IF there are alerts usort($atomAlerts, 'a_sort'); // sort locations foreach($atomAlerts as $aak => $aav) { // FOR EACH alert, get the data from the cache file $caav = count($aav); // count alerts for($i=0;$i<$caav;$i++) { // FOR EACH alert // assemble alert data $title[$i][0] = '<b>'.strtoupper($aav[$i][0]).'</b>'; @$adarray[$aav[$i][10].' '.$title[$i][0]] .= ' - <a href="'.$alertURL.'?a=' .$aav[$i][14].'#WA'.$aav[$i][13].'" title=" Details for '.$aav[$i][12] .' '.$aav[$i][0].'">' .$aav[$i][12] ."</a>"; } } }Here is a sample of the cached file the script reads from. $atomAlerts = array ( 'TXZ104' => array ( 0 => array ( 0 => 'Dense Fog Advisory', 1 => 'Expected', 2 => 'Minor', 3 => 'Likely', 4 => 1418136720, 5 => 1418148000, 6 => 'Anderson; Bell; Bosque; Collin; Comanche; Cooke; Coryell; Dallas; Delta; Denton; Eastland; Ellis; Erath; Falls; Fannin; Freestone; Grayson; Hamilton; Henderson; Hill; Hood; Hopkins; Hunt; Jack; Johnson; Kaufman; Lamar; Lampasas; Leon; Limestone; McLennan; Milam; Mills; Montague; Navarro; Palo Pinto; Parker; Rains; Robertson; Rockwall; Somervell; Stephens; Tarrant; Van Zandt; Wise; Young', 7 => 'DENSE FOG IS OCCURRING OVER THE REGION WHICH WILL CREATE VERY HAZARDOUS DRIVING CONDITIONS. SLOW DOWN...USE YOUR LOW BEAM HEADLIGHTS...AND LEAVE PLENTY OF DISTANCE BETWEEN YOU AND THE VEHICLE AHEAD OF YOU.', 8 => '...DENSE FOG ADVISORY NOW IN EFFECT UNTIL NOON CST TODAY... * LOCATION...ALL OF NORTH CENTRAL TEXAS. * VISIBILITY...WIDESPREAD VISIBILITY REDUCTIONS OF LESS THAN 1/4 OF A MILE. VISIBILITIES WILL BEGIN TO IMPROVE AFTER NOON. * IMPACTS...DENSE FOG WILL MAKE DRIVING HAZARDOUS.', 9 => '#F60', 10 => ' <img src="./images/FGY.gif" width="12" height="12" alt="Dense Fog Advisory" title=" Dense Fog Advisory" />', 11 => '56', 12 => 'Collin Co', 13 => '1', 14 => 'TXZ104', 15 => '', ), ),Any idea what might be causing this. I don't see anything right off the bat. Just strange it loads fine alone and the problem only happens and happened out of the blue when I include it in my site. I have tried to isolate it to see what might be conflicting with it but have been unsuccessful. I also would add it only errors and doesn't load when included in my site when there is an alert. Right now there is no alerts at the moment. There was alerts at the time this happened. -Thanks Edited by Texan78, 09 December 2014 - 02:19 PM. Hi everyone... please help me with this. I have a gallery that I am working on. Part of that are two files upload.php and preupload.php which upload pics. And it does its job successfully BUT it shows an error 'Notice: Undefined offset: 9 in C:\wamp\www\upload.php on line 34' My line 34 is Code: [Select] if($photos_uploaded['size'][$counter] > 0). My whole code for the upload.php is <?php include("config.inc.php"); // initialization $result_final = ""; $counter = 0; // List of our known photo types $known_photo_types = array( 'image/pjpeg' => 'jpg', 'image/jpeg' => 'jpg', 'image/gif' => 'gif', 'image/bmp' => 'bmp', 'image/x-png' => 'png' ); // GD Function List $gd_function_suffix = array( 'image/pjpeg' => 'JPEG', 'image/jpeg' => 'JPEG', 'image/gif' => 'GIF', 'image/bmp' => 'WBMP', 'image/x-png' => 'PNG' ); // Fetch the photo array sent by preupload.php $photos_uploaded = $_FILES['photo_filename']; // Fetch the photo caption array $photo_caption = $_POST['photo_caption']; while( $counter <= count($_FILES['photo_filename']['tmp_name']) ) { if($photos_uploaded['size'][$counter] > 0) { if(!array_key_exists($photos_uploaded['type'][$counter], $known_photo_types)) { $result_final .= "File ".($counter+1)." is not a photo<br />"; } else { mysql_query( "INSERT INTO gallery_photos( `photo_filename`, `photo_caption`, `photo_category` ) VALUES( '0', '".addslashes($photo_caption[$counter])."', '".addslashes($_POST['category'])."')" ) or die(mysql_error() . 'Photo not uploaded'); $new_id = mysql_insert_id(); $filetype = $photos_uploaded['type'][$counter]; $extention = $known_photo_types[$filetype]; $filename = $new_id.".".$extention; mysql_query( "UPDATE gallery_photos SET photo_filename='".addslashes($filename)."' WHERE photo_id='".addslashes($new_id)."'" ); // Store the orignal file copy($photos_uploaded['tmp_name'][$counter], $images_dir."/".$filename); // Let's get the Thumbnail size $size = GetImageSize( $images_dir."/".$filename ); if($size[0] > $size[1]) { $thumbnail_width = 200; $thumbnail_height = (int)(200 * $size[1] / $size[0]); } else { $thumbnail_width = (int)(200 * $size[0] / $size[1]); $thumbnail_height = 200; } // Build Thumbnail with GD 1.x.x, you can use the other described methods too $function_suffix = $gd_function_suffix[$filetype]; $function_to_read = "ImageCreateFrom".$function_suffix; $function_to_write = "Image".$function_suffix; // Read the source file $source_handle = $function_to_read ( $images_dir."/".$filename ); if($source_handle) { // Let's create an blank image for the thumbnail $destination_handle = ImageCreateTrueColor ( $thumbnail_width, $thumbnail_height ); // Now we resize it ImageCopyResized( $destination_handle, $source_handle, 0, 0, 0, 0, $thumbnail_width, $thumbnail_height, $size[0], $size[1] ); } // Let's save the thumbnail $function_to_write( $destination_handle, $images_dir."/tb_".$filename, 99 ); ImageDestroy($destination_handle ); // $result_final .= "<img src='".$images_dir. "/tb_".$filename."' /> File ".($counter+1)." Added<br />"; } } $counter++; } // Print Result echo <<<__HTML_END <html> <head> <title>Photos uploaded</title> </head> <body> $result_final </body> </html> __HTML_END; ?> I get an undefined offset error when i try and call the array i made i know very little so I'm stuck and i don't know what to do Code: [Select] <?php $file = fopen("playerstats.csv","r"); $data = array(); while (($csv_line = fgetcsv($file, 0, ";")) !== FALSE) { echo $csv_line; $number = $csv_line[0]; $name = $csv_line[1]; $half = $csv_line[2]; $goals = $csv_line[3]; $assists = $csv_line[4]; $SOG = $csv_line[5]; $shots = $csv_line[6]; $fouls = $csv_line[7]; $yellow = $csv_line[8]; $yellowred = $csv_line[9]; $red = $csv_line[10]; $CK = $csv_line[11]; $saves = $csv_line[12]; $data[] = array( 'name' => $name, 'half' => $half, 'goals' => $goals, 'assists' => $assists, 'sog' => $SOG, 'shots' => $shots, 'fouls' => $fouls, 'yellow' => $yellow, 'yellowred' => $yellowred, 'red' => $red, 'ck' => $CK, 'saves' => $saves ); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <table><tr><td>Number: </td><td><?php echo $data[0];?></td></tr></table> </body> </html> im getting Undefined offset: 0 in many line what can be the issue? Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><!-- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> --> <title>Untitled Document</title> </head> <body> <?php if(isset($_POST['submit'])) { $userquery = $_POST['userquery']; $xml = simplexml_load_file("http://www.google.com/ig/api?weather='".$userquery."'"); $information = $xml->xpath("/xml_api_reply/weather/forecast_information"); $current = $xml->xpath("/xml_api_reply/weather/current_conditions"); $forecast_list = $xml->xpath("/xml_api_reply/weather/forecast_conditions"); echo "<h1>".$information[0]->city['data'].", ".$information[0]->forecast_date['data']."</h1>"; echo "<h2>Current Contition</h2>"; echo "<div class=\"weather\">"; echo "<table width='250' border='1'>"; echo "<tr>"; echo "<td><img src='http://www.google.com".$current[0]->icon['data']."' width='70' height='70' alt='weather'></td>"; echo "<td>"; echo $current[0]->condition['data']; echo "<br/>Min "; echo $current[0]->temp_c['data']."° C, <br/>"; echo $current[0]->temp_f['data']."° F, <br/>"; echo $current[0]->humidity['data'].", <br/>"; echo $current[0]->wind_condition['data']."."; echo "</td>"; echo "</tr>"; echo "</table>"; echo "</span>"; echo "</div>"; echo "<h2>Forecast</h2>"; foreach ($forecast_list as $forecast) : echo "<div class=\"weather\">"; echo "<table width='250' border='1'>"; echo "<tr>"; echo "<td>"; echo "<img src='http://www.google.com".$forecast->icon['data']."' width='50' height='50'alt='weather'>"; echo "</td>"; echo "<td>"; echo "<div>".$forecast->day_of_week['data']."</div>"; echo "<span class=\"condition\">"; echo $forecast->low['data']."° F - ".$forecast->high['data']."° F,<br/>"; echo $forecast->condition['data']."."; echo "</td>"; echo "</tr>"; echo "</table>"; echo "</span>"; echo "</div>"; endforeach; } ?> <form action="test.php" method="post"> <input name="userquery" type="text" value=""/> <input type="submit" name='submit' value="get"/> </form> </body> </html> here all errors and there are few more Notice: Undefined offset: 0 in C:\wamp\www\fiunc\test.php on line 16 Notice: Trying to get property of non-object in C:\wamp\www\fiunc\test.php on line 16 Notice: Undefined offset: 0 in C:\wamp\www\fiunc\test.php on line 16 Notice: Trying to get property of non-object in C:\wamp\www\fiunc\test.php on line 16 , it happens when i add if(isset($_POST['submit'])) { $userquery = $_POST['userquery']; and this in '".$userquery."' $xml = simplexml_load_file("http://www.google.com/ig/api?weather='".$userquery."'"); What I am trying to do is to associate a user (id) to a page they create, so if joe blogs is user 4, then the data base will show the page details, and add the id (from a user page). However, when I try the code to save data I get the following error messages:
Notice: Undefined offset: 4 in C:\xampp\htdocs\MyCMS\admin\index.php on line 98 I include the code to insert the page: <!-- Insert Page --> <?php if(isset($_POST['submitted']) == 1) { $header = stripslashes($_REQUEST['header']); $header = mysqli_real_escape_string($dbc, $header); $title = stripslashes($_REQUEST['title']); $title = mysqli_real_escape_string($dbc, $title); $body = stripslashes($_REQUEST['body']); $body = mysqli_real_escape_string($dbc, $body); $userid = stripslashes($_REQUEST['userid']); $userid = mysqli_real_escape_string($dbc, $userid); $q = "INSERT INTO `pages` (`userid`, `header`, `title`, `body`) VALUES ($_POST[$userid], '$header', '$title', '$body')"; $r = mysqli_query($dbc, $q) or die(mysqli_error($dbc)); if($r) { $message = '<p>Page was added.</p>'; } else { $message = '<p>Page could not be added due to: </p>'.mysqli_error($dbc); $message .= '<p>'.$q.'</p>'; } // end if inner } // end if outer ?> The form has - Page Header, Page Title, User, and boys. There is a working list of current users. It is these users (and new users) that I want to add to a 'Pages' database, which has the following fields: id, userid, header, title, body; and a 'User' database with the following fields: id, firstname, lastname, username, password, status. Any help to solve the issues will be appreciated. Thanks.
I am writing a data scraping script but i am getting fatal error.Can someone please help me. My code:- Code: [Select] <?php $con = mysql_connect("localhost","root",""); mysql_select_db("cakeshop", $con); $test = '<form name="select"> <p><font color="#000000" size="3"><select name="city" size="1" onchange="self.location.href=this.options[this.selectedIndex].value"> <option value="xxxwi.htm">Wisconsin</option> <option value="xxxwy.htm">Wyoming</option> </select><br clear="all"> </font><font color="#000000" size="2">Click on the state below where you want to send cake<br> or use the pull down menu above </font> </form> '; preg_match_all('~<option\s+value="(.*?)">(.*?)</option>~', $test, $out); for($i=0;$i<=2;$i++) { $data = file_get_contents('http://xxx.com/'.$out[1][$i].''); preg_match_all('~<option\s+value="(.*?)">(.*?)</option>~', $data, $city); //$klimit = sizeof($city); $klimit = count($city[1]); for($k=2 ;$k < $klimit; $k++) { $data = file_get_contents('http://xxx.com/'.$city[1][$k].''); //Error on this line $regex = '~<td\s+colspan="2"\s+width="350"><font\s+size="2">\s+<b>\s+(.*?) <\/b><br>(.*?) <br>(.*?),\s+(.*?)\s+<br>(.*?), (.*?)\s+<BR><BR><font\s+size="2"><img\s+src="\.\.\/images\/phone1.gif"\s+align="left"\s+hspace="4"\s+alt\s+=(.*)>\s+-\s+Phone\s+#\s+(.*?)\s+<\/font>\s+<BR>\s+<font\s+size\s+="1">~'; preg_match_all($regex, $data, $final); $jlimit = count($final[1]); for($j=0 ;$j < $jlimit; $j++) { $name = $final[1][$j]; $name = mysql_real_escape_string($name); $address = $final[2][$j]; $address = mysql_real_escape_string($address); $city = $final[3][$j]; $city = mysql_real_escape_string($city); $state = $final[4][$j]; $state = mysql_real_escape_string($state); $pincode = $final[6][$j]; $pincode = mysql_real_escape_string($pincode); $telephone = $final[8][$j]; $telephone = mysql_real_escape_string($telephone); mysql_query("INSERT INTO cakeshop (name, address, city, state, pincode, telephone) VALUES ('$name', '$address', '$city', '$state', '$pincode', '$telephone')"); } } } mysql_close($con); echo "Data scraping completed"; ?> Error message :- Code: [Select] Fatal error: Cannot use string offset as an array in C:\Users\Booone\AppData\Roaming\NuSphere\PhpED\projects\scraping1.php Error is on this line "$data = file_get_contents('http://xxx.com/'.$city[1][$k].'');" I'm getting an error: Undefined offset: 1 in… I'm trying to display a 2D array after filling it. It displays fine if I echo it while it's being made, but after it is not working.
I'm making a pyramid solitaire game and am trying to set up the pyramid of cards. There are 7 arrays, each with a set amount of cards in them. The first array only gets one cards while the last array gets seven. This makes it like a pyramid. All the indexes that don't get a card are set to 0. So it looks like this where the 1's are cards:
1 0 0 0 0 0 0 0
1 1 0 0 0 0 0 0
1 1 1 0 0 0 0 0
1 1 1 1 0 0 0 0
1 1 1 1 1 0 0 0
1 1 1 1 1 1 0 0
1 1 1 1 1 1 1 0
1 1 1 1 1 1 1 1
The display2Darray function is what is causing the error. Specifically this line:
if($array[$i][$j] == 0)Heres my main code: <?php include_once "pyramidCard.php"; include_once "pyramidDeck.php"; $theDeck = new Deck(); $pyramid = array(array(), array(), array(), array(), array(), array(), array()); $size = 7; $theDeck->shuffleCards(); makePyramid($pyramid, $size, $theDeck); display2Darray($pyramid, $size); //************************ // FRUNCTIONS * //************************ function makePyramid($array, $size, $deck) { $row = 0; for($i = 0; $i < $size; $i++) { for($j = 0; $j < $size; $j++) { if($j > $row) { $array[$i][$j] = 0; //echo ". <br>"; } else { $array[$i][$j] = $deck->dealCards(); //echo "this card is ".$array[$i][$j]->getFace()." of ".$array[$i][$j]->getSuit()."<br>"; } } $row++; } } function display2Darray($array, $size) { for($i = 0; $i < $size; $i++) { for($j = 0; $j < $size; $j++) { if($array[$i][$j] == 0) echo " "; else echo $array[$i][$j]->getFace()." of ".$array[$i][$j]->getSuit(); } echo "<br>"; } } ?> Hi, when I run my script I get the following error message. These are array variables I am passing into the playerAttack function. I can't figure out what is wrong it looks fine to me. Any help greatly appreciated. Thanks. Derek Code: [Select] attack posted Fatal error: Cannot use string offset as an array in C:\wamp\www\SUN_DRAGON_GAME\gamestart.php on line 202 Code: [Select] $currentMonster='octalisk'; ///////////////////////////////////////////////////////////battle//////////////////////////// //function monsterEncounter($echoMonster,$monsterImage) if(!empty($_POST['attack'])) { echo "attack posted"; playerAttack($currentMonster,$player['stats']['playerHitRollLow'],$player['stats']['playerHitRollHigh'], $player['stats']['playerDmgLow'],$player['stats']['playerDmgHigh'],$monsters['Ocean']['octalisk']['defense'],$monster['Ocean']['octalisk']['hp'],$player['faction']['Teardrop_Ocean_Protectors']); $doesItAttack=encounter($monsters['ocean']['octalisk']['seeInvis'],$monsters['ocean']['octalisk']['aggro'],$player['factions']['Teardrop_Ocean_Protectors']); //insert octalisk stats into monsterattack function. if($doesItAttack =='yes') { monsterAttack($currentMonster,$monsters['Ocean']['octalisk']['hitRollLow'],$monsters['Ocean']['octalisk']['hitRollHigh'] , $monsters['Ocean']['octalisk']['dmgLow'],$monsters['Ocean']['octalisk']['dmgHigh'], $player['stats']['playerDefense'],$player['stats']['playerHp'],$monsters['Ocean']['octalisk']['hp']); } else { echo "do nothing"; } } here is the attack function Code: [Select] function playerAttack($currentMonster,$hitRollLow,$hitRollHigh,$dmgLow,$dmgHigh,$monsterDefense, $monsterHp,$playerFaction) { echo "in player attack"; $playerRoll= rand($playerHitRollLow, $playerHitRollHigh); if($playerHitRoll>=$monsterDefense) { global $theMessage; //shit had to make it global $playerDamage= rand($playerDmgLow,$playerDmgHigh); $theMessage = "You have hit a ". $currentMonster." for "."<strong>". $playerDamage."</strong> points of damage!"; $monsterHp= $monsterHp- $playerDamage; $theMessage.=" The ".$currentMonster."'s hp is now ".$monsterHp; if($monsterHp<=0) { if($playerFaction<=0) { $theMessage="Your faction standing with ".$playerFaction. "could not possibly get any worse."; } } $theMessage.=" You have killed the ".$currentMonster. "Your faction standing with ".$playerFaction." is now ".$playerFaction-1; } else { global $theMessage; //WTF i dont know what im doing. $theMessage= " Whoa! You missed the ".$currentMonster; } } Im having this error and have the not even the slightest clue on how to solve it... Code: [Select] Notice: Undefined offset: 2 in C:\wamp\www\updat5.php on line 146 <?php $picture = array(); while($row = mysql_fetch_assoc($result)) { $id = $row['id']; $picture = array(); switch ($row['icon']) { case 1: $picture[$id] = '<img src="img/apple.gif" title="apple" alt="apple" />'; echo $picture[$id]; break; case 2: $picture[$id] = '<img src="img/banana.gif" title="banana" alt="banana" />'; echo $picture[$id]; break; case 3: $picture[$id] = '<img src="img/orange.gif" title="orange" alt="orange" />'; echo $picture[$id]; break; default: $picture[$id] = ''; echo $row['icon'] . " is something other than 1 2 or 3"; break; } } ?> <hr> <?php echo $picture[2]; ?> And line 146 is: echo $picture[2]; My next post will be the full code if needed incase the error I have currently cant be fixed with the current snippet/block i posted. Hi, WHAT: So I cannot for the life of me figure out why I'm getting this error. I'm trying to create a function that will display the user information from the database in a table but I have like a ton of these errors on the page and I don't know whats wrong. STEPS TO RESOLVE: So I've gone over my code a bunch of types to make sure that all the variables and what not were spelled correctly and as far as I can tell they are. I've also googled this issue to see if I can find a solution but none of them are very helpful. I honestly don't know whats wrong so kinda hard to find ways to resolve an issue, I don't even really know what this error means. THE CODE: This is where I put the function into action <?php display_table( array( "id" => "Id", "emailaddress" => "Email", "firstname" => "First Name", "lastname" => "Last Name", "salesperson" => "Salesperson", "phonenumber" => "Phone Number", "extension" => "Extension", "type" => "Type" ) ); ?> //This is the function <?php function display_table($fields, $data, $rows, $page){ if(isset($_GET['page'])){ $page = $_GET['page']; } else { $page = 1; } $firstRecord = ($page - 1) * ROWS_PER_PAGE; $pageNumbers = ceil($rows / ROWS_PER_PAGE); echo '<div class="table-responsive w-75 mx-auto py-3"> <table class="table table-dark table-bordered table-sm"> <thead> <tr>'; foreach($fields as $key){ echo '<th class="py-2">' . $key . '</th>'; } echo '</tr> </thead> </tbody>'; $keys = array_keys($fields); for($record = $firstRecord; $record < $firstRecord + ROWS_PER_PAGE; $record++){ $row = $data[$record]; echo '<tr>'; for($recordCount = 0; $recordCount < count($keys); $recordCount++){ $column = $keys[$recordCount]; echo '<td class="py-2">' . $row[$column] . '</td>'; } echo '</tr>'; } echo '</tbody> </table'; for($pages = 1; $pages <= $pageNumbers; $pages++){ echo '<a class="btn btn-dark mx-1" href=?page=' . $pages . '</a>'; } } ?> Any help/advice would be really appreciated I'm trying to develop a Joomla plugin for 1.6/1.7 and from what I've read, future versions are supposed to be php E~STRICT compliant. I know that doesn't mean I have to fix this since it is just a notice, but I am curious how one would hide the error. Code: [Select] $task_array = explode('.', JRequest::getVar('task')); # Splits article.save $task = $task_array[1]; #This is line 58 I know it happens because $task_array is empty, but how can i wrap that in something to stop this Notice error? I've tried !empty() but that doesn't work. A friend of mine must of changed something on the site while I was asleep last night and now all the site says when you go to it is: Error Database query error Warning: mail() [function.mail]: SMTP server response: 530 SMTP authentication is required. in C:\xampp\htdocs\inc\utils.inc.php on line 449 I'm not exactly sure what he did since I can't contact him. Can anyone help me fix this? I am a new developer, trying to figure out what causing a memory error. The code goes through registered appointments and depends on the service ID, I have to free a 45 minutes for another service to be booked. Now, once I book an appointment for any of the services that can have 45 minutes free spot, the website takes forever to load the hours but doesn't show them, instead I get this error A PHP Error was encountered Severity: Error Message: Maximum execution time of 120 seconds exceeded
foreach ($appointments as $appointment) { foreach ($periods as $index => &$period) { $appointment_start = new DateTime($appointment['start_datetime']); $appointment_end = new DateTime($appointment['end_datetime']); if ($appointment_start >= $appointment_end) { continue; } $period_start = new DateTime($date . ' ' . $period['start']); $period_end = new DateTime($date . ' ' . $period['end']); $serviceId=$appointment['id_services']; $color1=1; $color2=2; $color3=3; $color4=4; $color5=5; $color6=6; $color7=7; $color8=8; $color9=9; $color10=10; $color11=11; $color12=12; $color13=13; $color14=14; $color15=15; $color16=16; $color17=17; $color18=18; $color19=19; $period_s=''; $period_e=''; if ($appointment_start <= $period_start && $appointment_end <= $period_end && $appointment_end <= $period_start) { // The appointment does not belong in this time period, so we will not change anything. continue; } else { if ($appointment_start <= $period_start && $appointment_end <= $period_end && $appointment_end >= $period_start) { // The appointment starts before the period and finishes somewhere inside. We will need to break // this period and leave the available part. //open slot for services 45,45,45 if($serviceId == $color1 || $serviceId == $color3 || $serviceId == $color7 || $serviceId == $color9|| $serviceId == $color10 || $serviceId == $color11 || $serviceId == $color12){ unset($periods[$index]); $period_s= clone $appointment_start; $period_s->modify('+45 minutes'); $period_e= clone $appointment_end; $period_e->modify('-45 minutes'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; $period['start'] = $appointment_end->format('H:i'); } //Open slot for service 45,45,60 else if($serviceId == $color2 || $serviceId == $color8){ $period_s= clone $appointment_start; $period_s->modify('+45 minutes'); $period_e= clone $appointment_end; $period_e->modify('-60 minutes'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; $period['start'] = $appointment_end->format('H:i'); } // // //Open slot for service 30,45,45 else if($serviceId == $color4 || $serviceId == $color6 ||$serviceId == $color16 || $serviceId == $color18){ $period_s= clone $appointment_start; $period_s->modify('+30 minutes'); $period_e= clone $appointment_end; $period_e->modify('-45 minutes'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; $period['start'] = $appointment_end->format('H:i'); } // // //Open slot for service 30,45,60 else if($serviceId == $color5 || $serviceId == $color17){ $period_s= clone $appointment_start; $period_s->modify('+30 minutes'); $period_e= clone $appointment_end; $period_e->modify('-60 minutes'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; $period['start'] = $appointment_end->format('H:i'); } // // //Open slot for service 60,45,45 else if($serviceId == $color13 || $serviceId == $color15){ $period_s= clone $appointment_start; $period_s->modify('+60 minutes'); $period_e= clone $appointment_end; $period_e->modify('-45 minutes'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; $period['start'] = $appointment_end->format('H:i'); } // // //Open slot for service 60,45,60 else if($serviceId == $color14 ){ $period_s= clone $appointment_start; $period_s->modify('+60 minutes'); $period_e= clone $appointment_end; $period_e->modify('-60 minutes'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; $period['start'] = $appointment_end->format('H:i'); } // //for the rest of services else { $period['start'] = $appointment_end->format('H:i');} } else { if ($appointment_start >= $period_start && $appointment_end < $period_end) { // The appointment is inside the time period, so we will split the period into two new // others. unset($periods[$index]); if($serviceId == $color1 || $serviceId == $color3 || $serviceId == $color7 || $serviceId == $color9|| $serviceId == $color10 || $serviceId == $color11 || $serviceId == $color12){ $period_s= clone $appointment_start; $period_s->modify('+45 minutes'); $period_e= clone $appointment_end; $period_e->modify('-45 minutes'); $periods[] = [ 'start' => $period_start->format('H:i'), 'end' => $appointment_start->format('H:i') ]; $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; $periods[] = [ 'start' => $appointment_end->format('H:i'), 'end' => $period_end->format('H:i') ]; } // //Open slot for service 45,45,60 else if($serviceId == $color2 || $serviceId == $color8){ $period_s= clone $appointment_start; $period_s->modify('+45 minutes'); $period_e= clone $appointment_end; $period_e->modify('-60 minutes'); $periods[] = [ 'start' => $period_start->format('H:i'), 'end' => $appointment_start->format('H:i') ]; $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; $periods[] = [ 'start' => $appointment_end->format('H:i'), 'end' => $period_end->format('H:i') ]; } // // //Open slot for service 30,45,45 else if($serviceId == $color4 || $serviceId == $color6 ||$serviceId == $color16 || $serviceId == $color18){ $period_s= clone $appointment_start; $period_s->modify('+30 minutes'); $period_e= clone $appointment_end; $period_e->modify('-45 minutes'); $periods[] = [ 'start' => $period_start->format('H:i'), 'end' => $appointment_start->format('H:i') ]; $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; $periods[] = [ 'start' => $appointment_end->format('H:i'), 'end' => $period_end->format('H:i') ]; } // // //Open slot for service 30,45,60 else if($serviceId == $color5 || $serviceId == $color17){ $period_s= clone $appointment_start; $period_s->modify('+30 minutes'); $period_e= clone $appointment_end; $period_e->modify('-60 minutes'); $periods[] = [ 'start' => $period_start->format('H:i'), 'end' => $appointment_start->format('H:i') ]; $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; $periods[] = [ 'start' => $appointment_end->format('H:i'), 'end' => $period_end->format('H:i') ]; } // // //Open slot for service 60,45,45 else if($serviceId == $color13 || $serviceId == $color15){ $period_s= clone $appointment_start; $period_s->modify('+60 minutes'); $period_e= clone $appointment_end; $period_e->modify('-45 minutes'); $periods[] = [ 'start' => $period_start->format('H:i'), 'end' => $appointment_start->format('H:i') ]; $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; $periods[] = [ 'start' => $appointment_end->format('H:i'), 'end' => $period_end->format('H:i') ]; } // // //Open slot for service 60,45,60 else if($serviceId == $color14 ){ $period_s= clone $appointment_start; $period_s->modify('+60 minutes'); $period_e= clone $appointment_end; $period_e->modify('-60 minutes'); $periods[] = [ 'start' => $period_start->format('H:i'), 'end' => $appointment_start->format('H:i') ]; $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; $periods[] = [ 'start' => $appointment_end->format('H:i'), 'end' => $period_end->format('H:i') ]; } //for other services once The code is completely correct else{ $periods[] = [ 'start' => $period_start->format('H:i'), 'end' => $appointment_start->format('H:i') ]; $periods[] = [ 'start' => $appointment_end->format('H:i'), 'end' => $period_end->format('H:i') ]; } } else if ($appointment_start == $period_start && $appointment_end == $period_end) { if($serviceId == $color1 || $serviceId == $color3 || $serviceId == $color7 || $serviceId == $color9|| $serviceId == $color10 || $serviceId == $color11 || $serviceId == $color12){ unset($periods[$index]); $period_s= $appointment_start; $period_s->modify('+45 minutes'); $period_e= $appointment_end; $period_e->modify('-45 minutes'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; } //Open slot for service 45,45,60 else if($serviceId == $color2 || $serviceId == $color8){ unset($periods[$index]); $period_s= clone $appointment_start; $period_s->modify('+45 minutes'); $period_e= clone $appointment_end; $period_e->modify('-60 minutes'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; } // // //Open slot for service 30,45,45 else if($serviceId == $color4 || $serviceId == $color6 ||$serviceId == $color16 || $serviceId == $color18){ unset($periods[$index]); $period_s= clone $appointment_start; $period_s->modify('+30 minutes'); $period_e= clone $appointment_end; $period_e->modify('-45 minutes'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; } // // //Open slot for service 30,45,60 else if($serviceId == $color5 || $serviceId == $color17){ unset($periods[$index]); $period_s= clone $appointment_start; $period_s->modify('+30 minutes'); $period_e= clone $appointment_end; $period_e->modify('-60 minutes'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; } // // //Open slot for service 60,45,45 else if($serviceId == $color13 || $serviceId == $color15){ unset($periods[$index]); $period_s= clone $appointment_start; $period_s->modify('+60 minutes'); $period_e= clone $appointment_end; $period_e->modify('-45 minutes'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; } // // //Open slot for service 60,45,60 else if($serviceId == $color14 ){ unset($periods[$index]); $period_s= clone $appointment_start; $period_s->modify('+60 minutes'); $period_e= clone $appointment_end; $period_e->modify('-60 minutes'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ];} // //for the rest of services else { unset($periods[$index]);} // The whole period is blocked so remove it from the available periods array. } else { if ($appointment_start >= $period_start && $appointment_end >= $period_start && $appointment_start <= $period_end) { // The appointment starts in the period and finishes out of it. We will need to remove //the time that is taken from the appointment. if($serviceId == $color1 || $serviceId == $color3 || $serviceId == $color7 || $serviceId == $color9|| $serviceId == $color10 || $serviceId == $color11 || $serviceId == $color12){ unset($periods[$index]); $period_s= clone $appointment_start; $period_s->modify('+45 minutes'); $period_e= clone $appointment_end; $period_e->modify('-45 minutes'); $period['end'] = $appointment_start->format('H:i'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; } //Open slot for service 45,45,60 else if($serviceId == $color2 || $serviceId == $color8){ $period_s= clone $appointment_start; $period_s->modify('+45 minutes'); $period_e= clone $appointment_end; $period_e->modify('-60 minutes'); $period['end'] = $appointment_start->format('H:i'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; } // // //Open slot for service 30,45,45 else if($serviceId == $color4 || $serviceId == $color6 ||$serviceId == $color16 || $serviceId == $color18){ $period_s= clone $appointment_start; $period_s->modify('+30 minutes'); $period_e= clone $appointment_end; $period_e->modify('-45 minutes'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; $period['end'] = $appointment_start->format('H:i'); } // // //Open slot for service 30,45,60 else if($serviceId == $color5 || $serviceId == $color17){ $period_s= clone $appointment_start; $period_s->modify('+30 minutes'); $period_e= clone $appointment_end; $period_e->modify('-60 minutes'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; $period['end'] = $appointment_start->format('H:i'); } // // //Open slot for service 60,45,45 else if($serviceId == $color13 || $serviceId == $color15){ $period_s= clone $appointment_start; $period_s->modify('+60 minutes'); $period_e= clone $appointment_end; $period_e->modify('-45 minutes'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; $period['end'] = $appointment_start->format('H:i'); } // // //Open slot for service 60,45,60 else if($serviceId == $color14 ){ $period_s= clone $appointment_start; $period_s->modify('+60 minutes'); $period_e= clone $appointment_end; $period_e->modify('-60 minutes'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; $period['end'] = $appointment_start->format('H:i'); } // for the rest of services else{ $period['end'] = $appointment_start->format('H:i'); } } else { if ($appointment_start >= $period_start && $appointment_end >= $period_end && $appointment_start >= $period_end) { // The appointment does not belong in the period so do not change anything. continue; } else { if ($appointment_start <= $period_start && $appointment_end >= $period_end && $appointment_start <= $period_end) { //Open slot for service 45,45,45 if($serviceId == $color1 || $serviceId == $color3 || $serviceId == $color7 || $serviceId == $color9|| $serviceId == $color10 || $serviceId == $color11 || $serviceId == $color12){ unset($periods[$index]); $period_s= clone $appointment_start; $period_s->modify('+45 minutes'); $period_e= clone $appointment_end; $period_e->modify('-45 minutes'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; } //Open slot for service 45,45,60 else if($serviceId == $color2 || $serviceId == $color8){ unset($periods[$index]); $period_s= clone $appointment_start; $period_s->modify('+45 minutes'); $period_e= clone $appointment_end; $period_e->modify('-60 minutes'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; } // //Open slot for service 30,45,45 else if($serviceId == $color4 || $serviceId == $color6 ||$serviceId == $color16 || $serviceId == $color18){ unset($periods[$index]); $period_s= clone $appointment_start; $period_s->modify('+30 minutes'); $period_e= clone $appointment_end; $period_e->modify('-45 minutes'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ];} //Open slot for service 30,45,60 else if($serviceId == $color5 || $serviceId == $color17){ unset($periods[$index]); $period_s= clone $appointment_start; $period_s->modify('+30 minutes'); $period_e= clone $appointment_end; $period_e->modify('-60 minutes'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ];} // // //Open slot for service 60,45,45 else if($serviceId == $color13 || $serviceId == $color15){ unset($periods[$index]); $period_s= clone $appointment_start; $period_s->modify('+60 minutes'); $period_e= clone $appointment_end; $period_e->modify('-45 minutes'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ];} // // //Open slot for service 60,45,60 else if($serviceId == $color14 ){ unset($periods[$index]); $period_s= clone $appointment_start; $period_s->modify('+60 minutes'); $period_e= clone $appointment_end; $period_e->modify('-60 minutes'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ];} else{ unset($periods[$index]); } } } } } } } } } return array_values($periods); } Hello all,
Appreciate if you folks could pls. help me understand (and more importantly resolve) this very weird error:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ASC, purchase_later_flag ASC, shopper1_buy_flag AS' at line 3' in /var/www/index.php:67 Stack trace: #0 /var/www/index.php(67): PDO->query('SELECT shoplist...') #1 {main} thrown in /var/www/index.php on line 67
Everything seems to work fine when/if I use the following SQL query (which can also be seen commented out in my code towards the end of this post) :
$sql = "SELECT shoplist.*, store_master.store_name, item_master.item_name FROM shoplist, store_master, item_master WHERE shoplist.store_id = store_master.store_id AND shoplist.item_id = item_master.item_id";However, the moment I change my query to the following, which essentially just includes/adds the ORDER BY clause, I receive the error quoted above: $sql = "SELECT shoplist.*, store_master.store_name, item_master.item_name FROM shoplist, store_master, item_master ORDER BY purchased_flag ASC, purchase_later_flag ASC, shopper1_buy_flag ASC, shopper2_buy_flag ASC, store_name ASC) WHERE shoplist.store_id = store_master.store_id AND shoplist.item_id = item_master.item_id";In googling for this error I came across posts that suggested using "ORDER BY FIND_IN_SET()" and "ORDER BY FIELD()"...both of which I tried with no success. Here's the portion of my code which seems to have a problem, and line # 67 is the 3rd from bottom (third last) statement in the code below: <?php /* $sql = "SELECT shoplist.*, store_master.store_name, item_master.item_name FROM shoplist, store_master, item_master WHERE shoplist.store_id = store_master.store_id AND shoplist.item_id = item_master.item_id"; */ $sql = "SELECT shoplist.*, store_master.store_name, item_master.item_name FROM shoplist, store_master, item_master ORDER BY FIND_IN_SET(purchased_flag ASC, purchase_later_flag ASC, shopper1_buy_flag ASC, shopper2_buy_flag ASC, store_name ASC) WHERE shoplist.store_id = store_master.store_id AND shoplist.item_id = item_master.item_id"; $result = $pdo->query($sql); // foreach ($pdo->query($sql) as $row) { foreach ($result as $row) { echo '<tr>'; print '<td><span class="filler-checkbox"><input type="checkbox" name="IDnumber[]" value="' . $row["idnumber"] . '" /></span></td>';Thanks Parse error: syntax error, unexpected T_STRING in C:\xampp\htdocs\mywork\unique.php on line 15 <html> <head> <title> </title> </head> <body bgproperties="fixed"> <?php $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = ''; $con = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); $dbname = 'mywork'; mysql_select_db($dbname, $con); $sql=mysql_query(insert into users (regno,name,gender,date,month,year,emailid,cell,paddress,caddress,incometype,incomeamt,dad,fyes,dadocup,mom,myes,momocup,password) VALUES ('$_POST[regno]','$_POST[name]','$_POST[gender]','$_POST[date]','$_POST[month]','$_POST[year]','$_POST[emailid]','$_POST[cell]','$_POST[paddress]','$_POST[caddress]','$_POST[incometype]','$_POST[incomeamt]','$_POST[dad]','$_POST[fyes]','$_POST[dadocup]','$_POST[mom]','$_POST[myes]','$_POST[momocup]','$_POST[password]')"); $sql1=mysql_fetch_array($sql); $result = @mysql_query($SQl1); $result="SELECT * FROM users WHERE regno='$regno'"; while($row = mysql_fetch_array($result)) { //echo $row['regno']."regno<br>"; //echo $row['name']."name<br>"; //echo $row['gender']."gender<br>"; //echo $row['date']."date<br>"; //echo $row['month']."month<br>"; //echo $row['year']."year<br>"; //echo $row['emailid']."emailid<br>"; //echo $row['cell']."cell<br>"; //echo $row['paddress']."paddress<br>"; //echo $row['caddress']."caddress<br>"; //echo $row['incometype']."incometype<br>"; //echo $row['incomeamt']."incomeamt<br>"; //echo $row['dad']."dad<br>"; //echo $row['fyes']."fyes<br>"; //echo $row['dadocup']."dadocup<br>"; //echo $row['mom']."mom<br>"; //echo $row['myes']."myes<br>"; //echo $row['momocup']."momocup<br>"; //echo $row['password']."password<br>"; } echo "Thanks for Register!"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 record added"; mysql_close($con); ?> <form name="security" action="index.php" method="post"> <input type="submit" value="click here to login"> </form> </body> </html> Hi, I am new to the forums. I am having an issue with a snippet of code that generates random strings. I have already searched the forums, but the fix that I found is already in my code. I am still receiving the error though and was wondering if there was something else going on that I didn't see. Here is my code: Code: [Select] $Data = 'Ahmet'.md5(mt_rand(0, 123456789)); $length = 30; $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; $string = ''; $string2 = ''; for ($a = 0; $a < $length; $a++) { $pos = mt_rand(0, strlen($chars)-1); $string .= $chars{$pos}; $pos2 = mt_rand(0, (strlen($Data))-1); $string2 .= $chars{$pos2}; } I appreciate any help on this, as it is cluttering my system log table. Thanks. Code: [Select] <?php mysql_connect ("-","-","-") or die ('Error'); mysql_select_db ("-"); $out = mysql_query("SELECT * FROM guestbook ORDER BY id DESC"); while($row = mysql_fetch_assoc($out); --and this one if that braces is deleted { ----this is where im getting the error $name = $row['name']; $email = $row['email']; $txt = $row['comment']; $msg = "Are you sure you want to delete"; /* @var $_REQUEST <type> */ if (isset($_REQUEST ["action"]) && $_REQUEST["action"] == "del") { $id = intval($_REQUEST['id']); mysql_query("DELETE FROM guestbook WHERE id=$id;"); echo "<action=index.php>"; } echo "<font face='verdana' size='1'>"; echo "<table border='0'> <tr><td>Name: ".$name."</td></tr>"." <tr><td>Email: ".$email."</td></tr> <tr><td colspan='2'>Comment:</td></tr> <tr><td colspan='2' width='500'><b>".$txt."</b></td></tr> <tr><td><a onclick=\"return confirm('.$msg.');\" href='index.php?action=del&id=".$row['id']."'><span class='red'>["."Delete"."]</span></a> </td></tr> </table><br />"; echo "<hr size='1' width='500' align='left'></font>"; } ?> Kindly help me please. When i delete ({) the error will become the ( i dont know what to do already. Thanks. Hey guys, I am using this script to connect to mysql database. Here it is the code: <?php define('DB_HOST', 'localhost'); define('DB_USER', 'myusername'); define('DB_PASSWORD', 'mypassword'); define('DB_DATABASE', 'mydatabase'); session_start(); $errmsg_arr = array(); $errflag = false; $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } function clean($str) { $str = @trim($str); if(get_magic_quotes_gpc()) { $str = stripslashes($str); } return mysql_real_escape_string($str); } $login = clean($_GET['login']); $password = clean($_GET['password']); if($login == '') { $errmsg_arr[] = 'Login ID missing'; $errflag = true; } if($password == '') { $errmsg_arr[] = 'PS ID missing'; $errflag = true; } if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; session_write_close(); echo "ERROR"; exit(); } $qry="SELECT level FROM users WHERE login='$login' AND passwd='$password'"; if($result) { $result=mysql_query($qry); echo $result; exit(); }else { die("Query failed"); } ?> However, I have received an error which I catch from this line: echo "ERROR"; I have input the correct username, password and the name of the database. Do you have any idea why I have received an error, guess if I have missing something? Hi, I've uploaded my website to the server and I'm getting this error:- Code: [Select] Parse error: syntax error, unexpected T_VARIABLE in /home/c/h/chichesterag/public_html/Connections/gary.php on line 9 This is the first 9 lines of code:- Code: [Select] <?php session_start(); ?> <?php require_once('Connections/gary.php'); ?> <?php ini_set ("display_errors", "1"); error_reporting(E_ALL); $gary = mysql_connect("localhost", "root") or die("Error connecting to database<br /><br />".mysql_error()); mysql_select_db("people") or die("Error selecting database<br /><br />".mysql_error()); This is my connecting code:- Code: [Select] <?php # FileName="Connection_php_mysql.htm" # Type="MYSQL" # HTTP="true" $hostname_gary = "localhost"; $database_gary = "chichesterag"; $username_gary = "chichesterag"; $password_gary = "xxxxxx"; $gary = mysql_pconnect($hostname_localhost, $username_chichesterag, $password_xxxxxx) or trigger_error(mysql_error(),E_USER_ERROR); ?> The server's owner doesn't know what the problem is so I'm hoping someone here can help. Thanks, Gary I have this script that is supposed to upload a csv file to a mysql database but I am getting the following error: Successfully uploaded. sending Data...The used command is not allowed with this MySQL version ERROR, could not add the CSV data to your database. Any help would be much appreciated. Thanks! Here is the code: <?php // error_reporting(E_ALL); include_once "config.inc"; $php_self = $_SERVER['PHP_SELF']; $file_open = 0; $page = "<center> <div align='center' style='border: 1px solid #000000; background-color: #000000;padding: 5px; color: #071bfd; width: 550px; font-family: verdana, arial, sans-serif;' > <table align='center' style='border: 1px solid #eff7c2; background-color: #e2feea;padding: 10px; color: #071bfd;' cellspacing=5><tbody> <tr><td style='background-color: #000000;padding: 5px'><u><b><h3><font color='#ffffff'><center>AGTC - CSV Upload Script v1.0a ©2006</center></font></h3></u></b></td></tr> <tr><td><span style=\"font-family: arial, sans-serif;\"><i><b>Instructions on use:</b></i> <br /> Before using this script please read the <a href='README.html'>README.html</a> file to check you have installed it correctly.<br /> Please make sure you are trying to upload a TXT or CSV file only with the extension .txt or .csv at the end of the file name. <br /> Do not exceed the maximum upload size of 2mb.<br /> You can create your files using MS-Excel or similar CSV creator.<br /><br /></td></tr> <tr><td style='background-color: #000000;padding: 5px'> <form enctype='multipart/form-data' action='$php_self' method='post' onSubmit='Alert()'> <input type='hidden' name='MAX_FILE_SIZE' value='2000000' /> <input type='hidden' name='option' value='yes' /> <font color='#ffffff' size='-1'>Locate CSV File: <br /></font><input name='csvfile' type='file' size='70' /> <br /> <center><input type='submit' value='Upload CSV File' /> </td></tr></tbody></table></div></center>"; if(!isset($_POST['option'])){ echo $page; } elseif($_POST['option'] == "yes"){ $uploaddir = './uploads/'; $uploadfile = $uploaddir . $_FILES['csvfile']['name']; if (move_uploaded_file($_FILES['csvfile']['tmp_name'], $uploadfile)) { print "<font face='arial'>Successfully uploaded. "; $notice = 1; chmod($uploadfile, 0777); } else { print "<font face='arial'>ERROR: Upload Failed. "; $notice = 0; } $notice = 1; if ($notice == 1) { echo "\n sending Data..."; flush(); echo "</font>"; if (file_exists($uploadfile)) { $fp = fopen($uploadfile, 'r') or die (" Cannot open the file"); $fileopen = 1; $length = calculate_length($uploadfile); } $replace = "REPLACE"; $field_terminater = ","; $enclose_option = 1; $enclosed = '"'; $escaped = '\\\\'; $line_terminator = 1; $local_option = 1; $sql_query = 'LOAD DATA'; if ($local_option == "1") { $sql_query .= ' LOCAL'; } $sql_query .= ' INFILE \'' . $uploadfile . '\''; if (!empty($replace)) { $sql_query .= ' ' . $replace; } $sql_query .= ' INTO TABLE ' . "`csv_test`"; if (isset($field_terminater)) { $sql_query .= ' FIELDS TERMINATED BY \'' . $field_terminater . '\''; } if (isset($enclose_option) && strlen($enclose_option) > 0) { $sql_query .= ' OPTIONALLY'; } if (strlen($enclosed) > 0) { $sql_query .= ' ENCLOSED BY \'' . $enclosed . '\''; } if (strlen($escaped) > 0) { $sql_query .= ' ESCAPED BY \'' . $escaped . '\''; } if (strlen($line_terminator) > 0){ $sql_query .= ' LINES TERMINATED BY \'' . '\n' . '\''; } $result = mysql_query ($sql_query); echo mysql_error() ; if(mysql_affected_rows() > 1) { echo " <div align=left><b><font color='#071bfd' face='arial'>The CSV data has been added to your database.<br><br> <a href='javascript:history.back()'><<< Return to CSV Upload Script</a></font></div> "; } else { error_log(mysql_error()); echo " <div align=left><b><font color='#e42127' face='arial' > ERROR, could not add the CSV data to your database.</font></div>"; } if ($file_open ==1) { fclose($fp) or die("ERROR: Could not close the file"); } } } function calculate_length($fp) { $length = 1000; $array = file($fp); for($i=0;$i<count($array);$i++) { if ($length < strlen($array[$i])) { $length = strlen($array[$i]); } } unset($array); return $length; } ?> <script language="Javascript"> function Alert() { var question = alert("Confirm this is a CSV file no more than 2mb in size!"); return question; } </script> |