PHP - How To Text A Phone Number In Database
How to text a phone number in database
as well as record recieved textmessages into mysql database. Any help here? i've been googling for ages. Similar Tutorialshello, i cant find this anywhere on the internet. i dont even know what to search. if you are on your phone and there is a phone number on a web page, sometimes you can click on that number and it will dial it. how can i do that? Alright so I am writing up a function to verify various formats of US based phone numbers.. And I seemed to have run into a snag. This is what I have gotten so far, and for the most part works well. Code: [Select] function validate_phoneUS($number){ $numStripX = array('(', ')', '-', '.', '+'); $numCheck = str_replace($numStripX, '', $number); $firstNum = substr($number, 0, 1); if(($firstNum == 0) || ($firstNum == 1)) {return false;} elseif(!is_numeric($numCheck)){return false;} elseif(strlen($numCheck) > 10){return false;} elseif(strlen($numCheck) < 10){return false;} else{ $formats = array('###-###-####', '(###) ###-####', '(###)###-####', '##########', '###.###.####', '(###) ###.####', '(###)###.####'); $format = trim(ereg_replace("[0-9]", "#", $number)); return (in_array($format, $formats)) ? true : false; } } When I try to run these test numbers down the line.. Code: [Select] $number1 = '0234567890'; $number2 = '1234567890'; $number3 = "(555)555-5555"; $number4 = '555-555-5555'; $number5 = '555.555.5555'; $number6 = '5555555555'; $number7 = "(555) 555-5555"; I get these as a result.. 0234567890 is bad. 1234567890 is bad. (555)555-5555 is bad. 555-555-5555 is a valid phone number. 555.555.5555 is a valid phone number. 5555555555 is a valid phone number. (555) 555-5555 is bad. Where I am stuck is on the numbers that have the parenthesis wrapped around them. For a while I had it working with them and coming back as a valid number, and then I changed a couple things else where for something else. and now they come back as bad. I am getting tired, and I need some extra eyes to help me figure this out.. what did I snag myself on? Hi All, I only want to allow phone number in ###-###-####. Anything else I want an error. Here is what I have, which says any number is valid. Function: function checkPhone($number) { if(preg_match('^[0-9]{3}+-[0-9]{3}+-[0-9]{4}^', $number)) { return $number; } else { $items = Array('/\ /', '/\+/', '/\-/', '/\./', '/\,/', '/\(/', '/\)/', '/[a-zA-Z]/'); $clean = preg_replace($items, '', $number); return substr($clean, 0, 3).'-'.substr($clean, 3, 3).'-'.substr($clean, 6, 4); } } Checking Number: $number = '1231231234'; if(checkPhone($number)) { echo $number.' is a valid phone number.'; } else { echo $number.' is not a valid phone number.'; } This should give me the not valid message. Thanks I have a form in which I want it to accept US phone formats, ie (123) 123-1234, 123-123-1234, 1-123-123-1234, etc.. Below is my code and I would really appreciate it if someone can tell me what I need to accept the #s. Thank you! $session = $_SESSION['verify']; $error = ''; if(trim($name) == '') { $error .= '<li>Your name is required.</li>'; } if(trim($email) == '') { $error .= '<li>Your e-mail address is required.</li>'; } elseif(!isEmail($email)) { $error .= '<li>You have entered an invalid e-mail address.</li>'; } if(trim($phone) == '') { $error .= '<li>Your phone number is required.</li>'; } elseif(!is_numeric($phone)) { $error .= '<li>Your phone number can only contain digits.</li>'; } if(trim($comments) == '') { $error .= '<li>You must enter a message to send.</li>'; } if($session != $verify) { $error .= '<li>The verification code you entered is incorrect.</li>'; } if($error != '') { echo '<div class="error_message">Attention! Please correct the errors below and try again.'; echo '<ul class="error_messages">' . $error . '</ul>'; echo '</div>'; } else { if(get_magic_quotes_gpc()) { $comments = stripslashes($comments); } I know this should be easy.... However, to validate a 7-digit phone number, I wrote this: Code: [Select] <?php if(!empty($_POST['mobile_number'])) { if(!is_numeric($_POST['mobile_number']) || strlen($_POST['mobile_number']) != 7) { $errors[] = 'Please enter a 7-digit number without spaces or dashes for your <strong>Mobile</strong>.'; } else { $_SESSION['mobile_number'] = $_POST['mobile_number']; } } else { $_SESSION['mobile_number'] = ''; } ... but now I realise that numeric/integer validation won't work because where I am - in Ireland - mobile numbers can start with an initial zero, too. So, the following mobile numbers are possible: 0123456 0224466 How can I ensure that: each digit in the mobile number is numeric an initial zero is possible there are exactly 7 digits I suppose I loop through each digit, ensuring that that digit is numeric and break out of the loop if a non-numeric digit is encountered..? Any suggestions? TIA hi friends could someone help with this criteria? i want to restrict entry to db if the post value number was entered into db less than 31 days ago?
if($homePhone == '') { $qry = "SELECT * FROM table WHERE homePhone='$homePhone '";in db i store time in datetime current timestamp like 2013-07-13 21:19:15 could someone help me out? Edited by lovephp, 12 July 2014 - 11:36 AM.
Hi,
<?php $connect = mysqli_connect('localhost', 'root', '1234', 'contact'); $query ='SELECT * FROM tbl_employee ORDER BY ID DESC'; $result = mysqli_query($connect, $query); ?>
<table id="employee_data" class="table table-striped table-bordered"> <thead> <tr> <td>Name</td> <td>Location</td> <td>Department</td> <td>Phone Number</td> </tr> </thead> <?php while($row = mysqli_fetch_array($result)) { echo ' <tr> <td>'.$row["name"].'</td> <td>'.$row["location"].'</td> <td>'.$row["department"].'</td> <td>'.$row['phone_number'].'</td> </tr> '; } ?> </table>
Like the title says. I have 4 of the same number in my database, but I only want my website to display one of the 4. How can I do something like this? How do I call the last ID number from a table in MySql and echo it? This is what I have so far: Code: [Select] $query = mysql_query("SELECT idnum FROM ready_aclassft"); Maybe im comeing at it all wrong. I am designing a mmorpg guild site, and decided to make a coordinate database. A user will enter their own coords, x and y, and the 10 closest coords to them will be displayed. I need help doing this. My table is: id coordx coordy alliance region I am using $_GET to retrieve the user's input. so $_GET['mex'] $_GET['mey'] Thanks in advance for your help. My current project requires me to save the number of views an image (banner ad) has appeared on users website. The problem here is that the image will be appearing on several users website and i want to be able to save the number of times it has appeared on my database. I know how to do this if the image was on the same server as the database, but not when the image and database are on completely different servers. This is somewhat like analytic where it tracks the visitors to a page. Does anyone how i can accomplish this? i figured i would need to create a JavaScript code to provide to the user so they can place it on the site but how do i get that code to connect to my database? Hello, I am using the following code to display images managed by a MySQL database. Basically another program manages a bunch of images, but this script displays certain ones (ones with INCLUDE = 1 in the database) on my main page. My question is, is there an easy way to limit the number of images it displays, say to 5? I'm not too concerned which images actually display (ascending or descending)... or better yet, random! Most importantly, I only want five to display. Each image will be linked to the full page, which displays all the images. Any ideas? Thanks! Code: [Select] <?php $username="XXXXXXX"; $password="XXXXXXX"; $database="XXXXXXX"; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM ft_form_12 WHERE col_24='1'"; // $query="SELECT * FROM ft_form_12"; // SELECT * FROM ft_form_12 WHERE col_24='1' $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); ?> <?php $i=0; while ($i < $num) { $f20=mysql_result($result,$i,"col_23"); //Photo file name $f21=mysql_result($result,$i,"col_24"); //INCLUDE ?> <a href="http://www.domain.com/display_whole_page.shtml"><img src="http://www.domain.com/the_file/pictures/<?php echo $f20; ?>" height="50" border="0"></a> <?php $i++; } ?> I don't want to use AI, or a primary key to sort the data, as it could create some problems if the items are visited out of order, but I want to sort it always based upon a single element for speed.
I'm creating a table that will be populated (built), when it's corresponding entry doesn't exist, how do I get it sorted out if someone visits 2, then 7 before they visit 5 to read what's there? It's not a 2d number line, but a 3d number grid.
Edited by Q695, 09 September 2014 - 11:30 PM. hi!, is it possible to use rand() to generate unique number that will be saved in a database as a primary key? Since i dont want to have numbers like 00001 incrementing on the table. They dont look like real account numbers... i need something like 45642 or 95452 and the like. thanks in advance. Hi, I need to write some code for this but unsure where to start. Basically i have a database of say 10 rows. I need to be able to input a number and some sort of fair algorithm will choose one of the rows. The number will be from 6 to 10 numbers long, and will need to pick the same result each time based on that number. Its for a lotto game Hey guys, I m not yet an experienced coder. SO faced alot of problems. Here, I'm trying to generate a UNIQUE RANDOM NUMBER set between two numbers. Repetative occurance must be avoided by all means as I want every number so generated bears a unique value. In other words, every values that made entry into the field of my database should be differant from each others. <?php $conN=mysql_connect("localhost","root",""); if(!$conN) { die('error'.mysql_error()); } mysql_select_db("freebie_allusers",$conN); $UIN=mt_rand(1,5); $locateUIN="SELECT UIN FROM user_info WHERE UIN='".$UIN."'"; $fetchUIN=mysql_query($locateUIN); $resultUIN=mysql_num_rows($fetchUIN); if($resultUIN>0) { WHAT CODE IS REQUIRED HERE SO AS TO GENERATE UNIQUE RANDOM NUMBER? } else echo $UIN; ?> Thanx in advance I'm getting the dreaded " Invalid parameter number: number of bound variables does not match number of tokens" error and I've looked at this for days. Here is what my table looks like:
| id | int(4) | NO | PRI | NULL | auto_increment | | user_id | int(4) | NO | | NULL | | | recipient | varchar(30) | NO | | NULL | | | subject | varchar(25) | YES | | NULL | | | cc_email | varchar(30) | YES | | NULL | | | reply | varchar(20) | YES | | NULL | | | location | varchar(50) | YES | | NULL | | | stationery | varchar(40) | YES | | NULL | | | ink_color | varchar(12) | YES | | NULL | | | fontchosen | varchar(30) | YES | | NULL | | | message | varchar(500) | NO | | NULL | | | attachment | varchar(40) | YES | | NULL | | | messageDate | datetime | YES | | NULL |Here are my params: $params = array( ':user_id' => $userid, ':recipient' => $this->message_vars['recipient'], ':subject' => $this->message_vars['subject'], ':cc_email' => $this->message_vars['cc_email'], ':reply' => $this->message_vars['reply'], ':location' => $this->message_vars['location'], ':stationery' => $this->message_vars['stationery'], ':ink_color' => $this->message_vars['ink_color'], ':fontchosen' => $this->message_vars['fontchosen'], ':message' => $messageInput, ':attachment' => $this->message_vars['attachment'], ':messageDate' => $date );Here is my sql: $sql = "INSERT INTO messages (user_id,recipient, subject, cc_email, reply, location,stationery, ink_color, fontchosen, message,attachment) VALUES( $userid, :recipient, :subject, :cc_email, :reply, :location, :stationery, :ink_color, :fontchosen, $messageInput, :attachment, $date);"; And lastly, here is how I am calling it: $dbh = parent::$dbh; $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING); if (empty($dbh)) return false; $stmt = $dbh->prepare($sql); $stmt->execute($params) or die(print_r($stmt->errorInfo(), true)); if (!$stmt) { print_r($dbh->errorInfo()); }I know my userid is valid and and the date is set above (I've echo'd these out to make sure). Since the id is auto_increment, I do not put that in my sql (though I've tried that too), nor in my params (tried that too). What am I missing? I feel certain it is something small, but I have spent days checking commas, semi-colons and spelling. Can anyone see what I'm doing wrong? Hello, I'm new! I am trying to populate a list of locations based on ratings. I can populate the list just fine but it's displaying every record in the table. Is there a way of only looping 4 times so as to just display the top 4 records? Here's the code: Code: [Select] $result = mysql_query("SELECT * FROM locations ORDER BY rating DESC"); while($row = mysql_fetch_array($result)) { echo $row['name']; echo "<br>; } Thankyou in advance for any help I need a way to generate a random number and insert into a database, and I need the database to not contain any duplicates of that number. I basically need to generate a RMA # (Return Merchandise Authorization Number), so the numbers absolutely CAN NOT be duplicate. I have no ideas how to go about this. Should I generate a random number, search the database and see if there's a duplicate, and if there is re-run the script? This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=334480.0 |