Insert Url last 2 characters in database php - php

I am trying to insert last 2 chararcters of Url into my database.When i insert everytime it takes some number like "2147483647".How to insert the correct last 2 chararcters of Url.
'$array = json_decode(stripslashes($_POST['data']));
for($i = 0, $l = sizeof($array); $i < $l; $i++){
$obj = $array[$i];
if($obj->{'leaf'} == true){
$leaf = 1;
} else{
$leaf = 0;
}
if($obj->{'parentId'} == null){
$parentID = 'null';
} else{
$parentID = $obj->{'parentId'};
}
if($obj->{'Duration'}==''){
$duration = 0;
} else{
$duration = $obj->{'Duration'};
}
$url = (!empty($_SERVER['HTTPS'])) ? "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] : "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
$gantt_id = substr(strrchr($url, '='), 1);
/*if($obj->{'gantt_id'}==null){
$gantt_id = 0;
} else{
$gantt_id = $obj->{'gantt_id'};
}
*/
$q = 'INSERT INTO j_gantt_tasks SET Name = "'.$obj->{'Name'}.'", StartDate = "'.$obj->{'StartDate'}.'", EndDate = "'.$obj->{'EndDate'}.'",
Duration = "'.$obj->{'Duration'}.'", DurationUnit = "'.$obj->{'DurationUnit'}.'", PercentDone = "'.$obj->{'PercentDone'}.'", Cls = "'.$obj->{'Cls'}.'", gantt_id="'.$gantt_id.'",
parentId = "'.$obj->{'parentId'}.'"';
$r = mysql_query($q);
if(!$r){
echo db_error($q);
}
$obj->{'id'} = mysql_insert_id();
}
echo json_encode($array);'

give a try to substring
$url = (!empty($_SERVER['HTTPS'])) ?
"https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] :
"http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
$last2 = substring($url,-2);

Related

unable to insert multiple array data from dynamic generated field?

I am unable to enter multiple data, it enter only single data. I have tried using for loop and then entering data, using 3 user and 2 task, there is an error previously offset.
public function add($postData)
{
// dd($postData);
$c = count($postData['user_name']);
$t = count($postData['task_name']);
for ($i = 0; $i < $c; $i++) {
$user_name = $postData['user_name'][$i];
$user_email = $postData['user_email'][$i];
$data['insert']['user_name'] = $user_name;
$data['insert']['user_email'] = $user_email;
}
for ($j = 0; $j < $t; $j++) {
$task_name = $postData['task_name'][$j];
$data['insert']['task_name'] = $task_name;
}
$data['insert']['name'] = $postData['name'];
$data['insert']['description'] = $postData['description'];
$data['insert']['customer_name'] = $postData['customer_name'];
$data['insert']['billing_method'] = $postData['billing_method'];
$data['insert']['dt_created'] = DT;
$data['table'] = PROJECT;
$result = $this->insertRecord($data);
if ($result == true) {
$response['status'] = 'success';
$response['message'] = 'Project created';
} else {
$response['status'] = 'danger';
$response['message'] = DEFAULT_MESSAGE;
}
return $response;
}
As Per lack of question details attached, I am supposing that you want to insert multiple task entry with project name, description etc.
Here is updated code:
<?php
// dd($postData);
$username = $postData['username'];
$user_email = $postData['user_email'];
$task_name = $postData['task_name'];
foreach ($username as $key => $value) {
$data['insert']['name'] = $postData['name'];
$data['insert']['description'] = $postData['description'];
$data['insert']['customer_name'] = $postData['customer_name'];
$data['insert']['billing_method'] = $postData['billing_method'];
$data['insert']['username'] = $value;
$data['insert']['user_email'] = $user_email[$key];
$data['insert']['task_name'] = $task_name[$key];
$data['insert']['dt_created'] = DT;
$data['table'] = PROJECT;
$result = $this->insertRecord($data);
}

PHP Link Shortener

