Hello Team,
I am trying to integrate an SMS gate way into my website, and the workflow is as follows :-
1) user hits a button which says verify my phone number ( a script runs and they get a random code on their phone number as sms.
2) The user gets directed to an article where there is a bunch of code which inserts the random code sent to user in their user row in comprofiler table in a column named cb_phoneverificationcode.in this page / article they also see an input box to enter the code they received as sms. and hit submit.
Code:
//*
<html>
<head>
</head>
<body>
<form id="sms2" name="sms2" method="POST" action="index.php?option=com_content&view=article&id=83&Itemid=654">
<table width= "400">
<tr>
<td align="right" valign="top">Verification Code:</td>
<td align="left"><input type="textarea" name="veficationcode" cols="82" rows="5" id="veficationcode"></textarea></td>
</tr>
<tr>
<td colspan="4" align="right"><input type="submit" name= "submit" value="submit"/>
</td>
</tr>
</table>
</form>
</body>
</html>
{source}
<?php
$phverf= rand();//stores the value of rand function in phverf variable
echo "$phverf" . "\n"; // echo this just to check...when users inputs the random number received on sms
Global $_CB_framework;
$myId = $_CB_framework->myId();
$cbUser =& CBuser::getInstance( $myId );
if ( ! $cbUser ) {
$cbUser =& CBuser::getInstance( null );
}
$user =& $cbUser->getUserData();
Echo $myId;
$firstname = $cbUser->getField('firstname');
echo $firstname;
$servername = "";
$username = "";
$password = "";
$dbname = "";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "UPDATE t4qcm_comprofiler SET cb_phoneverificationcode ='$phverf'
WHERE id = $myId";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>
3) The user is directed to a page / article where a sql query insert the submitted post data into a new column in their user row in a new column named cb_userinputphonecode, and another query retrieves the data stored in both the 2 columns / fields cb_phoneverificationcode & cb_userinputphonecode and finally there is an IF statement which compares these 2 values and if they match displays success and if not then user retries.
<?php
//calling CB framework to get user profile values in this case Userid.
Global $_CB_framework;
$myId = $_CB_framework->myId();
$cbUser =& CBuser::getInstance( $myId );
if ( ! $cbUser ) {
$cbUser =& CBuser::getInstance( null );
}
$user =& $cbUser->getUserData();
echo $myId;
if(isset($_POST)){
$verificationcode = $_POST["veficationcode"];
echo "Post".$verificationcode;
$servername = "";
$username = "";
$password = "";
$dbname = "";
// Create connection
$connect = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$connect) {
die("Connection failed: " . mysqli_connect_error());
}
//input user code in db
$sql2 = "UPDATE t4qcm_comprofiler SET cb_userinputphonecode ='$verificationcode' WHERE id = $myId";
if ($connect->query($sql2) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql2 . "<br>" . $connect->error;
}
//select the data from the database for random code input into database
$query = "SELECT cb_userinputphonecode,cb_phoneverificationcode FROM t4qcm_comprofiler WHERE id='$myId'";
//select the data from the database for user code input into database
//$query = "SELECT `cb_userinputphonecode` FROM `t4qcm_comprofiler` WHERE `id`= $myId";
if ($result = mysqli_query($connect,$query)) {
while($row = mysqli_fetch_assoc($result))
echo $row;
}
var_dump($row);
var_dump($row);
if($row == $row){ echo "SUCCESS!!! With values - User Input : ".$row." And Phone Verification : ".$row; }else{ echo "verification code mismatch. Please try again"; }
print_r(mysqli_fetch_assoc($result));
$connect->close();
}
?>
The issue is that even when the user inputs a wrong value it still shows success , i did a var_dump and that displays null for both fields but echo displays thir db values and so does their front end profile.
*//
[/code]