PHP - Coding Error
Hi can anyone please tell me what is wrong with this code? It is an index.php file. I think I might have accidentally deleted something somewhere between line 12 & 13? Please help my whole website is down because of it. I am not a programmer and I was trying to do a 301 redirect. It didn't work obviously, so I removed the script that I entered and saved the file again, but it is still not working.
Similar TutorialsI am trying to run the following code -------------------------- $result = mysql_query("SELECT * FROM indiatutors_profiles WHERE id='$id' ") or die(mysql_error()); while($row=mysql_fetch_array($result)){ $email =$row[email]; } echo $email; ---------------------------- It gives me the following error Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in website_path/profiles.php on line 7 The funny thing about the code is that inspite of giving the error, it outputs the email correctly based upon the id which it shouldn't have done if their was some error I am using X cart and I have tried add function that hide price until customers log in. so I added following codes to my files with notepad but I am keep getting smarty errors Error: Smarty error: [in customer/main/products_t.tpl line 161]: syntax error: 'if' statement requires arguments (Smarty_Compiler.class.php, line 1270) in /home1/lemielfa/public_html/include/lib/smarty/Smarty.class.php on line 1092 Here's Smarty.class.php line 1092 ------------------------------------------------------------------------------------------------------------------------------------- * @param string $error_msg * @param integer $error_type */ function trigger_error($error_msg, $error_type = E_USER_WARNING) { (line1092----->)trigger_error("Smarty error: $error_msg", $error_type); } /** * executes & displays the template results -------------------------------------------------------------------------------------------------------------------------------- This was my first time adding some code to my web, I hope I didn't screw up that much...... Thank You David ---------------------------------------------------------------------------------------- Following Code ADDED /b] 1. Apply following SQL statements either from your cart admin/patch area or myphpadmin. This will place 2 controls in General Settings / General options in Common options. The first one will allow you to turn this mod on/off Code: INSERT INTO `xcart_config` (`name`, `comment`, `value`, `category`, `orderby`, `type`, `defvalue`, `variants`, `validation`) VALUES ('cflsys_hide_prices', 'Hide prices for non-logged in customers (this will also hide quantity box, "buy now" and "add to cart" buttons)', 'N', 'General', 75, 'checkbox', 'N', '', ''); INSERT INTO `xcart_config` (`name`, `comment`, `value`, `category`, `orderby`, `type`, `defvalue`, `variants`, `validation`) VALUES ('cflsys_hide_prices_message', 'Show this optional message if the option "Hide prices" is enabled', 'You need to login in order to see prices and place orders.', 'General', 76, 'text', '', '', ''); 2. Add to init.php at the end of the file just before PHP Code: # # WARNING ! # Please ensure that you have no whitespaces / empty lines below this message. # Adding a whitespace or an empty line below this line will cause a PHP error. # this PHP Code: # added by CFL Systems for hide prices if customer not logged in $smarty->assign("cflsys_hide_prices",$config['General']['cflsys_hide_prices']); $smarty->assign("cflsys_hide_prices_message",$config['General']['cflsys_hide_prices_message']); # added by CFL Systems for hide prices if customer not logged in 3. In skin1/customer/main/products.tpl find Code: {if $config.Appearance.products_per_row && ($featured eq "Y" || $config.Appearance.featured_only_multicolumn eq "N")} {include file="customer/main/products_t.tpl"} {else} {include file="customer/main/products_list.tpl"} {/if}and before add Code: {* added by CFL Systems to hide prices if customer not logged in *} {if $login eq "" && $cflsys_hide_prices eq "Y"} {if $cflsys_hide_prices_message ne ""} <div style="color: red; margin: 5px 0; padding: 5px 5px 5px 10px; border: 1px solid #cccccc;">{$cflsys_hide_prices_message}</div> {/if} {/if} {* added by CFL Systems to hide prices if customer not logged in *} 4. In skin1/customer/main/product.tpl (skin1/customer/main/product_details.tpl for 4.3.x, code may be slightly different) find this Code: <tr> <td class="property-name product-price">{$lng.lbl_price}:</td> <td class="property-value"> and before add Code: {* added by CFL Systems to hide prices if customer not logged in *} {if $login eq "" && $cflsys_hide_prices eq "Y"} $nbsp; {else} {* added by CFL Systems to hide prices if customer not logged in *} then find Code: {if $product.forsale ne "B"} <tr> <td colspan="2"> {include file="customer/main/product_prices.tpl"} </td> </tr> {/if}and after add Code: {* added by CFL Systems to hide prices if customer not logged in *} {if} {* added by CFL Systems to hide prices if customer not logged in *} then find Code: <tr> <td class="property-name product-input"> {$lng.lbl_quantity}and before add Code: {* added by CFL Systems to hide prices if customer not logged in *} {if $login eq "" && $cflsys_hide_prices eq "Y"} <tr> <td colspan="2"> {if $cflsys_hide_prices_message ne ""} {$cflsys_hide_prices_message} {else} {/if} </td> </tr> {else} {* added by CFL Systems to hide prices if customer not logged in *}then find Code: {/if} </table> and before add Code: {* added by CFL Systems to hide prices if customer not logged in *} {if} {* added by CFL Systems to hide prices if customer not logged in *}then find Code: {if $product.appearance.buy_now_buttons_enabled}and before add Code: {* added by CFL Systems to hide prices if customer not logged in *} {if $login eq "" && $cflsys_hide_prices eq "Y"} $nbsp; {else} {* added by CFL Systems to hide prices if customer not logged in *}then find Code: </form>and before add Code: {* added by CFL Systems to hide prices if customer not logged in *} {if} {* added by CFL Systems to hide prices if customer not logged in *} 5. In skin1/customer/main/products_list.tpl find Code: {if $product.product_type eq "C"} {include file="customer/buttons/details.tpl" href=$url} {else}and after add Code: {* added by CFL Systems to hide prices if customer not logged in *} {if $login eq "" && $cflsys_hide_prices eq "Y"} $nbsp; {else} {* added by CFL Systems to hide prices if customer not logged in *} then find Code: {/if} </div> <div class="clearing"></div>and before add Code: {* added by CFL Systems to hide prices if customer not logged in *} {if} {* added by CFL Systems to hide prices if customer not logged in *} 6. In skin1/customer/main/products_t.tpl find Code: <tr> {foreach from=$row item=product} {if $product} <td class="product-cell product-cell-price"> {if $product.product_type ne "C"} {if $active_modules.Subscriptions ne "" && $product.catalogprice} and before add Code: {if $login eq "" && $cflsys_hide_prices eq "Y"} <tr> <td colspan="2"> </td> </tr> {else} {* added by CFL Systems to hide prices if customer not logged in *}then find at the end of the file Code: {/foreach} </table> {/if}and before add Code: {* added by CFL Systems to hide prices if customer not logged in *} {if} {* added by CFL Systems to hide prices if customer not logged in *} Could someone tell what's wrong here? $abc =sprintf("INSERT INTO my_db1 (username, password, firstname, company, email) VALUES ('%s', '%s', '%s', '%s', '%s'", mysql_real_escape_string($username), mysql_real_escape_string($password, mysql_real_escape_string($surname, mysql_real_escape_string($firstname, mysql_real_escape_string($company, mysql_real_escape_string($email))); $resultg = mysql_query($abc); Thanks! form2.php Code: [Select] <?php session_start(); if (empty($_SESSION['is_logged_in'])) { header("Location:chatframe.php"); die(); // just to make sure no scripts execute } ?> <?php mysql_connect("localhost","root") or die(mysql_error()); mysql_select_db("cute") or die(mysql_error()); $message=$_POST['message']; $a=$_SESSION['username']; if(isset($_POST['submit'])) //if submit button push has been detected { if(strlen($message)>1) { $message=strip_tags($message); $IP=$_SERVER["REMOTE_ADDR"]; //grabs poster's IP $checkforbanned="SELECT IP from ipbans where IP='$IP'"; $checkforbanned2=mysql_query($checkforbanned) or die("Could not check for banned IPS"); if(mysql_num_rows($checkforbanned2)>0) //IP is in the banned list { print "You IP is banned from posting."; } else { $thedate = date("U"); //grab date and time of the post $insertmessage="INSERT into chatmessages (name,IP,postime,message) values('$a','$IP','$thedate','$message')"; mysql_query($insertmessage) or die("Could not insert message"); } $a="window.location.replace('chatlog2.php')",2000); echo "<html> <head> <script> setTimeout($a); var objDiv = document.body; objDiv.scrollTop = objDiv.scrollHeight; </script> </head> </html>"; } } ?> <html> <head> <script type="text/javascript"> function addsmiley(code) { var pretext = document.smile.message.value; this.code = code; document.smile.message.value = pretext + code; } function a() { var x = document.smile.message.value; if(x=="") { alert("Please insert an message!"); return false; } } </script> <style type="text/css"> body{ background-color: #d8da3d } </style> </head> <body> <center> <form name="smile" method="post" action="form2.php" onSubmit="return a()" > Your message:                          <a style="text-decoration:none" <a href="javascript: void(0)" onclick="window.open('banip.php', 'windowname2', 'width=400, \ height=150, \ directories=no, \ location=no, \ menubar=no, \ resizable=no, \ scrollbars=1, \ status=no, \ toolbar=no'); return false;">Action</a>            <a style="text-decoration:none" href="logout.php">Sign Out</a><br><textarea name='message' cols='40' rows='2'></textarea><br> <img src="smile.gif" alt=":)" onClick="addsmiley(':)')" style="cursor:pointer;border:0" /> <img src="blush.gif" alt=":)" onClick="addsmiley('*blush*')" style="cursor:pointer;border:0" />                                                             <input type='submit' name='submit' value='Send' class='biasa' ></form> <br> <br> </center> </body> </html> which is wrong and can you please modified it ? This topic has been realloc()d to PHP Freelancing. http://www.phpfreaks.com/forums/index.php?topic=345803.0 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> 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. Hi guys,
I am needing some help of how to place the coding as I can not get it to work.
--
Basically I am building a website for the local motorclub and want some code that will "add up" each persons results.
Here is what I have come up with but it does not work;
<?php $total = mysql_fetch_array("SELECT cat1 + cat2 + cat3 + cat4 + cat5 + cat6 AS total FROM results") ?> <?php $cautotest_results = mysql_query("SELECT * FROM results WHERE cat ='1' ORDER BY cattotal DESC"); if(mysql_num_rows($cautotest_results) == '') { echo "<p>No Results Available."; } else { echo "<table width=\"800\" border=\"0\" cellpadding=\"2\" cellspacing=\"2\" class=\"greywritinglight\" align=\"center\"> <tr align=\"center\"> <td>Competitor</td> <td>Vehicle</td> <td>Class</td> <td>Skipton</td> <td>Weston</td> <td>King Bros</td> <td>Normans</td> <td>Norwood</td> <td>Uniroyal</td> <td>Total</td> </tr>"; $x=1; while($results_row = mysql_fetch_array($cautotest_results)) { if($x%2): $rowbgcolor = "#FFFFFF"; else: $rowbgcolor = "#EEEEEE"; endif; echo "<tr align=\"center\" bgcolor=\"" .$rowbgcolor. "\">"; echo "<td>" . $results_row['competitor'] . "</td>"; echo "<td>" . $results_row['catvehicle'] . "</td>"; echo "<td>" . $results_row['catclass'] . "</td>"; echo "<td>" . $results_row['cat1'] . "</td>"; echo "<td>" . $results_row['cat2'] . "</td>"; echo "<td>" . $results_row['cat3'] . "</td>"; echo "<td>" . $results_row['cat4'] . "</td>"; echo "<td>" . $results_row['cat5'] . "</td>"; echo "<td>" . $results_row['cat6'] . "</td>"; echo "<td>" . $total . "</td>"; echo "</tr>"; $x++; } echo "</table>"; } ?>Its the top line of coding... and the echo .total. at the bottom. If you could please correct me I would be ever so grateful. If you need more info please just ask. All help is appreciated. JTM. Edited by JTM, 17 August 2014 - 12:45 AM. Hi,
I need to change 'Products with stock >60' to 'there are no products that have more than 60 in stock' in php script. I am not sure how to do the coding to change this in php script. If someone could help me within the next hour or two that would be amazing. thank you
I have 4 files like attached.... if i clicked on index.php content-1 link... that open templet.php and body load with content-1.txt please helpme Hi I need some help. I have a page which will show all the result based on the user sign in. And it will show something like this ID | Event Start Date | Event End Date | Event Details 1 19-11-2011 20-11-2011 View Event Details The view event details is a link so when I click on the link, it will link me to the next page (eventDetails.php?id=1) And at eventDetails.php?id=1 page, it would requires user to input whether they will be attending or not and will they be bringing their friend along then submit the form. When I submit, how do I pass all the data from eventDetails.php?id=1 page to confirmation.php page (after submitting)? You might want to refer to the attached coding. All the 2 php pages are working fine but when submit to confirmation.php page, the data are not post over so I didn't attach the confirmation.php page. Thanks Ben Chew [attachment deleted by admin] <?php
$Title=$_POST['title']; why it gives "insertion failed" as a result?
Is there a way i can make a php code for making a lesson then upload to my made system? Im newbie here. so basically, i need to make an e-learning system that lets the user make a lesson then upload it so that other user can view their made lesson.. Someone help me pls. I have a small mp3 script and its running accurately ...i want to check the mp3 URL before playing it whether the mp3 link active or broken ....how to check the link is active or broken in php thanks Im making an E-learning system that when Student registers the Teacher will approve.. So i've got here a code that outputs all those who registered via Checkbox. Code: [Select] <form name="formapprove" method="POST" action="valval3.php" > <div id="apDiv12"><input type="image" src="images/Approve.png" name="approve" value="approve" width="170" height="35" border="0" > </div> <div id="apDiv11"> <input type="image" src="images/reject.png" name="reject" width="170" height="35" border="0" value="reject"> </div> <div id="apDiv14">'; $host="localhost"; $username="root"; $password=""; $db_name="dbreg"; $tbl_name="account"; mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM $tbl_name"; $result=mysql_query($sql); echo "<table border=\"5\" width=\"400\" >"; echo "<tr><th>List of Student to be approve</th>"; if(mysql_num_rows($result)) { while($row = mysql_fetch_assoc($result)) { echo "<tr><td>"; echo "<input type='checkbox' name='list[]' value='".$row['Username']."'>".$row['famname'].",".$row['gname']. ",".$row['mname']. ".<br/></td>"; echo "</tr></input>"; } } else { echo "<tr><td align=\"center\"> No Student to be Approve / Reject </td></tr>"; } echo' </form> Then the file "valval3.php" will be the one that will save the variables in my database.. Code: [Select] <?php session_start(); if(isset($_SESSION['uname2']) || ($_SESSION['section'])){ $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } if(isset($_POST['approve_x'], $_POST['approve_y'])) { mysql_select_db("dbreg", $con); $uname = $_SESSION['uname2']; $sec = $_SESSION['section']; $sql="SELECT * FROM account where sec='$sec'"; $result=mysql_query($sql); if(mysql_num_rows($result)) { while($row = mysql_fetch_assoc($result)) { $fullname = "" .$row['famname']. ", " .$row['gname']. " " .$row['mname']. "."; } foreach ($_POST['list'] as $checkbox) { $sql="SELECT * FROM account WHERE sec='$sec'"; } $result=mysql_query($sql); if(mysql_num_rows($result)) { while($row = mysql_fetch_assoc($result)) { $username = $row['Username']; $password = $row['Password']; $gname = $row['gname']; $mname = $row['mname']; $famname = $row['famname']; $sec = $row['sec']; $studnum = $row['studnum']; $fullname = "" .$row['famname']. ", " .$row['gname']. " " .$row['mname']. "."; $username = stripslashes($username); $password = stripslashes($password); $username = mysql_real_escape_string($username); $password = mysql_real_escape_string($password); $gname = stripslashes($gname); $famname = stripslashes($famname); $gname = mysql_real_escape_string($gname); $famname = mysql_real_escape_string($famname); $mname = stripslashes($mname); $mname = mysql_real_escape_string($mname); foreach ($_POST['list'] as $checkbox) { mysql_query("INSERT INTO dbaccount (Username, Password, gname, famname, mname, sec, studnum, fullname) VALUES ('$username', '$password', '$gname', '$famname', '$mname', '$sec', '$studnum', '$checkbox')") or die(mysql_error); mysql_query("DELETE FROM account WHERE sec='$sec'") or die(mysql_error); } echo '<script type="text/javascript"> {alert("Approved!");} </script>'; echo '<meta http-equiv="REFRESH" content="0;url=approvereject2.php">'; mysql_close($con); } } else { echo '<meta http-equiv="REFRESH" content="0;url=approvereject2.php">'; } }elseif(isset($_POST['reject_x'], $_POST['reject'])) { mysql_select_db("dbreg", $con); foreach ($_POST['list'] as $checkbox) { $sql="SELECT * FROM account WHERE sec='$sec'"; } $result=mysql_query($sql); if(mysql_num_rows($result)) { foreach ($_POST['list'] as $checkbox) { mysql_query("DELETE FROM account WHERE sec='$sec'") or die(mysql_error); } echo '<script type="text/javascript"> {alert("Rejected!");} </script>'; echo '<meta http-equiv="REFRESH" content="0;url=approvereject2.php">'; } else { echo '<meta http-equiv="REFRESH" content="0;url=approvereject2.php">'; } } else { echo '<meta http-equiv="REFRESH" content="0;url=approvereject2.php">'; } } } else { header("location:failunautho.php");; } ?> I tested my codes. Its only working if theres only 1 user registered ( which means one checkbox would appear in page) But when i tested to have 3 users registered and not yet approve, There would be an error saying.. Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\Documents and Settings\Ken\Desktop\xampplite\htdocs\Pages\valval3.php on line 49 Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in C:\Documents and Settings\Ken\Desktop\xampplite\htdocs\Pages\valval3.php on line 49 $username = mysql_real_escape_string($username); <-- line #49 Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\Documents and Settings\Ken\Desktop\xampplite\htdocs\Pages\valval3.php on line 50 Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in C:\Documents and Settings\Ken\Desktop\xampplite\htdocs\Pages\valval3.php on line 50 $password = mysql_real_escape_string($password); <-line #50 Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\Documents and Settings\Ken\Desktop\xampplite\htdocs\Pages\valval3.php on line 54 Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in C:\Documents and Settings\Ken\Desktop\xampplite\htdocs\Pages\valval3.php on line 54 Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\Documents and Settings\Ken\Desktop\xampplite\htdocs\Pages\valval3.php on line 55 Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in C:\Documents and Settings\Ken\Desktop\xampplite\htdocs\Pages\valval3.php on line 55 $gname = mysql_real_escape_string($gname); <-line #54 $famname = mysql_real_escape_string($famname); <-line# 55 Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\Documents and Settings\Ken\Desktop\xampplite\htdocs\Pages\valval3.php on line 58 Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in C:\Documents and Settings\Ken\Desktop\xampplite\htdocs\Pages\valval3.php on line 58 mname = mysql_real_escape_string($mname); <-line #58 Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\Documents and Settings\Ken\Desktop\xampplite\htdocs\Pages\valval3.php on line 64 Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in C:\Documents and Settings\Ken\Desktop\xampplite\htdocs\Pages\valval3.php on line 64 mysql_error VALUES ('$username', '$password', '$gname', '$famname', '$mname', '$sec', '$studnum', '$checkbox')") or die(mysql_error) <-line #64 Then still it saves 3 variables.. but all the same. Hope Someone could help me .. I have a sql statement w/c suppose to output only those records w/c has a name of seller. But, it keeps showing all the records. Code: [Select] <?php session_start(); if(isset($_SESSION['name']) || ($_SESSION['contact']) || ($_SESSION['address']) ) { ini_set('display_errors', 0); $name = $_SESSION['name']; $contact = $_SESSION['contact']; $address = $_SESSION['address']; ?> <div id="apDiv1"> <?php echo "Name : $name"; echo "</br>"; echo "Name : $contact"; echo "</br>"; echo "Name : $address"; ?> <div id="apDiv2"> <?php $host="localhost"; $username="root"; $password=""; $db_name="feedbackdb"; mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM Feedbacks WHERE Seller = $name"; $result=mysql_query($sql); echo "<table border=\"5\" width=\"600\" >"; echo "<tr><th>Feedbacks</th><th>From</th><th> To </th>"; if(mysql_num_rows($result)) { while($row = mysql_fetch_assoc($result)) { echo "<tr><td>"; echo "" .$row['Feedback']."<br></td>"; echo "<td>".$row['From']."<br></td>"; echo "<td>".$row['Seller']."<br></td>"; echo "</tr>"; } } else { echo "<tr><td align=\"center\"> No Feedback</td></tr>"; } ?></div> </div> <?php } else { header("location:loginpage.php");; } ?> Hi All I am fairly new to the PHP world so please excuse my ignorance. (I am trying!) Basically I bought a commercially available PHP script and created my own script to work alongside the bought one. What happened then is that the developers of the script I bought released a new version of the software. My script no longer works and is throwing up the following error PHP Fatal error: Using $this when not in object context in C:\wamp\www\classifieds\system\core\System.php on line 175 I've worked out that the script fails on this line, in the new version of the software. $dbhost = System::getSystemSettings('DBHOST'); On review of the commercial script's coding, I noticed that where the old version used the syntax above, the new version uses a syntax as shown below $this->appContext->getSystemSettings('DBHOST'); So I went and modified my script (mismatched.php) to read as follows $dbhost = $this->appContext->getSystemSettings('DBHOST'); But im now getting the following errors PHP Parse error: syntax error, unexpected T_REQUIRE_ONCE, expecting T_FUNCTION in C:\wamp\www\classifieds\admin\mismatched.php on line 5 I'd appreciate any ideas you may have that could help me get my script (mismatched.php) working again. Thanks again Ali Hello guys it's me again. I have not posted a question in awhile so I am glad to be on PHPFreaks again. Anyways here is my question, I have simple "Filter By" or "Refine By" script I am developing. It's foundation is primarily database (MySQL) and does not use XML or other table files. This script simply add's filtered array ("objects") to the url as the customer filters his/her search. An example, $attributeCodes("processor_type","color","memory"); // These arrays are defined and built from the database on the time of the request. So they are automatically updated. The above array is used in an if/and/or statement to look for these attribute codes. If it finds it and it has a value it then refines the MySQL query to look for products with the said attribute code. Now that we have the basics out there of how it works I am at the part where it confuses me. I give the user the ability to filter his/her search, however I want the user to be able to remove these filters separately if wanted. So for example the customer filters, Domain.com/search/productsearch.php?catId=112&processor_type=AMD&memory=2gb The customer does not need the memory filter and wishes to remove that specific item or vice-verse he/she does not want to search by processor_type. How is it that I can remove specifically one attribute and its value from the URL? So the url will then look like, Domain.com/search/productsearch.php?catID=112&processor_type=AMD or Domain.com/search/productsearch.php?catID=112&memory=2gb Any help would be great. Or if you have any suggestions on a different method to filter by attributes products. Suggestions and criticism are welcome. Please do not be shy or modest when it comes to giving me advice as I am trying to learn efficiently. - Travis |