Zack here.. I've recently run into a spot of trouble with my URL Shortener.. Can you check the below code for errors? Thanks so much!
<?php
$db = new mysqli("localhost","pretzel_main","00WXE5fMWtaVd6Dd","pretzel");
function code($string_length = 3) {
$permissible_characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$char_length = strlen($permissible_characters);
$random = '';
for ($i = 0; $i < $string_length; $i++) {
$random .= $permissible_characters[rand(0, $char_length - 1)];
}
return $random;
}
if (substr($_POST['long'], 0, 7) == http://) {
$url = $_POST['long'];
} elseif (substr($_POST['long'], 0, 8) == https://) {
$url = $_POST['long'];
} else {
$url = "http://".$_POST['long'];
}
$result = $db->prepare("INSERT INTO links VALUES('',?,?)");
$result->bind_param("ss",$url, $title);
$result->execute();
$title = $code();
?>
Good luck, and Thanks in advance!
- Zack
Try this :
<?php
$db = new mysqli("localhost","pretzel_main","00WXE5fMWtaVd6Dd","pretzel");
function code($string_length = 3) {
$permissible_characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$char_length = strlen($permissible_characters);
$random = '';
for ($i = 0; $i < $string_length; $i++) {
$random .= $permissible_characters[rand(0, $char_length - 1)];
}
return $random;
}
if (substr($_POST['long'], 0, 7) == "http://") {
$url = $_POST['long'];
} elseif (substr($_POST['long'], 0, 8) == "https://") {
$url = $_POST['long'];
} else {
$url = "http://".$_POST['long'];
}
$result = $db->prepare("INSERT INTO links VALUES('ss','$url','$title')");
$result->execute();
$title = code(); // no need of $ sign here
?>

How to split and count sms messages from file in PHP

