PHP - Resolve Array Error W/out Error Suppression Operatior @
My script IS working, but I can't get around a blank array error when no errors exist.
Below is my code, and as you can see, I am being handed this: Notice: Undefined variable: error in C:\wamp\www\php\form_validation.php on line 19 as a result of my ... if (is_array($error)) { ... .. I could do if (@is_array($error)) { (note the @), but I hate using that thing... I've tried several things with no luck, so any ideas welcome at this point. <?php if (isset($_POST['set_test'])) { if (!preg_match("/^[A-Za-z' -]{1,50}$/", $_POST['first_name'])) { $error[] = "Please enter a valid First Name"; } if (!preg_match("/^[A-Za-z' -]{1,50}$/", $_POST['last_name'])) { $error[] = "Please enter a valid Last Name"; } if (is_array($error)) { foreach ($error as $err_message) { echo $err_message . "<br />"; } } } ?> Similar TutorialsHi, 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 In the given code below I am getting this error Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\samples\getcustomers.php on line 20 WHY? Code: [Select] <?php $value = $_GET["q"]; $con = mysql_connect('localhost', 'root', ''); //db_connect(); if (!$con) { die('Could not connect: ' . mysql_error()); } $db_selected = mysql_select_db("ajaxDb",$con); $sql = "SELECT * FROM 'cutomers' WHERE Name = '".$value."'"; // echo $sql; $result = mysql_query($sql); echo "<table border='1'> <tr> <th>Name</th> <th>Address</th> <th>Country</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['Name'] . "</td>"; echo "<td>" . $row['Address'] . "</td>"; echo "<td>" . $row['Country'] . "</td>"; echo "</tr>"; } echo "</table>"; mysql_close($con); ?> 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. Im getting the following error on this line: Code: [Select] Fatal error: Cannot use string offset as an array Code: [Select] $array['headers_style'] = 'color:'.$color['headers_text']['text'].'; background-color:'.$color['headers']['background'].';'; This error only occurs on one page, others that use this line dont have a problem. So i tried to delete parts of the code from the page causing the error but it still exists. So i deleted a huge peice of the code and the error vanished. So i eliminated portions of the huge code 1 at a time but the error stays until i delete all of the code. Anyone know why this page doesnt like the error? i could post the code but its a huge chunk(around 600 lines) I've been thinking of using an assoc_array for validation code in php to have an associative of all the fields (name, email, message) and to see if there has been an "ERROR" declared in any of them? How would I first declare this array? and How would I check to see if they are empty or any of them contain "ERROR". Thanks i keep getting this error when there is no array. Warning: array_values() [function.array-values]: The argument should be an array in /home/learnat2/public_html/cart.php on line 37 but i put this code to prevent the error Code: [Select] $items = $_SESSION['items']; if(is_array($items)) { $quantity = array_count_values($items); $items = array_unique($items); } i still get the error. it should not display an error because $items is not an array, no values have been added. SOLVED Hi guys this one page is giving me a headache. i posted earlier today with a question on how to insert multiple records and got given a quick demo of how to do it so ive gone away to look more and ive edited my code. however it still doesnt work. im wondering if ive coded a tiny bit wrong. id be really appreciative if you guys could help me out Code: [Select] <?php include 'dbc.php'; page_protect(); company(); $stafflist = mysql_query("SELECT * FROM StaffList WHERE full_name != 'Adam Carter' AND full_name != 'Jakata' AND branch = '$_SESSION[branch]' "); $id = $_POST['id']; if (isset($_POST['submit'])) { //Assign each array to a variable $id = $_POST['id']; $user_name = $_POST['user_name']; $Serviceamount = $Serviceamount['item']; $limit = count($id); echo $limit; $values = array(); // initialize an empty array to hold the values for($k=0;$k<$limit;$k++){ $user_name[$k] = check_input($user_name[$k]); $Serviceamount[$k] = check_input($Serviceamount[$k]); $values[$k] = "( '{$id[$k]}', '{$Serviceamount[$k]}')"; // build the array of values for the query string } $query = "INSERT INTO `Services` (Staffname, ServiceAmount) VALUES " . implode( ', ', $values ); // Form the query string and add the implod()ed values if (!mysql_query($query,$link)){ die('Error: ' . mysql_error()); } else { echo "$row record added"; } echo $values; } if (checkAdmin()) { ?> <html> <head> <title>Book Off Holiday</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script src="php_calendar/scripts.js" type="text/javascript"></script> <link href="styles.css" rel="stylesheet" type="text/css"> </head> <body> <form name="form" action="Newkpi.php" method="post"> <table width="100%" border="0" cellspacing="0" cellpadding="5" class="main"> <tr> <td colspan="3"> </td> </tr> <td width="160" valign="top"> <?php if (isset($_SESSION['user_id'])) { } ?> <a href="admin.php">Admin CP </a> </td> <td width="732" valign="top"> <p> <h3 class="titlehdr">New KPI</h3> <table width="300px" border="0" align="Centre" cellpadding="2" cellspacing="0"> <tr bgcolor="#000050"> <td width="20px"><h3 class="Text2">Staff ID</h3></td> <td width="20px"><h3 class="Text2">Staff Member</h3></td> <td width="20px"><h3 class="Text2">Service Amount</h3></td> <td width="20px"><h3 class="Text2">Service Date</h3></td> <td width="20px"><h3 class="Text2">Forecast For Next Month</h3></td> <td width="20px"><h3 class="Text2">Product Sales</h3></td> <td width="20px"><h3 class="Text2">Clients This Month</h3></td> <td width="20px"><h3 class="Text2">Personel Retension</h3></td> <td width="20px"><h3 class="Text2">Total Retension</h3></td> <td width="20px"><h3 class="Text2">Colours</h3></td> <td width="20px"><h3 class="Text2">Cuts</h3></td> <td width="20px"><h3 class="Text2">Pre-Booking</h3></td> <td width="20px"><h3 class="Text2">Time Used</h3></td> </tr> <?php while ($rrows = mysql_fetch_array($stafflist)) {?> <tr> <td><h3 class="Text3"><input type="" name="id[]" id="id[]" size="4" value="<?php echo $rrows['id'];?>" /></h3></td> <td><h3 class="Text3"><input type="" name="user_name[]" id="user_name[]" value="<?php echo $rrows['full_name'];?>" /></h3></td> <td><h3 class="Text3"><input name="Serviceamount" type="text" size="4" id="Serviceamount"></h3></td> <td><h3 class="Text3"><input name="servicedate" type="text" size="4" id="servicedate"></h3></td> <td><h3 class="Text3"><input name="forecast" type="text" size="4" id="forecast"></h3></td> <td><h3 class="Text3"><input name="productsales" type="text" size="4" id="productsales"></h3></td> <td><h3 class="Text3"><input name="Clientsthismonth" type="text" size="4" id="Clientsthismonth"></h3></td> <td><h3 class="Text3"><input name="Personelret" type="text" size="4" id="Personelret"></h3></td> <td><h3 class="Text3"><input name="Totalret" type="text" size="4" id="Totalret"></h3></td> <td><h3 class="Text3"><input name="colours" type="text" size="4" id="colours"></h3></td> <td><h3 class="Text3"><input name="cuts" type="text" size="4" id="cuts"></h3></td> <td><h3 class="Text3"><input name="prebooking" type="text" size="4" id="prebooking"></h3></td> <td><h3 class="Text3"><input name="timeused" type="text" size="4" id="timeused"></h3></td> </tr> <?php } ?> </table> <input name="submit" type="submit" id="submit" value="Create"> </table> </form> </body> </html> <?php } ?> thank you in advance $BoxSize = array("smallbox" = array("length" => 12, "width" => 10, "depth" => 2.5), "mediumbox" = array("length" => 30, "width" => 20, "depth" => 4), "largebox" = array("length" => 60, "width" => 40, "depth" => 11.5)); I'm getting this error, but I'm not sure how to fix it (on my Wordpress site). Warning: usort() [function.usort]: The argument should be an array in /home2/lushwebs/public_html/4mulaevents/wp-content/themes/dailyedition/includes/talking-points.php on line 20 Warning: Invalid argument supplied for foreach() in /home2/lushwebs/public_html/4mulaevents/wp-content/themes/dailyedition/includes/talking-points.php on line 22 Any help appreciated. Thanks! Hello I have the following code Code: [Select] <?php // STORE DATABASE VARIABLES $hostname_cnConnection = "localhost"; $database_cnConnection = "tekou"; $username_cnConnection = "root"; $password_cnConnection = "1234"; $cnConnection = mysql_pconnect($hostname_cnConnection, $username_cnConnection, $password_cnConnection); mysql_set_charset('utf8',$cnConnection); // CONNECT TO DATABASE mysql_select_db($database_cnConnection, $cnConnection); $data = mysql_query("SELECT * from jos_users") or die(mysql_error()); // Print "<table border cellpadding=3>"; while($info = mysql_fetch_array( $data )) { // echo $info['id']; $prod_id=$info['id'] ; // echo "Product ID " .$prod_id; //Show Product Id mysql_query("UPDATE jos_vm_user_info SET first_name = '".$info['name']." WHERE user_id = ".$info['id']) or die(mysql_error()); } echo $info['id']; ?> I want to read every $name and update in jos_vm_user_info the first_name but I think I have error in code because nothing happens. I quess that .$info['id'] doesnt return a single number but all numbers but I dont know how to fix it. Please someone to help me. Hi all,
I have a looping error in my PHP.
I am trying to add use a while statement to gather the users first and last name in to a string, add them to an array called $friendname, then check that the $friendname[] is only output/echoed once.
At the moment the code looks good to me but with multiple rows with the same name associated, the name is echoed the same amount of times as rows, instead of once as it is supposed to be.
Any ideas anyone?
while($row2 = mysqli_fetch_assoc($result2)) { $friendcode = $row2['Code']; $names = "SELECT FirstName, LastName from users WHERE Code = '$friendcode' AND Code != '$crewcode'"; $resultnames = mysqli_query($cxn,$names) or die ("Can't get friends names."); while($rownames = mysqli_fetch_assoc($resultnames)) { $friendname = array(); $newfriendname = ($rownames['FirstName'].' '.$rownames['LastName']); if (!in_array($newfriendname, $friendname)) { array_push($friendname, "$newfriendname"); echo $newfriendname; } } } Hi guys, I am pretty new to php and mysql, so please don't only tell me what to do without showing me. Would be very appreciated. Thanks in advance!! Here is what I am trying to do. I am trying to use php to print the fields a table in Mysql into a form page called index.php. I think I sucessfully did it, but not the best way (mixing php and html, because I couldn't figure it out how to do it seperately) Everything looks good, except when I press submit and now we go to the insert_stats.php where the error: Warning: Invalid argument supplied for foreach() in /insert_stats.php on line 8 insert_stats.php Code: [Select] <? include("sql.php"); $paddler = $_POST['paddler'] ; $practice = $_POST['practice'] ; $header = $_POST['header'] ; [b]foreach ($header as $value) [/b] { $insert="INSERT INTO pushup ($header) VALUES ('$value')"; mysql_query($insert) OR die(mysql_error()) ; } $insert2="INSERT INTO pushup (paddler_id , practice_id) VALUES ('$paddler' , '$practice')"; mysql_query($insert2) OR die(mysql_error()) ; mysql_close(); ?> index.php Code: [Select] <table width="250" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC"> <tr> <form id="pushup" name="pushup" method="post" action="insert_stats.php"> <td> <table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF"> <tr> <td colspan="3" bgcolor="#E6E6E6"><strong>IDENTIFICATION</strong> </td> </tr> <tr> <td width="80%">Paddler ID</td> <td width="2%">:</td> <td width="18%"><input name="paddler" type="text" id="paddler" size="1" /></td> </tr> <tr> <td>Practice #</td> <td>:</td> <td><input name="practice" type="text" id="practice" size="1" /></td> </tr> <tr> <td colspan="3" bgcolor="#E6E6E6"><strong>ADD FITNESS STATS</strong> </td> </tr> <? include("sql.php"); $result = mysql_query("SELECT * FROM pushup"); $printed_headers = false; while ( $row = mysql_fetch_array($result) ) { if ( !$printed_headers ) { //print the headers once: echo "<tr>"; foreach ( array_keys($row) AS $header ) { if($header == 'paddler_id' || $header == 'practice_id' || $header == 'p_id') continue; if ( !is_int($header) ) { echo "<td>$header</td><td>:</td><td><input name='".$header."' type=\"text\" id='".$header."' size=\"1\" /></td></tr>"; } } $printed_headers = true; } } mysql_free_result($result); mysql_close(); ?> <tr> <td><input type="reset" name="Submit2" value="Reset" /></td> <td> </td> <td><input type="submit" name="Submit" value="Submit" /></td> </table> </td> </form> </tr> </table> database.php
________________________________________________________________________________________
$res = pg_query ($conn, "SELECT artist, composer, genre, title, album, label, price, description FROM music");
echo "<table border='1'>"; while($a = pg_fetch_array($res)){ echo "<td>" . $a['1'] . "</td>"; echo "<td>" . $a['2'] . "</td>"; echo "<td>" . $a['3'] . "</td>"; echo "<td>" . $a['4'] . "</td>"; echo "<td>" . $a['5'] . "</td>"; echo "<td>" . $a['6'] . "</td>"; echo "<td>" . $a['7'] . "</td>"; echo '<td><input type="checkbox" name="music[]" value="$ref"' . $row['0'] . $row['1'] . $row['2'] . $row['3'] . $row['4'] . $row['5'] . $row['6'] . $row['7'] . '"/></td>'; echo"</tr>"; } echo "</table>\n"; ?> _____________________________________________________________________________- shoppingbasket.php _____________________________________________________________________________- <form action="shoppingbasket.php" method="POST"> Send To Basket: <name="music"> <input type="submit" value="submit"> </form> cant get it to send data from database to this page shoppingbasket.php I have an array ($other_images) that contains image file names separated by semi colons. I can successfully echo the individual values using echo $other_images[0], $other_images[1], $other_images[2]... When I put it in a for loop, though, I run into the followng error: Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in... Here is my code: <?php $other_images = explode(";", $data['ItemAltImage']); for($i=0; $i<count($other_images); $i++) { echo "<p><img src='http:\\www.oppictures.com\SINGLEIMAGES\100\" . $other_images[$i] . "' /></p>"; } ?> This is the result of print_r($other_images): Array ( => UNV21200_3_2.JPG [1] => UNV21200_2_2.JPG [2] => UNV21200_4_1.JPG [3] => UNV21200_8_1.JPG [4] => UNV21200_5_1.JPG [5] => UNV21200_6_1.JPG [6] => UNV21200_7_1.JPG [7] => UNV21200_9_1.JPG ) Do you see where I'm making a mistake? Thanks |