PHP - Php Error Help Needed
hello I keep getting these errors:
Warning: mysql_query() expects parameter 2 to be resource, string given in C:\xampp\htdocs\PHP & JQUERY\WEBSITE\index.php on line 17
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, null given in C:\xampp\htdocs\PHP & JQUERY\WEBSITE\index.php on line 19 This is the code I am using: $conn = mysql_connect("localhost", "root"); $q = "SELECT * FROM users"; Similar Tutorialshey there, i have created a guestlist that is linked to a database for people to add some details and submit it off. The problem i am having is confusing because the server connects to the database fine but after 5 or so entries it goes to my echo comment which is "unbale to insert record" just after 5 entries and or if i use a different computer......it will be much appreciated if someone could help me this thankyou heres my code: ****************************************************************** <?php # FileName="conn_db.php" $hostname= "********"; $database= "*********"; $user = "********"; $pass ="********"; $mysql_link=mysql_connect($hostname,$user,$pass) or die("unable to connnect to the server"); mysql_select_db($database) or die ("unable to select the database"); ?> **************************************************************** <?php $first_name=$_POST['first_name']; $last_name=$_POST['last_name']; $phone=$_POST['phone']; $email=$_POST['email']; $guests=$_POST['guests']; if (($first_name == "") or ($last_name == "") or ($email == "") or ($guests == "")) { echo"<p>Required Field (s) missing....!!!! Go Back and Try Again...!!!</p>"; } elseif (!(strstr($email, "@")) or !(strstr($email, "."))) { echo"<p>Invalid Email....!!!! Go Back and Try Again...!!!</p>"; } else { //Connect to the server and add a new record require_once('conn_db.php'); $query = mysql_query("SELECT COUNT(*) as pcount FROM cust")or die(mysql_error()); $row= mysql_fetch_assoc($query); //echo 'current count:'.$row['pcount']; // if ($row['pcount'] >120) { echo "guest list is full"; } else { $query = "INSERT INTO cust Values ('$first_name', '$last_name', '$phone', '$email', '$guests')"; mysql_query($query) or die ("unable to insert the record"); mysql_close(); echo "<p><b>Record Addedd Successfully.....!!!!</p>"; echo"<p> <a href=../html/thankyou.html>Click Here to Return to the Guests Page</a></b></p>"; $message = "Thankyou for registering with us\ Your deatils a \nName: $_POST[first_name] \nEmail: $_POST[email] /nPhone: $_POST[phone] \nguests: $_POST[guests]\n"; mail ($email, "Website Email", $message); } } ?> Hi, I had a chat script lying around but wanted to add a login form in case the mxitid wasn't found in the database so I made a few changes to the script to check for records in databases and retrieving the username according the mxit ID. but after I made few changes im getting syntax errors can someone maybe tell me where I made mistakes please.
<?php // database connection info $conn = mysql_connect('*******','********','*******') or trigger_error("SQL", E_USER_ERROR); $db = mysql_select_db('************',$conn) or trigger_error("SQL", E_USER_ERROR); $query0 = mysql_query("SELECT username FROM Users WHERE mxitid=$mid", $con); $result = mysql_query($query0); $myrows = mysql_fetch_array($result); if (mysql_num_rows($query0) != 0) { echo "define('TIMEZONE', 'Africa/Harare'); date_default_timezone_set(TIMEZONE); echo "<html><br> <span style="color:red"><b><u>Chat Beta: Errors may apply please send feedback with contact us regarding problems!</u></b></span> </html>"; // find out how many rows are in the table $sql = "SELECT COUNT(*) FROM StringyChat"; $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); $r = mysql_fetch_row($result); $numrows = $r[0]; // number of rows to show per page $rowsperpage = 20; // find out total pages $totalpages = ceil($numrows / $rowsperpage); // get the current page or set a default if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) { // cast var as int $currentpage = (int) $_GET['currentpage']; } else { // default page num $currentpage = 1; } // end if // if current page is greater than total pages... if ($currentpage > $totalpages) { // set current page to last page $currentpage = $totalpages; } // end if // if current page is less than first page... if ($currentpage < 1) { // set current page to first page $currentpage = 1; } // end if // the offset of the list, based on current page $offset = ($currentpage - 1) * $rowsperpage; /* * StringyChat * * Please refer to readme.txt supplied with the StringyChat distribution for information on * installing and configuring. * */ define('TIMEZONE', 'Africa/Harare'); date_default_timezone_set(TIMEZONE); include("chat_code_header.php"); $result = mysql_query("SELECT * FROM ".$ConfigTable, $db); $myrow = mysql_fetch_array($result); $domain_installed = $myrow["domain_installed"]; // The domain StringyChat is installed on $install_url = $myrow["install_url"]; // URL to install dir of StringyChat $name_size = $myrow["name_size"]; // Maximum size of the name $message_size = $myrow["message_size"]; // Maximum message size. Do not exceed 250 as this is the database limit. $line_length = $myrow["line_length"]; // Maximum length of words in a line. Anything above this value will be split. $ShowPostNum = $myrow["show_posts"]; // The number of historic posts to load and display. $email_notification = $myrow["email_notification"]; // Send email to administrator when new posts are made. 0 = No, 1 = Yes $email_notification_to = $myrow["email_notification_to"]; // The email address to send notifications to if ($_SERVER['REQUEST_METHOD'] == "POST" && !empty($_POST['StringyChat_name'])) { $StringyChat_name = $_POST['StringyChat_name']; $StringyChat_message = $_POST['StringyChat_message']; } <div id="StringyChat"> // Check if visitor's IP is banned. If so, do not display the form, // show a banned IP message instead. $name = $myrows["Username"]; if(!isset($name)) { $name = "SYSOP"; } $ip = $_SERVER["REMOTE_ADDR"]; $sql = "SELECT * FROM StringyChat_IPBan WHERE ip=\"$ip\""; $result = mysql_query($sql); $myrow = mysql_fetch_array($result); if($myrow["ip"] == "") { // Checks if IP not found in banned list ?> <html><form name="StringyChat_form" method="POST" action="<? echo $_SERVER['REQUEST_URI']; ?>"> <input type="hidden" name="StringyChat_name" class="StringyChatFrm" value="<?php echo $name ?>" size="20"> <textarea name="StringyChat_message" class="StringyChatFrm" cols="20" rows="1"></textarea> <br> <input name="StringyChat_submit" class="StringyChatFrm" type="submit" value="Post Message"> </form> </html> <? } else { echo "Posting disabled - Your IP has been banned."; } // Should we try to create a post? if (isset($StringyChat_name) && isset($StringyChat_message)) { // Remove whitespaces and slashes. $name = trim(stripslashes($StringyChat_name)); $message = trim(stripslashes($StringyChat_message)); // Check name and message have been entered. if (strlen($name) > 0 && strlen($message) > 0) { // Limit the size of the fields as per variable defnitions. if (strlen($name) > $name_size) { $name = substr($name, 0, $name_size); } if (strlen($message) > $message_size) { $message = substr($message, 0, $message_size); } // Remove new lines from name. $name = str_replace("\n", " ", $name); // Stripping out \r's so email formattnig appears correctly. $message = str_replace("\r", "", $message); // Create an email-friendly version of the message. $message_emailable = str_replace("<br>", "\n", $message); $result_wordswap = mysql_query("SELECT * FROM ".$WordBanTable,$db); while ($myrow_wordswap = mysql_fetch_array($result_wordswap)) { $the_word = $myrow_wordswap["word"]; $message_emailable = ereg_replace($the_word, "!*#$%",$message_emailable); } // Replace the new lines with encoded line breaks for HTML (thanks milahu). $message = str_replace("\n", "c#lb", $message); // Use HTML encoding on ame and message so database doesn't misinterpret data. $name = htmlentities($name); $message = htmlentities($message, ENT_COMPAT); // IP address of submitter and time of post. $ip = $_SERVER["REMOTE_ADDR"]; $name = $_SERVER["HTTP_X_MXIT_NICK"]; $msg = $_POST['StringyChat_message']; $post_time = date("U"); $mxitid = $_SERVER["HTTP_X_MXIT_LOGIN"]; if(!isset($mxitid)) { $mxitid = "DEFAULT"; } if(!isset($name)) { $name = "SYSOP"; } // check to see if a duplicate exists $sql = "SELECT * FROM StringyChat WHERE StringyChat_ip=\"$ip\" AND StringyChat_message=\"$msg\" AND StringyChat_time>($post_time - 1800 )"; $result = mysql_query($sql); $myrow = mysql_fetch_array($result); if($myrow["StringyChat_message"] == "") { // Checks if record not matching in db // Save the record $sql = "INSERT INTO StringyChat (StringyChat_ip,StringyChat_name,StringyChat_message,StringyChat_time) VALUES (\"$ip\",\"$name\",\"$msg\",$post_time)"; $result = mysql_query($sql); } else { echo "Duplicate post detected<br>"; } } else { echo "<font color=\"red\">You must Type a message</font><br><br>"; } unset($_POST["StringyChat_name"]); unset($_POST["StringyChat_message"]); unset($StringyChat_ip); unset($StringyChat_name); unset($StringyChat_message); unset($StringyChat_time); unset($mxit_id); } // get the info from the db $sql = "SELECT StringyChat_time, StringyChat_name, StringyChat_message FROM StringyChat ORDER BY id DESC LIMIT $offset, $rowsperpage"; $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); function filterBadWords($str) { $result1 = mysql_query("SELECT word FROM StringyChat_WordBan") or die(mysql_error()); $replacements = ":-x"; while($row = mysql_fetch_assoc($result1)) { $str = eregi_replace($row['word'], str_repeat(':-x', strlen($row['word'])), $str); } return $str; } // while there are rows to be fetched... while ($list = mysql_fetch_assoc($result)) //while (($pmsg = $list['StringyChat_message'] == $bwords) ? ":-x" : $list['StringyChat_message']) { // echo data //echo ($pmsg = ($list['StringyChat_message'] == $bwords) ? ":-x" : $list['StringyChat_message']) $admin = array('SYSOP','cobusbo'); if (in_array($list['StringyChat_name'], $admin)) { print '<span style="color:#828282">' . '(' . date( 'D H:i:s', $list['StringyChat_time'] ) . ') ' . '</span>' . '<span style="color:red">' . '<b>' . $list['StringyChat_name'] . '</b>' . ' : ' . filterBadWords($list['StringyChat_message']) . '</span>' . '<br />' . '<p>'; } else { print '<span style="color:#828282">' . '(' . date( 'D H:i:s', $list['StringyChat_time'] ) . ') ' . '</span>' . '<b>' . $list['StringyChat_name'] . '</b>' . ' : ' . filterBadWords($list['StringyChat_message']) . '<br />' . '<p>'; } } // Load up the last few posts. The number to load is defined by the "ShowPostNum" variable. $result = mysql_query("SELECT * FROM ".$dbTable." ORDER BY StringyChat_time DESC LIMIT " . $ShowPostNum,$db); include("sort_widths.php"); while ($myrow = mysql_fetch_array($result)) { $msg = $myrow["StringyChat_message"]; // Convert the encoded line break into an actual <br> tag (thanks milahu) $msg = str_replace("c#lb", "<br>", $msg); // Convert the encoded image tag into a html tag $msg = eregi_replace("im#([a-z]{3})", "<img src=\"http://".$install_url."images/\\1.gif\" alt=\"emoticon\">",$msg); // split the lines $msg = htmlwrap($msg, $line_length); $result_wordswap = mysql_query("SELECT * FROM ".$WordBanTable,$db); while ($myrow_wordswap = mysql_fetch_array($result_wordswap)) { $the_word = $myrow_wordswap["word"]; $msg = ereg_replace($the_word, ":-x",$msg); } } ?> <? // end while /****** build the pagination links ******/ // range of num links to show $range = 3; // if not on page 1, don't show back links if ($currentpage > 1) { // show << link to go back to page 1 echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> "; // get previous page num $prevpage = $currentpage - 1; // show < link to go back to 1 page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> "; } // end if // loop to show links to range of pages around current page for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) { // if it's a valid page number... if (($x > 0) && ($x <= $totalpages)) { // if we're on current page... if ($x == $currentpage) { // 'highlight' it but don't make a link echo " [<b>$x</b>] "; // if not current page... } else { // make it a link echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> "; } // end else } // end if } // end for // if not on last page, show forward and last page links if ($currentpage != $totalpages) { // get next page $nextpage = $currentpage + 1; // echo forward link for next page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> "; // echo forward link for lastpage echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> "; } // end if /****** end build pagination links ******/ ?><br> <html> <i>Type your Message here...</i>:<br></html> "; } else { <html> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="GET"> Username:<br> <input type="text" name="username" ><br> <input type="hidden" value="<?php echo $_SERVER['HTTP_X_MXIT_LOGIN']; ?>" name"userid" > <br><br> <input type="submit" value="Submit"> </form> </html> <? $usernames = $_GET['username']; $mid = $_GET['userid']; $sql0 = "INSERT INTO Users (username,mxitid) VALUES (\"$usernames\",\"$mid\")"; $result = mysql_query($sql0); ?> } I'm getting an error like : Fatal error: Declaration of Cog\YouTrack\Rest\Authenticator\CookieAuthenticator::authenticate (Cog\Contracts\YouTrack\Rest\Client\Client $client): Cog\YouTrack\Rest\Authenticator\void must be compatible with Cog\Contracts\YouTrack\Rest\Authenticator\Authenticator::authenticate (Cog\Contracts\YouTrack\Rest\Client\Client $client): Cog\Contracts\YouTrack\Rest\Authenticator\void in /var/www/html/vendor/cybercog/youtrack-rest-php/src/Authenticator/CookieAuthenticator.php on line 24 my index file is : require_once 'vendor/autoload.php'; use Cog\YouTrack\Rest; // use Cog\Contracts\YouTrack\Rest\Authenticator\Authenticator; // Application configuration (replace with your YouTrack server values) $apiBaseUri = 'http://111.111.111.111:8080'; $apiUsername = 'username'; $apiPassword = 'password'; // Instantiate PSR-7 HTTP Client $psrHttpClient = new \GuzzleHttp\Client([ 'base_uri' => $apiBaseUri, 'debug' => true, ]); // Instantiate YouTrack API HTTP Client $httpClient = new Rest\HttpClient\GuzzleHttpClient($psrHttpClient); // Instantiate YouTrack API Cookie Authenticator $authenticator = new Rest\Authenticator\CookieAuthenticator(); CookieAuthenticator.php file is : namespace Cog\YouTrack\Rest\Authenticator; use Cog\Contracts\YouTrack\Rest\Authenticator\Authenticator as AuthenticatorContract; use Cog\Contracts\YouTrack\Rest\Client\Client as ClientContract; /** * Class CookieAuthenticator. * * @package Cog\YouTrack\Rest\Authenticator */ class CookieAuthenticator implements AuthenticatorContract // <--line 24 where the error is { /** * @var string */ private $username = ''; /** * @var string */ private $password = ''; /** * @var string */ private $cookie = ''; /** * Determine is trying to authenticate. * * @var bool */ private $isAuthenticating = false; /** * CookieAuthenticator constructor. * * @param string $username * @param string $password */ public function __construct(string $username, string $password) { $this->username = $username; $this->password = $password; } /** * Authenticate client and returns cookie on success login. * * @param \Cog\Contracts\YouTrack\Rest\Client\Client $client * @return void * * @throws \Cog\Contracts\YouTrack\Rest\Authenticator\Exceptions\AuthenticationException */ public function authenticate(ClientContract $client): void { $client = new ClientContract; if ($this->cookie !== '' || $this->isAuthenticating) { return; } $this->isAuthenticating = true; $response = $client->request('POST', '/user/login', [ 'login' => $this->username, 'password' => $this->password, ]); $this->isAuthenticating = false; if ($response->isStatusCode(200)) { $this->cookie = $response->cookie(); } } /** * Retrieve authentication token. * * @return string */ public function token(): string { return $this->cookie; } } Why I'm getting this error? I think there is something wrong with CookieAuthanticator.php file but unfortunately I could not find it Edited May 24, 2019 by Rommeo Hello Freaks! I am having problem with following code: <?php simplexml_load_string ('?xml version="1.0" encoding="utf-8"?>'); php?> This code is giving me following error Parse error: syntax error, unexpected '<' in public_html/wp-content/plugins/pluginnamehere/whatever.php on line 665 I know there is only a minor bracket problem that causing me this error. I would be helpful to you if you can modify it for me Thanks 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. $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 have been trying to get my files to upload onto a computer and I receive this message: Parse error: syntax error, unexpected T_STRING in /home/content/19/6550319/html/listing.php on line 27. Line 27 is how the php logs into my SQL. The problem is that I was able to log in before. I just made changes to the form by adding a dropdown menu and price and now it says it doesnt parse. Can anyone figure this out. I will include the code without the login information because the forum is public but I did put the words left out for you to see where I took out the passcodes. Code: [Select] <?php //This is the directory where images will be saved $target = "potofiles/"; $target = $target . basename( $_FILES['photo']['name']); //This gets all the other information from the form $price=$_POST['price']; $gig=$_POST['giga']; $yesg=$_POST['yesg']; $pic=($_FILES['photo']['name']); $pic2=($_FILES['phototwo']['name']); $pic3=($_FILES['photothree']['name']); $pic4=($_FILES['photofour']['name']); $description=$_POST['iPadDescription']; $condition=$_POST['condition']; $fname=$_POST['firstName']; $lname=$_POST['lastName']; $email=$_POST['email'] // Connects to your Database mysql_connect ("left out", "left out", "left out") or die(mysql_error()) ; mysql_select_db("left out") or die(mysql_error()) ; //Writes the information to the database mysql_query("INSERT INTO listing (price,giga,yesg,photo,phototwo,photothree,photofour,iPadDescription,condition,firstName,lastName,email) VALUES ('$price', '$gig', '$yesg', '$pic', '$pic2', '$pic3', '$pic4', '$description', '$condition', '$fname', '$lname', '$email')") ; //Writes the photo to the server if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) { //Tells you if its all ok echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory"; } else { //Gives and error if its not echo "Sorry, there was a problem uploading your file."; } echo date("m/d/y : H:i:s", time()) ?>
Hello everyone,
1 <?php
7 // Create connection
10 // Check connection
14 $firstname = $conn->real_escape_string($_REQUEST['firstname']); 25 $sql2 = "INSERT INTO countries VALUES ('$country')"; 27 $sql3 = "INSERT INTO Contacts (firstname, lastname, address, city, country, phone, email) VALUES ('$firstname', '$lastname', '$address', $city, $country, '$phone_number','$email')";
29 SELECT * FROM cities;
if($conn->query($sql2) === true){
if($conn->query($sql3) === true){ I don`t get it, waht is wrong?! Code: [Select] <?php require_once 'auth.php'; if (!isset($_SESSION['SESS_VERIFY'])) { header("location: access-denied.php"); exit(); } if ($_SESSION['lang'] == 'Ro') { // setare data romania date_default_timezone_set('Europe/Bucharest'); $today = getdate(); $zi = $today['mday']; $luna = $today['mon']; $lunastring = $today['month']; $an = $today['year']; $data = $zi.$luna.$an; $data = (string)$data; $ora = date('H:i:s'); $msg = array(); $err = array(); $luni = array ( 1=>'Ianuarie', 2=>'Februarie', 3=>'Martie', 4=>'Aprilie', 5=>'Mai', 6=>'Iunie', 7=>'Iulie', 8=>'August', 9=>'Septembrie', 10=>'Octobrie', 11=>'Noiembrie', 12=>'Decembrie'); // comun const SQL_ERR = 'SQL statement failed with error: '; const ADD_MODEL = 'ADAUGA UN MODEL NOU'; . .many constants.. . } elseif ($_SESSION['lang'] == 'It') {... Thank you! Hello , I have a made a PHP website where users signup and send their Date of Birth and gets an OTP on their email after signup. The OTP is recieved but when we enter the OTP this problem occurs QuoteError! Something went wrong and I am facing this error in the error log QuotePHP Fatal error: Uncaught Error: Object of class DateTime could not be converted to string This is my config.php code <?php session_start(); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Confirmation Page - Kanha Stories</title> <style> body { background-color: #330000; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100%25' height='100%25' viewBox='0 0 800 400'%3E%3Cdefs%3E%3CradialGradient id='a' cx='396' cy='281' r='514' gradientUnits='userSpaceOnUse'%3E%3Cstop offset='0' stop-color='%23D18'/%3E%3Cstop offset='1' stop-color='%23330000'/%3E%3C/radialGradient%3E%3ClinearGradient id='b' gradientUnits='userSpaceOnUse' x1='400' y1='148' x2='400' y2='333'%3E%3Cstop offset='0' stop-color='%23FA3' stop-opacity='0'/%3E%3Cstop offset='1' stop-color='%23FA3' stop-opacity='0.5'/%3E%3C/linearGradient%3E%3C/defs%3E%3Crect fill='url(%23a)' width='800' height='400'/%3E%3Cg fill-opacity='0.4'%3E%3Ccircle fill='url(%23b)' cx='267.5' cy='61' r='300'/%3E%3Ccircle fill='url(%23b)' cx='532.5' cy='61' r='300'/%3E%3Ccircle fill='url(%23b)' cx='400' cy='30' r='300'/%3E%3C/g%3E%3C/svg%3E"); background-attachment: fixed; background-size: cover; padding: 20px; width: 100vw; height: 100vh; display: flex; align-items: center; justify-content: center; color:#ffffff; overflow-x: hidden; } .cont { padding: 20px 40px; position: relative; border-right: 4px solid rgb(184, 182, 182); border-bottom: 4px solid rgb(184, 182, 182); border-radius: 15px; display: flex; flex-direction: column; align-items: center; } #left{ float: left; } #right{ float: right; } input{ margin: 10px 0px; } s{ padding: 5px; } .error{ padding: 5px; color: #ffffff; } .resend{ color: rgb(14, 14, 196); padding: 5px; } .s:hover{ cursor: pointer; background-color:gray; color: rgb(243, 237, 237); border-radius: 5px; } </style> </head> <body> <?php $code=""; $err=""; $error=""; if(($_SERVER["REQUEST_METHOD"]=="GET" && $_SESSION['xyz'] === 'xyz') || isset($_POST['verify']) || isset($_POST['resend'])) { unset($_SESSION["xyz"]); if($_SERVER["REQUEST_METHOD"] ==="POST") { if(isset($_POST['verify'])) { if(empty($_POST['code'])) { $err="Enter the code!"; } else { $code=$_POST['code']; if(password_verify($code,$_SESSION['code'])) { $name=$_SESSION['name']; $email=$_SESSION['email']; $tel=$_SESSION['tel']; $dob=$_SESSION['dob']; $password=$_SESSION['password']; $age_category=$_SESSION['age_category']; require_once('./all_utils/connection.php'); $sql="INSERT INTO identity_table(name,email,password,tel,dob,age_category) VALUES ('$name','$email','".$password."','$tel','$dob','$age_category')"; if(mysqli_query($conn,$sql) === TRUE) { unset($_SESSION["name"]); unset($_SESSION["password"]); unset($_SESSION["dob"]); unset($_SESSION["tel"]); unset($_SESSION["age_category"]); header("location:welcome/welcome.php"); } else { $err="Error! Something went wrong"; } } else { $err="Incorrect code!"; } } } elseif(isset($_POST['resend'])) { require_once('./all_utils/mail.php'); $error="OTP has been sent again!"; } } } else{ header("location:signup.php"); } ?> <div class="cont"> <h2> Email Verification</h2> <form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']) ?>" method="POST"> <label for="verification">Enter the 5 digit code</label> <br/> <p> Didn't got the mail? Please check your spam folder </p> <input type="text" name="code" placeholder="Eg. 12345" value="<?php echo $code; ?>"> <br/> <div class="error"><?php echo $err; ?></div> <div class="resend"><?php echo $error;?></div> <input type="submit" name="resend" class="s" id="left" value="Resend OTP"> <input type="submit" name="verify" class="s" id="right" value="Verify"> </form> </div> </body> </html>
This is my signup.php code <?php session_start(); if(!empty($_SESSION['email'])) { require_once('./all_utils/connection.php'); $query="SELECT * FROM identity_table WHERE email='".$_SESSION['email']."'"; $result=mysqli_query($conn,$query); if(mysqli_fetch_assoc($result)) { header("location:welcome/welcome.php"); } } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>SignUp - Kanha Stories</title> <style> * { margin: 0; padding: 0; } body { width: 100vw; height: 100vh; display: flex; align-items: center; background-color: #ff9d00; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100%25' height='100%25' viewBox='0 0 1600 800'%3E%3Cg stroke='%23000' stroke-width='66.7' stroke-opacity='0' %3E%3Ccircle fill='%23ff9d00' cx='0' cy='0' r='1800'/%3E%3Ccircle fill='%23f27d00' cx='0' cy='0' r='1700'/%3E%3Ccircle fill='%23e55f00' cx='0' cy='0' r='1600'/%3E%3Ccircle fill='%23d84400' cx='0' cy='0' r='1500'/%3E%3Ccircle fill='%23cb2c00' cx='0' cy='0' r='1400'/%3E%3Ccircle fill='%23bf1600' cx='0' cy='0' r='1300'/%3E%3Ccircle fill='%23b20300' cx='0' cy='0' r='1200'/%3E%3Ccircle fill='%23a5000e' cx='0' cy='0' r='1100'/%3E%3Ccircle fill='%2398001c' cx='0' cy='0' r='1000'/%3E%3Ccircle fill='%238b0027' cx='0' cy='0' r='900'/%3E%3Ccircle fill='%237e0030' cx='0' cy='0' r='800'/%3E%3Ccircle fill='%23710037' cx='0' cy='0' r='700'/%3E%3Ccircle fill='%2364003b' cx='0' cy='0' r='600'/%3E%3Ccircle fill='%2358003c' cx='0' cy='0' r='500'/%3E%3Ccircle fill='%234b003a' cx='0' cy='0' r='400'/%3E%3Ccircle fill='%233e0037' cx='0' cy='0' r='300'/%3E%3Ccircle fill='%23310030' cx='0' cy='0' r='200'/%3E%3Ccircle fill='%23210024' cx='0' cy='0' r='100'/%3E%3C/g%3E%3C/svg%3E"); background-attachment: fixed; background-size: cover; overflow-x: hidden; } .cont { color: #ffffff; width: 500px; margin: auto; } h2 { color: #ffffff; text-align: center; padding: 1.5px; } .error { text-align: center; padding: 20px; font-size: 1rem; color: rgb(233, 76, 76); } form { font-size: 1.2rem; /* width: 40%; */ /* margin: auto; */ } .in{ margin: 5px 0; } input { border: 2px solid white; padding: 10px; margin: 5px 0; font-size: 1rem; width: 100%; } input:hover { border: 2px solid rgb(228, 81, 81); cursor: text; } p,a{ text-align: center; font-size: 1rem; } a{ color: deepskyblue; font-size:20px; } #s{ text-decoration:none; border-radius: 12px; } #s:hover { cursor: pointer; } a { text-decoration: none; } @media only screen and (max-width: 600px){ .cont{ width: 300px; } .error,input{ font-size: 0.8rem; } } @media only screen and (max-width: 400px){ .cont{ width: 70%; } h2{ font-size: 1.3rem; } a,p{ font-size: 0.7rem; } label{ font-size: 1.0rem; } input{ padding: 4px; } } </style> </head> <body> <?php $name=""; $email=""; $tel=""; $dob=""; $err=""; $name_err=""; $email_err=""; $tel_err=""; $dob_err=""; $password_err=""; if($_SERVER["REQUEST_METHOD"]=="POST") { if(isset($_POST['signup'])) { if(empty($_POST['name']) || empty($_POST['dob']) || empty($_POST['tel']) || empty($_POST['email']) || empty($_POST['password'])) { if(empty($_POST['name'])) { $name_err="Name is required!"; } else{ $name=$_POST['name']; } if(empty($_POST['email'])) { $email_err="Email is required!"; } else{ $email=$_POST['email']; } if(empty($_POST['tel'])) { $tel_err="Contact Number is required!"; } else{ $tel=$_POST['tel']; } if(empty($_POST['dob'])) { $dob_err="D.O.B is required!"; } else{ $dob=$_POST['dob']; } if(empty($_POST['password'])) { $password_err="Password is required!"; } } else { $today = new DateTime(date('m.d.y')); $dob = new DateTime($_POST['dob']); $diff1 = $today->diff($dob); $age = $diff1->y; if($age > 15 || $age <3) { $dob = $_POST['dob']; $dob_err = "Age criteria not satisfied , child's age must be between 3-15 years"; } else { require_once("./all_utils/connection.php"); $email=$_POST['email']; $query="SELECT * FROM identity_table WHERE email='".$email."'"; $result=mysqli_query($conn,$query); if(mysqli_fetch_assoc($result)) { $err="Email alredy registered!"; $name=$_POST['name']; $email=$_POST['email']; } else { if($age < 7) { $_SESSION['age_category'] = '1'; } else { $_SESSION['age_category'] = '2'; } $_SESSION['name']=$_POST['name']; $_SESSION['email']=$_POST['email']; $_SESSION['password'] = password_hash($_POST['password'],PASSWORD_DEFAULT); $_SESSION['tel']=$_POST['tel']; $_SESSION['dob']=$_POST['dob']; $_SESSION['xyz']='xyz'; require_once("all_utils/mail.php"); header("location:conf.php"); } } } } } ?> <div class="cont"> <h2>SignUp - Kanha Stories</h2> <form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF'])?>" method="POST"> <span class="error"><?php echo $err; ?></span> <br/> <label for="name">Name</label><br /> <input type="text" name="name" placeholder="Enter your name" value="<?php echo $name; ?>"> <span class="error"><?php echo $name_err; ?></span> <br/> <label for="email">Email</label><br /> <input type="email" name="email" placeholder="Enter your Email ID" value="<?php echo $email; ?>"> <span class="error"><?php echo $email_err;?></span> <br/> <label for="tel">Mobile Number</label><br /> <input type="tel" name="tel" placeholder="Enter Mobile Number" value="<?php echo $tel; ?>"> <span class="error"><?php echo $tel_err;?></span> <br/> <label for="date">D.O.B. of Child (Click on Calander icon)</label><br /> <input type="date" name="dob" placeholder="Enter date of birth " value="<?php echo $dob;?>"> <span class="error"><?php echo $dob_err;?></span> <br/> <label for="password">Password</label><br /> <input type="password" name="password" placeholder="Enter your Password"> <span class="error"><?php echo $password_err; ?></span> <br/> <div class="sub"> <input type="submit" name="signup" id="s" placeholder="Submit"><br /> </div> </form> <p>Already registered? <a href="./login.php">log in here</a></p> </div> </body> </html>
I don't know what I can do now , Please try to give me the solutions as soon as possible. Thanks I just enabled error reporting and I am not that familiar with it. I know I have an error some where around line 33. I know I am missing a bracket or a comma or some other syntax error I just cannot find where the error is. Below is my script. Thanks for any help. Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Airline Survey</title> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <meta name="author" content="Revised by abc1234"/> </head> <body> <?php $WaitTime = addslashes($_POST["wait_time"]); $Friendliness = addslashes($_POST["friendliness"]); $Space = addslashes($_POST["space"]); $Comfort = addslashes($_POST["comfort"]); $Cleanliness = addslashes($_POST["cleanliness"]); $Noise = addslashes($_POST["noise"]); if (empty($WaitTime) || empty($Friendliness) || empty($Space) || empty($Comfort) || empty($Cleanliness) || empty($Noise)) echo "<hr /><p>You must enter a value in each field. Click your browser's Back button to return to the form.</p><hr />"; else { $Entry = $WaitTime . "\n"; $Entry .= $Friendliness . "\n"; $Entry .= $Space . "\n"; $Entry .= $Comfort . "\n"; $Entry .= $Cleanliness . "\n"; $Entry .= $Noise . "\n"; $SurveyFile = fopen("survey.txt", "w") } if (flock($SurveyFile, LOCK_EX)) { if (fwrite($SurveyFile, $Entry) > 0) { echo "<p>The entry has been successfully added.</p>"; flock($SurveyFile, LOCK_UN; fclose($SurveyFile); else echo "<p>The entry could not be saved!</p>"; } else echo "<p>The entry could not be saved!</p>"; } ?d> <p><a href="AirlineSurvey.html">Return to Airline Survey</a></p> </body> </html> Hi folks, I am a complete n00b at php and mysql. I am teaching myself from books and the WWW, but alas I am stuck... the error I get is: Parse error: syntax error, unexpected T_STRING in X:\xampp\htdocs\search.php on line 7 here is the code: <?php mysql_connect ("localhost", "user", "password") or die (mysql_error()); mysql_select_db ("it_homehelp_test") or die (mysql_error()); $term = $_POST['term']; $sql = $mysql_query(select * from it_homehelp_test where ClientName1 like '%term%'); <<<------this is line 7 while ($row = mysql_fetch_array($sql)){ echo 'Client Name:' .$row['ClientName1']; echo 'Address:' .$row['Address1']; echo 'Phone:' .$row['Tel1']; } ?> Any help you can offer would be great. I can also post the ".html" file that creates the search bar if it is needed. Thanks I have a pdo prepared statement that fetches records from mysql database. The records show up on the page. However if there are no records on a page, I get this error message.
"QLSTATE[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 '-10' at line 4"
Here is my statement
$getCategoryId = $_GET['id']; $limit = 10; $offset = ($page - 1) * $limit; $statement = $db->prepare("SELECT records.*, categories.* FROM records LEFT JOIN categories ON records.category_id = categories.category_id WHERE records.category_id = :category_id ORDER BY record_id DESC LIMIT {$limit} OFFSET ".$offset); $statement->bindParam('category_id', $getCategoryId); $statement->execute(); $results = $statement->fetchAll(PDO::FETCH_ASSOC);If I remove try and catch block, it'll tell me exactly which line is giving the issue. So from the above code, the error has to do with "$statement->execute();". This is where the error occurs. As far as I know, the above pdo statement is correct. Can you tell me if something is wrong with it? Edited by helloworld001, 16 December 2014 - 04:14 PM. I keep getting an error code when running my php, it states: Parse error: syntax error, unexpected $end in W:\www\blog\login.php on line 33 Line 33 is </html> Code: [Select] <?php mysql_connect ("localhost", "root", ""); mysql_select_db("blog"); ?> <html> <head> <title>Login</title> </head> <body> <?php if(isset($_POST['submit'])){ $name = $_POST['name']; $pass = $_POST['password']; $result = mysql_query("SELECT * FROM users WHERE name='$name' AND pass='$pass'"); $num = mysql_num_rows($result); if($num == 0){ echo "Bad login, go <a href='login.php'>back</a>"; }else{ session_start(); $SESSION ['name'] = $name; header("Location: admin.php"); } ?> <form action='login.php' method='post'> Username: <input type='text' name='name' /><br /> Password: <input type='password' name='password' /><br /> <input type='submit' name='sumbit' value='Login!' /> </form> </body> </html>Can any one advise me whats wrong? |