PHP - Another Mysql Insert Problem? Error Included This Time.
Code: [Select]
$date = date('m-d-y'); $ip = $_SERVER['REMOTE_ADDR']; mysql_query("INSERT INTO users VALUES ($username, $password, 0, $ip, $date)") or die(mysql_error()); Error: 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 '.60.116, 03-06-11)' at line 1 I'm not sure why I get this error. :/ Similar TutorialsSo, I feel like I am running up against some beginner's problem. So I am hoping this should be an easy fix. I have had a bit of trouble finding the right search terms to find a fix for this, so I am sorry ahead of time if there is already a post on this, please point me towards it. I am running PHP 4.4.9 and MySQL client API 4.1.22, in case that is of use. I can get the following to work and provide the appropriate output. Note in this first case that the connection info is in the same file as the call to it. <?php // set database access information define ('DB_USER', "*****"); define ('DB_PASSWORD', "*****"); define ('DB_HOST', "localhost"); define ('DB_NAME', "content"); // database connection protocol $dbc = mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) or die ('Could not connect to MySQL: Error #' . mysql_errno() . ' - ' . mysql_error()); mysql_select_db (DB_NAME) or die ('Could not connect to MySQL: Error #' . mysql_errno() . ' - ' . mysql_error()); $query = "SELECT content_element_title FROM content_main"; $result = mysql_query ($query); while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) { echo ("<p>" . $row[content_element_title] . "</p>"); } unset($dbc); ?> My problem is, however, that when I separate the connection info into a separate file, I have been having problems. I think I got past the method calling the connection info not being able to see it, but now it isn't returning anything - should be returning "<p>" . $row[content_element_title] . "</p>", for which there are three rows in the db. Here is what the two files look like separated: kinnect.php <?php // set database access information define ('DB_USER', '*****'); define ('DB_PASSWORD', '*****'); define ('DB_HOST', 'localhost'); define ('DB_NAME', 'content'); //// database connection protocol $dbc = mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) or die ('Could not connect to MySQL: Error #' . mysql_errno() . ' - ' . mysql_error()); mysql_select_db (DB_NAME, $dbc) or die ('Could not connect to MySQL: Error #' . mysql_errno() . ' - ' . mysql_error()); ?> file.php <?php require_once ("correctpathto/kinnect.php"); $query = "SELECT content_element_title FROM content_main"; $result = mysql_query ($query, $dbc); while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) { echo ("<p>" . $row[content_element_title] . "</p>"); } unset($dbc); ?> So what am I doing wrong? I am getting these error messages now. Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /Users/max/Sites/rdbase-llc/preliminary/connecttroubleshoot.php on line 18 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /Users/max/Sites/rdbase-llc/preliminary/connecttroubleshoot.php on line 20 Thanks ahead of time for any help! What needs to be changed to make this work... Code: [Select] // Build query. $q2 = "UPDATE member SET logged_in=?, last_activity=time(), updated_on=NOW() WHERE id=? LIMIT 1"; Apparently PHP doesn't like time() Debbie Can you guys tell me where is the error please...
$sql2= ('CREATE TABLE `'.$pub_unik.'` (ID SERIAL,ID_Use CHAR(30),Comment TEXT,Like INT,Score CHAR(30))');I can't find... Thank you guys I have a Form on registration.html through which i trying to get data in mysql through the below php script but there is and mysql syntax error please help me with the below code. Code: [Select] <?php $conn = mysql_connect("localhost", "onlinewe_meghraj", "password123") or die(mysql_error()); $db = mysql_select_db("onlinewe_college") or die(mysql_error()); $name1 = $_POST['name1']; $name2 = $_POST['name2']; $year = $_POST['year']; $department = $_POST['deparment']; $group = $_POST['group']; $in_name = $_POST['in_name']; $in_address = $_POST['in_address']; $phone = $_POST['phone']; $email = $_POST['email']; $mobile1 = $_POST['mobile1']; $mobile12 = $_POST['mobile2']; $comment = $_POST['comment']; $result=mysql_query("INSERT INTO register (name1, name2, year, department, group, in_name, in_address, phone, email, mobile1, mobile2, date, comment) VALUES ('$name1', '$name2', '$year', '$department', '$group', '$in_name', '$in_address', '$phone', '$email', '$mobile1', '$mobile2', '".date("Y-m-d h:i:s")."', '$comment')") or die("Insert Error: ".mysql_error()); echo "REGISTRATION DONE"; ?> Please reply. Thank you. Hi. I think you all know me by now so I'll cut to the chase. Code: [Select] <?php $host="edited"; $username="edited"; $password="edited"; $db_name="edited"; $tbl_name="topic"; // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $name=$_POST['name']; $detail=$_POST['details']; $sql="INSERT INTO $tbl_name(topic, detail, datetime)VALUES('$name', '$detail', NOW())"; $result=mysql_query($sql); if($result){ header("location:site.html");} else{ echo("I have failed you master.");} ?> Displayed error: "I have failed you master." Anyone know a possible cause? Thanks. Bye. Hey guys, this is my first post here(not going to be the last one, Im sure), im trying to insert in mysql from session array, i don't know where is my error, I leave the code below, if someone can help me please . I can't find the error, someone help me please.
$conn = mysql_connect("localhost","root","Pass"); $err_db = mysql_select_db('bd_amics'); $sql = ("INSERT INTO `'".$_SESSION["use"][14]."'` (ID,Amic,PubID) VALUES ('".$_SESSION["person"][14]."', "1", '".$_SESSION["person"][15]."')"); mysql_query("SET NAMES utf8"); mysql_query($sql, $conn); mysql_close(); $conn3 = mysql_connect("localhost","root","Pass"); $err_db3 = mysql_select_db('bd_amics'); $sql3 = ("UPDATE `'".$_SESSION["person"][14]."'` SET Amic="2" WHERE ID='".$_SESSION["use"][14]); mysql_query("SET NAMES utf8"); mysql_query($sql3, $conn3); mysql_close(); This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=342913.0 I get a "No database selected" error whenever I submit information on my register.php page, which is: <?php include_once('includes/config.php'); include_once('functions.php'); $return_content = AccountRelated(null, null, 3); ?> <html> <head> <link rel="stylesheet" type="text/css" href="style/style.css" /> <title><?php echo $title; ?></title> </head> <body> <div class="logo"><a href="index.php"><img src="style/images/logo.png" border="0"></a></div> <center> <div class="background"> <div class="container"> <?php echo $return_content; ?> </div> </div> </center> </body> </html> But after I click submit, I get the "No database selected" error, but using WAMP, I include config.php which holds the following details: <?php $title = "NovaUpload - File Uploader"; mysql_connect("localhost", "", ""); mysql_select_db("data"); ?> And if functions.php is required, he <?php function AccountRelated($username, $password, $query_type) { if($query_type == 1) { $set_query = mysql_query("SELECT COUNT(d.username), u.date, u.username FROM uploads d, users u WHERE d.username = '$username' AND u.username = '$username' LIMIT 1") or die(mysql_error()); //user must not exist if(mysql_num_rows($set_query) == 0) { $content_return = 'Sorry, no information was found'; } else { $grab = mysql_fetch_assoc($set_query); //login information if($grab['COUNT(d.username)'] > 0) { $welcome_return = "You have uploaded ". $grab['COUNT(d.username)'] ." files. You've registered on ". $grab['u.date'] ."!"; } else { $welcome_return = "You have uploaded 0 files. You've registered on ".$grab['date'] . "!"; } } } elseif($query_type == 2) { $set_query = mysql_query("SELECT title,views,downloads,description,username,date FROM uploads LIMIT 20"); if(mysql_num_rows($set_query) == 0) { $content_return = "Sorry, there are currently no files uploaded to view."; } else { //display all files while($row = mysql_fetch_assoc($set_query) == 0) { echo $row['title']."<br/>"; } } } elseif($query_type == 3) { $username = mysql_real_escape_string($_POST['username']); $password = sha1(sha1(md5($_POST['password']))); if(!$username || !$password) { $return_content = "All fields are required! <table><form action='register.php' method='POST'> <tr><td>Username</td><td><input type='text' name='username' maxlength='20'></td></tr> <tr><td>Password</td><td><input type='text' name='password' maxlength='30'</td></tr> <tr><td><input type='submit' value='Register'></td></tr> </form></table>"; } else { $set_query = mysql_query("SELECT username FROM users WHERE username = '$username' LIMIT 1"); if(mysql_num_rows($set_query) == 0) { $return_content = "You have successfully registered the account ". $username ." with the password ". $_POST['password'] ."!"; mysql_query("INSERT INTO users VALUES (null, '$username', '$password', 0, 0, '". date("M-d-Y") ."', '". $_SERVER['REMOTE_ADDR'] ."')") or die(mysql_error()); } else { $return_content = "An account with this username already exists."; } } return $return_content; } else { //nothing to process } } ?> Hey guys for some reason this code is not working i can't see a problem myself could someone please have a look and point the issue out to me. what i mean by it not working is it won't insert into the database or show a mysql_error. thanks in advance Code: [Select] $guestip = $_SERVER['REMOTE_ADDR']; $time = date('G:i'); $date = date("y-m-d"); $query = mysql_query("SELECT * FROM IP_Address") or die(mysql_error()); while($row = mysql_fetch_assoc($query)){ if($guestip != $row['ip']){ //insert into db. mysql_query("INSERT INTO IP_Address(id, ip, date, time) VALUES(NULL,'$questip','$date','$time')") or die(mysql_error()); echo "inserted in to database"; echo mysql_error(); }else{ // add hit count and update time and date. echo "already in db"; } } I have an old site written for PHP 5.4 and under and trying (very trying) to get it to work with PHP 7x without much luck. Due to all the changes in 7 my code is one big error message, but one thing at a time. I cannot get the follow code to work at all, even though it worked in PHP 5. Error:
QUERY ERROR: 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 'viewuser.php?u=666' id='member'>THE PREDATOR [666] was added to the hit' at line 1 I have tried at least 20+ different ways of doing this but just can't get the right syntax to get it inserted into MySQL, the code below is just the latest version. If I echo the a href line out, it works perfect. I am sure it is something ridiculously simple, but I have been 4 hours and counting on this now. Thanks gangevent_add_2($gangdata['gangID'], "<a href='viewuser.php?u=".$r['userid']."' ".$csscode[$r['userlevel']-1].">".$r['username']."</a> [".$r['userid']."] was added to your hitlist"); function gangevent_add_2($gang, $text) { global $db; $csscode; $db->query("UPDATE users SET gangevent = gangevent + 1 WHERE gang={$gang}"); $db->query("INSERT INTO gangevents VALUES('','$gang', UNIX_TIMESTAMP(),'$text')"); }
I have problem with this code. It does absolutely nothing. When INSERT is over it should redirect to index.php but it does nothing. There is no error, when the submit is clicked the page just refresh itself and because of echo function it write all the values. What seems to be the problem (I going slightly mad ) Code: [Select] <?php require_once("public/includes/session.php"); ?> <?php require_once("public/includes/connection.php"); ?> <?php require_once("public/includes/functions.php"); ?> <?php include_once("public/includes/form_functions.php"); include_once("public/includes/header.php"); if (isset($_POST['submit'])) { // Form has been submitted. $errors = array(); $required_fields = array('nik', 'lozinka', 'ime', 'prezime', 'adresa', 'grad', 'postanskiBroj', 'fiskni', 'moblini', 'email'); $errors = array_merge($errors, check_required_fields($required_fields, $_POST)); $username = trim(mysql_prep($_POST['nik'])); $password = trim(mysql_prep($_POST['lozinka'])); $hashed_password = sha1($password); $ime = trim(mysql_prep($_POST['ime'])); $prezime = trim(mysql_prep($_POST['prezime'])); $adresa = trim(mysql_prep($_POST['adresa'])); $grad = trim(mysql_prep($_POST['grad'])); $postanskiBroj = trim(mysql_prep($_POST['postanskiBroj'])); $fiskni = trim(mysql_prep($_POST['fiksni'])); $moblini = trim(mysql_prep($_POST['mobilni'])); $email = trim(mysql_prep($_POST['email'])); echo $username . $hashed_password . $ime . $prezime . $adresa . $grad . $postanskiBroj . $fiskni . $moblini . $email; if ( empty($errors) ) { $query = " INSERT INTO `gume`.`korisnik` (`id`, `korisnicko_ime`, `lozinka`, `ime`, `prezime`, `adresa`, `grad`, `postanskiBroj`, `fiksni_telefon`, `mobilni_telefon`, `email`) VALUES (NULL, '$username', '$hashed_password', '$ime', '$prezime', '$adresa', '$grad', '$postanskiBroj', '$fiskni, $moblini', '$email' )"; $result = mysql_query($query, $connection) or die(mysql_error); if ($result) { redirect_to("index.php"); } else { $message = "The user could not be created."; $message .= "<br />" . mysql_error(); } } else { if (count($errors) == 1) { $message = "There was 1 error in the form."; } else { $message = "There were " . count($errors) . " errors in the form."; } } } else { // Form has not been submitted. $username = ""; $password = ""; } ?> <div id="telo"> <div id="kreiranjeNaloga"> <script src="SpryAssets/SpryValidationTextField.js" type="text/javascript"></script> <link href="SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" /> <script src="SpryAssets/SpryValidationPassword.js" type="text/javascript"></script> <script src="SpryAssets/SpryValidationConfirm.js" type="text/javascript"></script> <link href="SpryAssets/SpryValidationPassword.css" rel="stylesheet" type="text/css" /> <link href="SpryAssets/SpryValidationConfirm.css" rel="stylesheet" type="text/css" /> <p>Polja sa * su obavezna</p> <form action="new_user.php" method="post"> <span id="sprytextfield1"> <label>Korisnicko ime: </label> <input type="text" name="nik" id="nik" size="40" value=""/> *<span class="textfieldMinCharsMsg">Korisnicko ime ne moze imati manje od 5 karaktera</span><span class="textfieldMaxCharsMsg">Korisnicko ime moze imati najvise 30 karaktera.</span></span><br /> <span id="sprypassword1"> <label>Lozinka:</label> <input type="password" name="lozinka" id="lozinka" size="40" value=""/> *<span class="passwordMinCharsMsg">Sifra mora sadrzati najmanje 5 karaktera.</span><span class="passwordMaxCharsMsg">Sifra moze imati najvise 30 karaktera.</span></span> <br /> <span id="spryconfirm1"> <label>Potvrdite lozinku:</label> <input type="password" name="password1" id="password1" size="40" value=""/> <span class="confirmRequiredMsg">*</span>Obe lozinke moraju da budu iste.</span> <br /> <span id="sprytextfield2"> <label>Ime:</label> <input type="text" name="ime" id="ime" size="40" value=""/> * </span> <br /> <span id="sprytextfield3"> <label>Prezima</label> <input type="text" name="prezime" id="prezime"size="40" value="" /> *</span> <br /> <span id="sprytextfield4"> <label>Adresa:</label> <input type="text" name="adresa" id="adresa" size="40" value=""/> * </span> <br /> <span id="sprytextfield7"> <label>Grad:</label> <input type="text" name="grad" id="grad" size="40" value="" /> * </span> <br /> </span><span id="sprytextfield9"> <label>Postanski Broj: </label> <input type="text" name="postanskiBroj" id="postanskiBroj" size="10" value=""/> * <span class="textfieldInvalidFormatMsg">Postanski broj nije pravilno upisan.</span></span><br /> <span id="sprytextfield5"> <label>Broj fiksnog telefona: </label> <input type="text" name="fiksni" id="Broj fiksnog telefona" size="40" value="" /> *<span class="textfieldInvalidFormatMsg">Broj telefona nije pravilno upisan</span></span> <br /> <span id="sprytextfield6"> <label>Broj mobilnog telefona: </label> <input type="text" name="mobilni" id="mobilni" size="40" value="" /> *<span class="textfieldInvalidFormatMsg">Broj telefona nije pravilno upisan</span></span><br /> <span id="sprytextfield10"> <label>Email:</label> <input type="text" name="email" id="email" size="40" value="" /> *<span class="textfieldInvalidFormatMsg">Email adresa nija pravilno upisana.</span></span><br /> <input name="submit" type="submit" id="submit" value="Kreiraj korisnika" /> </form> </div> </div> <?php include("public/includes/footer.php"); ?> i have created my own code of custom shopping cart
i have viewcart.php working great, now when i want to insert the orders from viewcart.php with list of like 5 items, how can i insert 5 names of products into my database 1 row
example
names are
1. jean
2. mond
3. richard
4. gwen
list above is the results of my while loop, now i want to insert those names to my database column[order_productname] so that i can identity what products are paid by my clients.
i tried fetch_array but if i assign variable to fetch array result, it only shows 1 which is "jean"
i wish this is possible
dforth
Say I have... Code: [Select] <? echo("do something"); include("include_file.php"); echo("do something else"); ?> include_file.php Code: [Select] <? $a_$string = "a string"; echo($a_string); ?> I have put an error in the include_file.php an extra $ in the variable name. The first script would kick up an error that there is a problem with file include_file.php as line 3 or what ever the line may be. How can I have it so I can choose what the error message is, say a cryptic code and the line number without having the file names show as this is showing up my hidden includes folder and the file name which means that someone may try to visit this page alone and this can cause security issues. Adding in extra lines to every file to see if it is being use correctly a bit like sessions is not an option although I have looked at it as I have houndreds of files to alter in this case. I have just tried this instead of the top script but I does not show the secret code on error Code: [Select] <? echo("top"); @include("dummy.php") or die("secreterrorcode123"); echo("bottom"); ?> 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); } Can anyone tell me why this is not INSERTing? My array data is coming out just fine.. I've tried everything I can think of and cannot get anything to insert.. Ahhhh! <?php $query = "SELECT RegionID, City FROM geo_cities WHERE RegionID='135'"; $results = mysqli_query($cxn, $query); $row_cnt = mysqli_num_rows($results); echo $row_cnt . " Total Records in Query.<br /><br />"; if (mysqli_num_rows($results)) { while ($row = mysqli_fetch_array($results)) { $insert_city_query = "INSERT INTO all_illinois SET state_id=$row[RegionID], city_name=$row[City] WHERE id = null" or mysqli_error(); $insert = mysqli_query($cxn, $insert_city_query); if (!$insert) { echo "INSERT is NOT working!"; exit(); } echo $row['City'] . "<br />"; echo "<pre>"; echo print_r($row); echo "</pre>"; } //while ($rows = mysqli_fetch_array($results)) } //if (mysqli_num_rows($results)) else { echo "No results to get!"; } ?> Here is my all_illinois INSERT table structu CREATE TABLE IF NOT EXISTS `all_illinois` ( `state_id` varchar(255) NOT NULL, `city_name` varchar(255) NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1; Here is my source table geo_cities structu CREATE TABLE IF NOT EXISTS `1` ( `CityId` varchar(255) NOT NULL, `CountryID` varchar(255) NOT NULL, `RegionID` varchar(255) NOT NULL, `City` varchar(255) NOT NULL, `Latitude` varchar(255) NOT NULL, `Longitude` varchar(255) NOT NULL, `TimeZone` varchar(255) NOT NULL, `DmaId` varchar(255) NOT NULL, `Code` varchar(255) NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1; Hey! I have a small code where I want to check if one variable matches the other when the other is sent through a function. The function, for practical reasons, is included with a separate PHP-file. And I cant seem to apply a variable to the function which processes the other variable. Its really wierd to me. Here is the code for the main PHP-file: Code: [Select] <?php include 'function.php'; $unformatted = "FORMATTING AY ..."; $formatted1 = "formattingay..."; $formatted2 = test_format($unformatted); if ($formatted1 == $formatted2) { echo "Success, formatted!"; } else { echo "Fail, unformatted."; } ?> And here is the code for "function.php": Code: [Select] <?php function test_format($var) { strtolower(str_replace(array(" "), array(""), $var)); } ?> Does anybody have a clue to why this simply wont work? Any answers and help is highly appreciated! hi im trying to insert the username and time into the online table the trouble is nothing is getting inserted into the table no errors have echoed both variables to check they contain the right information and they do. Code: [Select] $time=time(); echo $time; echo $myusername; $insert_user=mysql_query("INSERT INTO cvisinko_db.online (username,time,) VALUES ('$myusername','$time')") ; then the plan is display a basic online list haven't been able to test this as nothing is getting inserted into the online table Code: [Select] $data = mysql_query("SELECT count(*) from cvisinko_db.online WHERE `time` >= DATE_SUB(NOW(), INTERVAL 30 minute);") or die(mysql_error()); Hi i need to count the number items in an album now on the album i have create a field called count which counts the number items in that album but now i dnt knw how to update those as soon insert a item in the table item so i thought woul be possible to create a script that when insert data into item tables also update album table row count by adding one like update count with A now A equal row count ++1 any help on start of it if possible???/ |