I have problem that my sms messages are imported with csv, then it is checked if number is ok and how long sms is. My problem is that if text messages is longer then 160 it still enters 1 in databse. But it should start counting, if it is less or equal than 160, it is 1 messages, if it is more than 160 but less or equal than 320 it is two messages and if it is more then it is 3 messages.
Page code is here:
<?php
$link = #mysql_connect("localhost", "admin", "") or die("Error: Database offline.");
mysql_select_db("database", $link);
mysql_query("SET NAMES 'utf8' ", $link);
function detect_type($smstext) {
$type = 0;
$dec_codes = array();
for ($i = 0; $i < strlen($smstext); $i++) {
$symbol = substr($smstext,$i,1);
if (!in_array(ord($symbol), $dec_codes)) { $type = 1; }
}
return $type;
}
$result_array = array();
$unic_numbers = array();
$fp = file_get_contents($_FILES['filename']['tmp_name']);
$fp = str_replace("\r\n", "\n", $fp);
$fp = str_replace("\r", "\n", $fp);
$fp = str_replace("\t", "", $fp);
$rows = explode("\n", $fp);
$imported_rows = 0;
$duplicate_rows = 0;
$error_rows = 0;
$long_rows = 0;
for ($i = 0; $i < sizeof($rows); $i++) {
$data = explode(";", $rows[$i]);
$data[1] = sms_formatNumbers($data[1]); // formating number
$userid = 78;
if(strlen($data[1]) > 9){
if($unic_numbers[$data[1]] != true ){ // unic number check
$unic_numbers[$data[1]] = true;
$imported_rows++;
$fullSMS = iconv("ISO-8859-1","UTF-8", trim($data[2])." ".trim($data[3])." ".trim($data[4]));
if(strlen($fullSMS) > 164){
$long_rows++;
}
if($_POST['action'] == 'send'){
// SMS TEXT
$smstext = str_replace("õ", "ò", $fullSMS);
$smstext = str_replace("Õ", "ò", $smstext);
$type = detect_type($smstext);
// servicegroup
$char2 = substr($data[1], 0, 2);
$char3 = substr($data[1], 0, 3);
$c1 = mysql_query("SELECT * FROM zone_info WHERE country_code = '".$char2."'", $link);
$c2 = mysql_query("SELECT * FROM zone_info WHERE country_code = '".$char3."'", $link);
if (mysql_num_rows($c1) == 1) {
$r = mysql_fetch_array($c1);
$price = $r['price'];
$z = mysql_query("SELECT * FROM zone WHERE id = ".$r['up']."", $link);
$zone = mysql_fetch_array($z);
$zone_id = $zone['id'];
$servicegroup = $zone['servicegroup'];
} else if (mysql_num_rows($c2) == 1) {
$r = mysql_fetch_array($c2);
$price = $r['price'];
$z = mysql_query("SELECT * FROM zone WHERE id = ".$r['up']."", $link);
$zone = mysql_fetch_array($z);
$zone_id = $zone['id'];
$servicegroup = $zone['servicegroup'];
}
require_once("../scripts/number.class.php");
$receiver = "00".$data[1];
$obj = new NumberClass($receiver);
$operator = $obj -> operator_code;
$country = $obj -> code;
$operator_name = $obj -> operator_name;
if(strlen($operator) > 0) {
$er = mysql_query("SELECT * FROM zone_exception WHERE country = ".$country." AND operator = ".$operator."", $link);
if (mysql_num_rows($er) == 1) {
$erand = mysql_fetch_array($er);
$price = $erand['price'];
$servicegroup = $erand['servicegroup'];
}
} else $operator_name = "-";
if ($operator_name == "-") { $servicegroup = $servicegroup; }
else {
if ($operator_name == " First Operator") $servicegroup = "90";
else if ($operator_name == "Second Operator") $servicegroup = "91";
else if ($operator_name == "Third Operator") $servicegroup = "92";
else $servicegroup = $servicegroup;
}
require_once("../core/init.mini.inc.php");
$servicegroup = UserBasedRerouting($receiver, $userid, $operator_name, $servicegroup);
$client_type ='corporative';
$sender = $data[0];
$zone_id = 11;
$client_sms_id = '0';
$client_want_report = '0';
$client_report_url = '';
$amount = 1;
$dt_delaysend = '1970-01-01 00:00:00';
$SMSsent = 0;
$SMStotal = 1;
$smstext_old = $smstext;
while($SMSsent < $SMStotal){
$sql = mysql_query("insert into sms_queue (user_id,client_type,dt_entered,sender,receiver,operator,smstext,sms_type,zone_id,client_sms_id,client_want_report,client_report_url,sms_price,amount,servicegroup,dt_delaysend) values ('$userid','$client_type','".date('Y-m-d H:i:s')."','$sender','$receiver','$operator_name','$smstext',0,'$zone_id','$client_sms_id','$client_want_report','$client_report_url','$price','$amount','$servicegroup','$dt_delaysend')", $link);
$SMSsent++;
}
}
}else{
$duplicate_rows ++;
}
}else{
$error_rows++;
}
}
$result_array['success'] = true;
$result_array['long_sms'] = $long_rows;
$result_array['send_sms'] = $imported_rows;
$result_array['error_sms'] = $error_rows;
$result_array['duplicate_sms'] = $duplicate_rows;
$result_array['action'] = $_POST['action'];
echo json_encode($result_array);
function sms_formatNumbers($number){
$number = (int)$number;
$start_code = (int)substr($number,0,4);
if($start_code < 3780 or $start_code == 3785 or $start_code > 3789){
return $number;
}else{
return '';
}
}
?>
Can someone help me out with that?
Thank you
Try
if(strlen($fullSMS) > 164){
$long_rows = ceil(strlen($fullSMS)/160);
}
instead of
if(strlen($fullSMS) > 164){
$long_rows++;
}

Issues with PHP for loop entering names into database

