PHP - Ctype_alpha Returns Unwanted False
Code: [Select]
<?php # This script does get included into the document create_new_tag_from.php if(isset($_POST['tag_name_submit'])){ $tag_name_submit = $_POST['tag_name_submit']; } if(!empty($_POST['tag_name'])){ $tag_name = strip_tags($_POST['tag_name']); } if(!empty($_POST['tag_description'])){ $tag_description = strip_tags($_POST['tag_description']); } if(isset($tag_name_submit)){ # The Validation of User Entered Data # Do validate for solely alphabetic characters with ctype_alpha # ctype_alpha($tag_name) && if(ctype_alpha($tag_description)){ $tag_name = strtolower($tag_name); $tag_description = strtolower($tag_description); # The Insertion Into the Database $db_connect = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); # Do research if SQL query has to be modified into a PHP comform query $sql_query = sprintf( "set @newid = convert( ( select max(convert( (substring(tag_id, 2)) , unsigned integer))+1 from tags), char(10) ); set @newid = if(length(@newid) = 1, concat('0', @newid), @newid); set @newid = concat('c', @newid); INSERT INTO tags (tag_id, tag_name, tag_description, added_by_user_id, creation_date, last_edited) VALUES (@newid, '%s', '%s', 7, now(), '0')", mysqli_real_escape_string($db_connect, $tag_name), mysqli_real_escape_string($db_connect, $tag_description) ); $sql_query_run = mysqli_multi_query($db_connect, $sql_query); # Print Test to See If It Works echo "works_ "; echo $tag_name . "_ "; echo $tag_description . "_ "; } else { # End of the Validation echo "The entered data must be in alphabetic characters."; } } ?> Here is the form: Code: [Select] <?php include_once('../../header.php'); include_once('../../model/contribution/create_new_tag_script.php'); ?> <form action="" method="post"> <input type="text" name="tag_name" value="" /> <textarea maxlength="60" type="text" name="tag_description" value=""></textarea> <input type="submit" name="tag_name_submit" value="Submit the New Tag" /> </form> <?php include_once('../../footer.php'); ?> By the script as given above the conditional check will skip to the error message. Though I have to say that ctype_alpha does return TRUE when I do try it with "tag_name" which is entered data from the input field, while the other is from the textarea. I simply cannot see the reason for the returned FALSE. Similar TutorialsI am trying to unserialize this string: a:3:{s:3:\"zip\";s:5:\"55068\";s:4:\"city\";s:9:\"Rosemount\";s:5:\"state\";s:2:\"MN\";} but I unserialize is returning false. Why is it doing that? $info = unserialize($_COOKIE['zipcode']); var_dump($info); Hi, I am trying to verify if the given url exists or not, by using file_exists() function. It always returns 'FALSE' , according to my understanding it happening because the file to be checked on the given url is located in safe mode. Could anyone please suggest as to how this could be overcome, by similar function or by using alternative method. Regards Abhishek Madhani Hi, I'm pretty new to PHP and I am working on a form that sends and email. I want to display a message if the mail can't be sent (i.e. if mail() returns false) and a different message if mail() returns true, except it is returning false even though the emails are sending. Basically I have used: $to = 'myemail@email.com'; $subject = "Subject Line Goes here"; $headers = "From: $email"; $message = 'My message'; $mailSent = mail($to, $subject, $message, $headers); In testing it I have used the following to determine what is going on: if (isset($mailSent)) { echo '$mailSent ='.$mailSent; } - echo's nothing if ($mailSent == FALSE) { echo '$mailSent = FALSE'; } - echo's '$mailSent = FALSE' if ($mailSent == TRUE) { echo '$mailSent = TRUE'; } - echo's nothing if (is_null($mailSent)) { echo '$mailSent = NULL'; } - echo's '$mailSent = NULL' echo '$mailSent ='.$mailSent; - echo's '$mailSent =' Any help would be greatly appreciated! Thanks! How can I check if a function has returned false.. I know theirs the following way: if (!checkdate($month, $day, $year)) { //the function has returned false } But is their another way (beside using the ! operator) perhaps === FALSE (not sure if that'd work so asking)? Hi all ! The following code has two similar queries. Query 1 and Query 2. While Query 1 works just fine, Query 2 simply fails persistently. I have not been able to figure out why?
I have checked every single variable and field names but found no discrepancy of any sort or any mismatch of spelling with the fields in the database.
I would be grateful if anybody can point out what is preventing the second query from returning a valid mysqli object as the first one does. Here is the code for the two.
<?php $db_host = "localhost"; $db_user ="root"; $db_pass =""; $db_database ="allscores"; //////////////// CHECKING VARIABLE FILEDS IN A UPDATE QUERY ////////////////////////////////// //////////////// QUERY 1 ///////////////////////////////////////////////////////////////////// /* $db_database ="test"; $db_table ="users"; $RecNo = 1; $field1 = 'name'; $field2 = 'password'; $field3 = 'email'; $field4 = 'id'; $val1 = "Ajay"; $val2 = "howzatt"; $val3 = "me@mymail.com"; $con = mysqli_connect($db_host,$db_user,$db_pass,$db_database) or die('Unable to establish a DB connection'); $query = "UPDATE $db_table SET $field1 = ?, $field2 = ?, $field3 = ? WHERE $field4 = ? "; // session terminated by setting the sessionstatus as 1 $stmt = $con->prepare($query); var_dump($stmt); $stmt->bind_param('sssi',$val1,$val2,$val3,$RecNo); if($stmt->execute()) { $count = $stmt->affected_rows; echo $count; } //////////////// QUERY 1 END ///////////////////////////////////////////////////////////////////// */ //////////////// QUERY 2 ///////////////////////////////////////////////////////////////////// $con = mysqli_connect($db_host,$db_user,$db_pass,$db_database) or die('Unable to establish a DB connection'); $table = 'scores'; $date = date('Y-m-d H:i:s'); /* $prestr = "Mrt_M_"; $STATUS = $prestr."Status"; $S_R1 = $prestr."Scr_1"; $S_R2 = $prestr."Scr_2"; $PCT = $prestr."PPT"; $DPM = $prestr."DSP"; $TIMETAKEN = $prestr."TimeTaken"; */ $STATUS = "Mrt_M_Status"; $S_R1 = "Mrt_M_Scr_1"; $S_R2 = "Mrt_M_Scr_2"; $PPT = "Mrt_M_PPT"; $DSP = "Mrt_M_DSP"; $TIMETAKEN = "Mrt_M_TimeTaken"; $TimeOfLogin = $date; $no_of_logins = 10; $time_of_nLogin = $date; $m_scr_row1 = 5; $m_scr_row2 = 5; $m_ppt = 20; $m_dsp = 60; $m_time = 120; $date = $date; $RecNo = 24; $query = "UPDATE $table SET TimeOfLogin = ?, no_of_logins = ?, time_of_nLogin = ?, $S_R1 = ?, $S_R2 = ?, $PPT = ?, $DSP = ?, $TIMETAKEN = ?, $STATUS = '1', TimeOfLogout = ?, WHERE RecNo = ?"; $stmt = $con->prepare($query); var_dump($stmt); $stmt->bind_param('sisiiddssi',$TimeOfLogin,$no_of_logins,$time_of_nLogin,$m_scr_row1 $m_scr_row2,$m_ppt,$m_dsp,$m_time,$date,$RecNo); if($stmt->execute()) echo " DONE !"; ?>Thanks to all I tried parsing through first https://www.jadaliyya.com/Details/28167/The-Empire-of-Sexuality-An-Interview-with-Joseph-Massad then even tried www.google.com and on both I get the following returned
post_url equals: www.google.compost_title equals: testpost_Threadybody equals: Enter your posts... URL equals: www.google.com www.google.com is not a valid URL Web page redirects after 2 seconds. And here is the if statement that handles my filter for URLs if(isset($_POST["submit"]) && !empty($_POST["url"]) && !empty($_POST["Title"])){ $URL = $conn -> real_escape_string($_POST["url"]) ; $BodyText = $conn -> real_escape_string(nl2br($_POST["ThreadBody"])) ; echo "<P>URL equals: " ; echo $URL ; echo "<P>" ; //Change to embed for youtube. if (filter_var($URL, FILTER_VALIDATE_URL)) { echo("$URL is a valid URL"); //Check if url is a youtube url if (strpos($URL,'youtube') !== false) { echo 'Youtube exists.'; $URL = preg_replace("/\s*[a-zA-Z\/\/:\.]*youtube.com\/watch\?v=([a-zA-Z0-9\-_]+)([a-zA-Z0-9\/\*\-\_\?\&\;\%\=\.]*)/i","<iframe width=\"420\" height=\"315\" src=\"//www.youtube.com/embed/$1\" frameborder=\"0\" allowfullscreen></iframe>",$URL); } else { echo 'Youtube is not included .'; $URL = "<ahref ='" . $URL . "</a>" ; } $Title = $conn -> real_escape_string($_POST["Title"]) ; $User = $_SESSION['username']; $sql = "INSERT INTO Threads (Title, Users, ThreadBody, url) VALUES ('$Title', '$User','$BodyText','$URL')"; if (mysqli_query($conn, $sql)) { echo "New record has been added successfully !"; } else { echo "Error: " . $sql . ":-" . mysqli_error($conn); } } else { echo("$URL is not a valid URL"); }
I'm working on a WordPress theme and I'm trying to build in a simple if statement which will check if the user has add his own logo into the images folder if he doesn't then the name of the blog will appear as normal text in place of the graphic logo. This is how it looks like: <?php $logo_dir = get_template_directory_uri() . "/images/logo.png"; if (file_exists($logo_dir)) { ?> <li><img src="<?php bloginfo ('template_directory'); ?>/images/logo.png" alt="<?php bloginfo('description'); ?>" /></li> <?php } else { ?> <li id='blog_name'><a href="<?php bloginfo('url'); ?>"><?php bloginfo('name'); ?><font>*</font></a></li> <?php } ?> I've echo'd out $logo_dir, the URL is correct, but still for some reason it's seeing it as if there would no file exist. If I turn it around into !file_exists then the graphic logo WILL show up. So it's always seeing it as non-existent. Any ideas why this could be or am I using this function in a wrong fashion? As far as I've understood the PHP manual, this is the correct way of using it. Hello , this is my first post in this forum , i would like to see the following code and tell me your opinion , not about the security issues not about how good or bad it is. Its just a simple demonstration in order to show you the problem.
<?php include('config/functions.php'); $mysqli = connectionToDb(); $mysqli->autocommit(FALSE); $stmt = $mysqli->prepare("INSERT INTO users (first_name,last_name) VALUES ('stelios','stelios2')"); $stmt->execute(); $stmt->close(); $stmt = $mysqli->prepare("INSERT INTO users (first_name,last_name) VALUES ('stelios3','stelios4')"); $stmt->execute(); $stmt->close(); var_dump($mysqli->commit()); $mysqli->close();This is the code and the var_dump($mysqli->commit()); line prints false ! BUT , the inserts are in the database. If i comment out the commit line , then nothing is in the database. Can you advise ? Thanks ! in my code below the **data is extracted correctly for the first foreach but doesn't return anything for 2nd foreach though selected one present inside the 2nd foreach** i still get the error Warning: Invalid argument supplied for foreach() for line `foreach ($authorlist as $post)`... however the 2nd foreach returns data correctly as soon as i remove the first foreach loop. hi there, is there a difference between if($var == false) and if(false == $var) thankyou! Hey all, I'm trying to learn more about PHP but I keep having all these problems with Aptana Studio. I'll write out a bunch of code and it will flag my code as having an error, normally one of the curly brackets, even though I can't see anything wrong with the code at all. Sometimes if I delete it all and retype it in the error will go away even though I typed it out EXACTLY as I did the first time. Here is some code that it's flagging as having an error: Code: (php) [Select] <?php //Classes// class Dog{ public $hungry = 'Hell yeah!'; public function($food){ $this->hungry = 'not so much.'; } } //Program Variables// $dog = new Dog; //Program Code// echo $dog->hungry; ?> It is saying that the curly brace after "public function ($food)" is wrong as well as the closing curly brace on line 9 and the parentasis just before "$food". I can't see an error, no matter how long I look at it. What am I doing wrong? Hello! Just started getting into PHP! I'd like to set a variable to false, and then check if it is set to false ( set to false = true ), but I'm confused about assignment operators vs. comparison operators, no pun intended. Code: [Select] = false or Code: [Select] == false ? Just a silly question. I've been using 1 and 0 to tell if something is true or false, such as if a feature is enabled or not. I see that some use the words true and false. Is there a proper way or is either way correct? Thanks! Hi guys! I'm new to PHP and I'm using Drupal and there's a function that one block will be called if PHP scripts returns value TRUE. Now I want my "Search" to only show at ALL THE other pages but not index. With the code: if (Url::exists('http://www.example.com')) I get my Search function to return TRUE so it will be showed on index page only, but not on any other pages!! So I kinda need this on reverse - how do I get a TRUE value for something that excists? In this case it would be www.example.com, or if anyone else has any other ideas I would be very thankful! strange i want to update ProductDescription i get the parsed $pdescription it is echoed but it's regarded as empty by var_dump Code: [Select] <?php // example of how to use basic selector to retrieve HTML contents include('../simple_html_dom.php'); $links=array("http://www.example.com/apartments/198.htm"); foreach($links as $page) { $phtml = file_get_html($page); // find all td tags with attribite align=center foreach($phtml->find('span[id=lblCodiceAppartamento]') as $name){ echo $name->plaintext.'<br><br>'; } foreach($phtml->find('span[id=lblDescrizione]') as $pdescription){ echo $pdescription.'<br><br>'; } $con = mysql_connect("localhost","root","root"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("international", $con); $query=mysql_query("UPDATE products_NEW SET ProductDescription='$pdescription' WHERE ProductName = '$name->plaintext' AND SupplierID = '38'"); var_dump($query); //mysql_query("INSERT INTO apartments (name) //VALUES ('$name->plaintext')"); mysql_close($con); } private function _authenticate() { // if there's already an auth error if ( $this->_checkForMessageType('auth') ) { $this->_addMessage('auth', 3); self::__destruct(); return false; } $stmt = $this->_dbh->prepare("SELECT shopID FROM api_users WHERE shopID = ? AND API_key = ? LIMIT 1"); var_dump($stmt->execute(array($this->_shopID, $this->_key))); echo $stmt->rowCount(); // authenticate key / shop id if ( !$stmt->rowCount() ) { $this->_addMessage('auth', 3); self::__destruct(); return false; } $this->_addMessage('auth', 4); } I am using PDO with MySQL driver and ATTR_EMULATE_PREPARES => true, however, when I run this code I get the output: Code: [Select] bool(false) 0{"auth":{"3":""}} Any ideas why PDOStatement::execute is returning false? I get no connection errors, no PDOExceptions, the db structure is correct, and there is valid data in the database. Any help appreciated, thanks. I'm having trouble with a script and I just can't figure out what's wrong with it. The script is located at http://www.qlhosting.com/ham/check.php Here's the code for it <?php if (isset($_POST['submit'])) { $domain = $_POST['domain']; $password = md5($_POST['password']); include 'db.php'; mysql_query("SELECT * FROM apps WHERE domain='$domain' AND WHERE cpassmd5='$password' LIMIT 1"); $stat = $row['status']; } else { } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Quotaless Web Hosting | Check Status</title> <style type="text/css"> body,td,th { font-family: Arial, Helvetica, sans-serif; font-size: 12px; } </style> </head> <body> <h1>Check Application/Account Status</h1> <?php if ($stat="PENDING") { echo "<hr />"; echo "Your application is currently listed as PENDING. Our staff have not viewed your application yet. Please be patient, and watch your email for a response. Thank you!"; } elseif ($stat="NMI") { echo "<hr />"; echo "We need more information from you in order to take action on your application. Please check your e-mail inbox for a message from our staff specifically stating what we need. If you did not get this message, please post a message on our support forum. Thank you!"; } else { } ?> <hr /> <h2>To check the status of your application or account, login using the form below.</h2> <form id="check" name="check" method="post" action="<?php echo $PHP_SELF;?>"> <p>Domain: <input type="text" name="domain" id="domain" /> <br /> Password: <input type="password" name="password" id="password" /> <br /> <input type="submit" name="button" id="button" value="Check" /> </p> </form> <hr /> <p> </p> </body> </html> The part under if ($stat="PENDING") is performed upon page load, even when the if condition relating to it is false. I can't seem to figure out what exactly is wrong here. Please help me out. I would really appreciate the help. Thanks! Anthony |