I am using the following code to enter submitted names into the database. The code, when working correctly, should capture the names and other information submitted in the form and create three unique entries in the database. This is not happening. Instead the code is capturing the last name in the three pack and entering its information into the database. You can view the form here beta website. The payment processing script is disabled on the form. What do I need to change in the for loop code to fix this issue? Any assistance is greatly appreciated. Thank you. I have added all of the code that is used in the script below. Hopefully this will give you a better understanding of what is going on in the script.
class DreamModelDream extends JModel {
function getDetails()
{
$session = JFactory::getSession();
if($session->get('dreamticket'))
{
return $session->get('dreamticket');
}
$data = new stdClass();
$data->tickets = -1;
$data->fiftytickets = '';
$data->qty = 0;
$data->fiftyqty = 0;
$data->firstname = '';
$data->firstname2 = '';
$data->firstname3 = '';
$data->lastname = '';
$data->lastname2 = '';
$data->lastname3 = '';
$data->address = '';
$data->address2 = '';
$data->address3 = '';
$data->city = '';
$data->city2 = '';
$data->city3 = '';
$data->postal = '';
$data->postal2 = '';
$data->postal3 = '';
$data->phone = '';
$data->phone2 = '';
$data->phone3 = '';
$data->altphone = '';
$data->altphone2 = '';
$data->altphone3 = '';
$data->email = '';
$data->email2 = '';
$data->email3 = '';
$data->giftname = '';
$data->giftaddress = '';
$data->giftcity = '';
$data->giftpostal = '';
$data->sec_firstname = '';
$data->sec_firstname2 = '';
$data->sec_firstname3 = '';
$data->sec_lastname = '';
$data->sec_lastname2 = '';
$data->sec_lastname3 = '';
$data->agegroup = 0;
$data->expm = 0;
$data->expy = 0;
$data->nameoncard = '';
$data->cctype = '';
$data->ccnum = '';
$data->Media_Radio = false;
$data->Media_TV = false;
$data->Media_Newspaper = false;
$data->Media_Mail = false;
$data->Media_Web = false;
$data->Media_Kinsmen_Member = false;
$data->Media_Other = false;
$data->Radio_CJCY = false;
$data->Radio_MY96 = false;
$data->Radio_ROCK = false;
$data->Radio_CHAT = false;
$data->Radio_POWER = false;
$data->Radio_Other = false;
$data->total = false;
$data->billingphone = '';
$data->agree = 0;
$data->ord_type = 0;
$data->creditcard = '';
$data->user_ip = $_SERVER['REMOTE_ADDR'];
return $data;
}
function getConfirmDetails()
{
$post = JRequest::get('post');
$ticket = new stdClass();
foreach($post as $key => $value)
{
$ticket->$key = $value;
}
$session = JFactory::getSession();
$session->set('dreamticket', $ticket);
if(!strlen($post['firstname'])){
return "Your first name is missing<br>";
}
if(!strlen($post['lastname'])){
return "Your last name is missing<br>";
}
if(!strlen($post['address'])){
return "Your address is missing<br>";
}
if(!strlen($post['city'])){
return "Your city is missing<br>";
}
if(!strlen($post['postal'])){
return "Your postal code is missing<br>";
}
if (!preg_match("/^T\d\w\d\w\d$/i", $post['postal'])) {
//return "Your postal code is invalid for this province<br>";
}
if(!strlen($post['phone'])){
return "Your phone number is missing<br>";
}
if(!strlen($post['email'])){
return "Your email is missing<br>";
}
if($post['tickets'] == '-1'){
////////// TICKET 2
if(!strlen($post['firstname2'])){
return "Your first2 name is missing<br>";
}
if(!strlen($post['lastname2'])){
return "Your last2 name is missing<br>";
}
if(!strlen($post['address2'])){
return "Your address2 is missing<br>";
}
if(!strlen($post['city2'])){
return "Your city2 is missing<br>";
}
if(!strlen($post['postal2'])){
return "Your postal2 code is missing<br>";
}
if (!preg_match("/^T\d\w\d\w\d$/i", $post['postal2'])) {
//return "Your postal2 code is invalid for this province<br>";
}
if(!strlen($post['phone2'])){
return "Your phone number2 is missing<br>";
}
/////////////Ticket 3
if(!strlen($post['firstname3'])){
return "Your first name3 is missing<br>";
}
if(!strlen($post['lastname3'])){
return "Your last name3 is missing<br>";
}
if(!strlen($post['address3'])){
return "Your address3 is missing<br>";
}
if(!strlen($post['city3'])){
return "Your city3 is missing<br>";
}
if(!strlen($post['postal3'])){
return "Your postal code3 is missing<br>";
}
if (!preg_match("/^T\d\w\d\w\d$/i", $post['postal3'])) {
//return "Your postal code3 is invalid for this province<br>";
}
if(!strlen($post['phone3'])){
return "Your phone number3 is missing<br>";
}
}
//////// END TICKET CHECK
if(!strlen($post['nameoncard'])){
return "Your Name on Credit Card is missing<br>";
}
if($post['cctype'] == "Please select one"){
return "Your Credit Card Type is missing<br>";
}
if(!strlen($post['ccnum'])){
return "Your Credit Card Number is missing<br>";
}
if(!strlen($post['billingphone'])){
return "Your billing phone number is missing<br>";
}
if(!strlen($post['agree'])){
return "Your must agree to the Lottery rules in order to proceed<br>";
}
return $ticket;
}
function process()
{
$user = JFactory::getUser();
jimport('joomla.database.table');
$params = JComponentHelper::getParams('com_dream');
$session = JFactory::getSession();
$data = $session->get('dreamticket');
if(!is_object($data))
{
return false;
}
$dif = strtotime("-1 hour");
$timestamp = date("F j, Y, g:i a",$dif);
$ord_id = date('ymdHis') . rand(1000,9999);
$ticket_total = (int) (($data->tickets == '-1') ? '250' : (int) $data->tickets * 100);
$fiftyticket_total = (int) (($data->fiftytickets == '0') ? '' : (int) $data->fiftytickets * 10);
$ordertotal = $ticket_total + $fiftyticket_total;
if(strlen($data->expm) == 1)
{
$data->expm = '0'.$data->expm;
}
if(strlen($data->expy) != 2)
{
$data->expy = substr($data->expy, 2, 2);
}
$data->total = $ordertotal;
JTable::addIncludePath(JPATH_BASE.DS.'administrator'.DS.'components'.DS.'com_dream'.DS.'tables');
$table = JTable::getInstance('Tickets', 'Table');
$table->auth = $auth;
$table->billingphone = $data->billingphone;
$table->Media_Radio = isset($data->Media_Radio) ? 1 : 0;
$table->Media_TV = isset($data->Media_TV) ? 1 : 0;
$table->Media_Newspaper = isset($data->Media_Newspaper) ? 1 : 0;
$table->Media_Mail = isset($data->Media_Mail) ? 1 : 0;
$table->Media_Web = isset($data->Media_Web) ? 1 : 0;
$table->Media_Kinsmen_Member = isset($data->Media_Kinsmen_Member) ? 1 : 0;
$table->Media_Other = isset($data->Media_Other) ? 1 : 0;
$table->Radio_CJCY = isset($data->Radio_CJCY) ? 1 : 0;
$table->Radio_MY96 = isset($data->Radio_MY96) ? 1 : 0;
$table->Radio_ROCK = isset($data->Radio_ROCK) ? 1 : 0;
$table->Radio_CHAT = isset($data->Radio_CHAT) ? 1 : 0;
$table->Radio_POWER = isset($data->Radio_POWER) ? 1 : 0;
$table->Radio_Other = isset($data->Radio_Other) ? 1 : 0;
$table->agegroup = $data->agegroup;
$table->orderdate = date('Y-m-d H:i:s');
$table->ip = $_SERVER['REMOTE_ADDR'];
$table->ord_type = ($user->get('id') > 0) ? 'CallCentre' : 'online';
$table->ord_id = $ord_id;
if($data->tickets == '0') {
$table->ticket_type = 'None';
} elseif($data->tickets == '-1') {
$table->ticket_type = '3Pack';
} elseif($data->tickets == '1') {
$table->ticket_type = '1ticket';
} elseif($data->tickets == '5') {
$table->ticket_type = '8tickets';
}
if($data->fiftytickets == '0') {
$table->fiftyticket_type = 'None';
} elseif($data->fiftytickets == '1') {
$table->fiftyticket_type = '1ticket';
} elseif($data->fiftytickets == '2') {
$table->fiftyticket_type = '3tickets';
}
$table->province = 'AB';
$table->creditcard = $data->cctype;
if(isset($data->giftpurchase)) {
$table->giftname = $data->giftname;
$table->giftadress = $data->giftadress;
$table->giftcity = $data->giftcity;
$table->giftpostal = $data->giftpostal;
}
$data->ord_id = $ord_id;
$tickets = 1;
$table->qty = $data->tickets;
if($data->tickets === '-1')
{
$tickets = 3;
$table->qty = 3;
} elseif($data->tickets === '1')
{
$tickets = 1;
$table->qty = 1;
} elseif($data->tickets === '5')
{
$tickets = 8;
$table->qty = 8;
}
$threepack = '';
$i = '';
for($i = 0; $i < $tickets; $i++)
{
$firstname = 'firstname'.$threepack;
$lastname = 'lastname'.$threepack;
$address = 'address'.$threepack;
$city = 'city'.$threepack;
$postal = 'postal'.$threepack;
$phone = 'phone'.$threepack;
$altphone = 'altphone'.$threepack;
$sec_firstname = 'sec_firstname'.$threepack;
$sec_lastname = 'sec_lastname'.$threepack;
$email = 'email'.$threepack;
$table->firstname = $data->$firstname;
$table->lastname = $data->$lastname;
$table->address = $data->$address;
$table->city = $data->$city;
$table->postal = $data->$postal;
$table->phone = $data->$phone;
$table->altphone = $data->$altphone;
$table->sec_firstname = $data->$sec_firstname;
$table->sec_lastname = $data->$sec_lastname;
$table->email = $data->$email;
$table->id = 0;
if($data->tickets === '-1' || $data->tickets === '5')
{
if($threepack == 2)
{
$threepack = 3;
} else {
$threepack = 2;
}
}
}
$fiftytickets = 1;
$table->fiftyqty = $data->fiftytickets;
if($data->fiftytickets === '1')
{
$fiftytickets = 1;
$table->fiftyqty = 1;
} elseif($data->fiftytickets === '2')
{
$fiftytickets = 3;
$table->fiftyqty = 3;
}
$table->order_total = $data->total;
$table->store();
//sending confirmation mail
$mailcontent = '';
for($i = 0; $i < $data->tickets; $i++)
I have figured out the issues with the for loop. The fiftytickets code needed to be moved above the for loop and the $table->store() function needed to be moved into the for loop and placed after the $table->id line. Now when a ticket or tickets are purchased, three entries with the same name or unique names are inserted into the database.

Add a number after a string, if it already exists

I'm working on a script that checks if the url already exists in the database, and if yes adds an additional -1 or -2 etc etc at the end. I found this script
But it 'd need to to check it again after adding-1. Since it may be already existing. How can I do that? I tired i this way
$query = mysql_query("SELECT * FROM posts WHERE url='$url'");
while ( $query ) {
$result = mysql_fetch_assoc($query);
$url = $result['url'];
$urlnew = $result['url'];
$oldurl = $url;
$first = 1;
$separator = '-';
while ( $urlnew == $url ) {
$url = preg_match('/(.+)'.$separator.'([0-9]+)$/', $urlnew, $match);
$urlnew = isset($match[2]) ? $match[1].$separator.($match[2] + 1) : $url.$separator.$first;
$first++;
}
$url = $urlnew;
}
The new code above works just fine. But it checks only once. How can I make it to check untill it dose not exists in the DB?
tried adding a new sql query at the bottom after $url -$urlnew but it only breaks the function.
EDIT
Here's the correct script :D
$query = mysql_query("SELECT * FROM posts WHERE url LIKE '%".$url."%'");
if ( $query ) {
while ( $result = mysql_fetch_assoc($query) ) {
$url = $result['url'];
$urlnew = $result['url'];
$first = 1;
$separator = '-';
while ( $urlnew == $url ) {
preg_match('/(.+)'.$separator.'([0-9]+)$/', $urlnew, $match);
$urlnew = isset($match[2]) ? $match[1].$separator.($match[2] + 1) :$url.$separator.$first;
$first++;
}
}
}
$url = $urlnew;
Your code is likely vulnerable to SQL Injection. You should consider using PDO or MySQLi instead.
Here's an example of how you could do so:
$url = 'www.example.com';
$i = 0;
$max_duplicates = 100;
$query = $pdo->prepare('SELECT COUNT(id) count FROM urls WHERE url=?');
while ($i++ < $max_duplicates) {
$result = $query->execute($url);
if (!$result->fetch(PDO::FETCH_OBJ)->count)
break;
if ($i == 1) {
$url = $url . '-1';
} else {
$n = $i > 10 ? 2 : 1;
$url = substr($url, -$n) . $i;
}
}
Here's what I used for my needs
function checkLink($link, $counter=1){
global $connect;
$newLink = $link;
do{
$checkLink = mysqli_query($connect, "SELECT id FROM table WHERE link = '$newLink'");
if(mysqli_num_rows($checkLink) > 0){
$newLink = $link.'-'.$counter;
$counter++;
} else {
break;
}
} while(1);
return $newLink;
}
$link = 'www.example.com';
$uniquelink = checkLink($link);

Categories