I'm trying to do a simple select and send it via SMS Gateway but when I send the message that should run the function nothing happens. This is the function that i wrote. Sender should send "utakmice x" where the x is the number of the next x events that are sent from the database:
function utakmice($broj) {
$conn = connect();
if ($conn->connect_error) {
$smsporuka = "Ne moze se uspostaviti konekcija sa bazom, pokusajte kasnije.";
} else {
$query = "SELECT * FROM utakmica ORDER BY datum LIMIT = $broj;";
$rezultat = mysql_query($query);
if($rezultat) {
if(mysql_num_rows($rezultat) !== 0) {
$smsporuka="";
while($red = mysql_fetch_array($rezultat)) {
$smsporuka .= "(".$red["id_tekma"]." ".$red["protivnik"].",".$red["cena"]."RSD datum: ".$red["datum"].")";
}
} else {
$smsporuka = "Nema selektovanih utakmica!";
}
}
}
disconnect($conn);
sendResponse($smsporuka);
}
Here is the code before the functions, function info works as it's supposed to work:
function sendResponse($t) {
$reply = rawurlencode($t);
header("Content-Type: text/html; charset=utf-8");
header("text: ".$reply);
}
if(empty($text) || strlen($text) == 0 || $text == "") {
$smsporuka = "Poslali ste sms poruku u losem formatu, za vise informacija posaljite INFO.";
sendResponse($smsporuka);
} else {
$text = str_replace(";", "", $text);
$explodeovanText = explode(' ',trim($text));
$komanda = strtolower($explodeovanText[0]);
switch ($komanda) {
case "info":
info();
break;
case "utakmice":
utakmice($explodeovanText[1]);
break;
case "dodaj":
dodaj($explodeovanText[1], $explodeovanText[2]);
break;
case "rezervisi":
rezervisi($explodeovanText[1], $explodeovanText[2]);
break;
case "otkazi":
otkazi($explodeovanText[2]);
break;
}
}
function info() {
$smsporuka = "Posaljite UTAKMICA da bi ste videli narednih 5 protivnika i datume utakmica. Posaljite REZ_x_y, gde je x id utakmice, a y broj mesta koje rezervisete.";
sendResponse($smsporuka);
}
I solved it! mysql functions were supposed to be mysqli and the query was not correct. Here is the solution. Also in the beginning I set the default parameter to be 5.
function utakmice($broj = 5) {
$smsporuka = "";
$conn = connect();
if ($conn->connect_error) {
$smsporuka = "Ne moze se uspostaviti konekcija sa bazom, pokusajte kasnije.";
} else {
$query = "SELECT * FROM utakmica ORDER BY datum LIMIT $broj;";
$rezultat = mysqli_query($conn, $query);
if($rezultat) {
if(mysqli_num_rows($rezultat) !== 0) {
$smsporuka="";
while($red = mysqli_fetch_array($rezultat)) {
$smsporuka .= "(".$red["id_tekma"]." ".$red["protivnik"].",".$red["cena"]."RSD datum: ".$red["datum"].")";
}
}
else {
$smsporuka = "Nema selektovanih utakmica!";
}
}
}
disconnect($conn);
sendResponse($smsporuka);
}
Related
I am trying to insert email into the table newsletter but it is not inserting into database
This is the code:
PHP
$table = 'news_letters';
if(isset($_REQUEST['mode'])) {
extract($_REQUEST);
$email=$_POST['email'];//print_r($email);die;
if (isset($_POST['email']) && trim($_POST['email'])=="submitNewsletter") {
$condition = " WHERE email='$email'";
$res = $obj_common->select_record('news_letters', $condition);
if (count($res) > 0) {
echo 'already register';
header("location:index.html?msg=already_register");
die;
}
}
if(trim($_POST['mode'])=="submitNewsletter")
{
$condition = " WHERE email='$email'";
$res = $obj_common->select_record('news_letters', $condition);
if (count($res) > 0) {
echo 'already register';
header("location:thankyou.html?msg=already_register");
die;
}
else
{
$data=array('email'=>"$email",'status'=>'$status');
$res=$obj_common->insert_record('news_letters', $data); //print_r($res);die;
header("location:thankyou.html?msg=newsletter_add_success");
die;
}
}
}
?>
Email is not inserting into the table newsletter.
I am trying to do if, which will check if value is stored in the mysql database but I do not understand why it does not work. Is this how you can save it?
$przelew_nrkonta = $_POST['przelew_nrkonta'];
if (mysqli_num_rows($przelew_nrkonta) <= 0) { ... }
My all code:
$przelew_nrkonta = $_POST['przelew_nrkonta'];
$przelew_pieniadze = $_POST['przelew_pieniadze'];
$sql1 = sprintf("UPDATE kontabankowe SET pieniadze = pieniadze + '%s' WHERE nrkonta= '%s'",
mysqli_real_escape_string($polaczenie, $przelew_pieniadze),
mysqli_real_escape_string($polaczenie, $przelew_nrkonta));
$sql2 = sprintf("UPDATE kontabankowe SET pieniadze = pieniadze - '%s' WHERE nrkonta = '%s'",
mysqli_real_escape_string($polaczenie, $przelew_pieniadze),
mysqli_real_escape_string($polaczenie, $_SESSION['nrkonta']));
if ($polaczenie->connect_errno != 0) {
echo "Error: " . $polaczenie->connect_errno;
} else {
if (mysqli_num_rows($przelew_nrkonta) <= 0) {
echo "zly numer konta";
//header('Location: errors/error2.php');
} else {
if ($_SESSION['pieniadze'] < $przelew_pieniadze || $_SESSION['pieniadze'] <= 0) {
header('Location: errors/error1.php');
} else {
if ($polaczenie->query($sql1) && ($polaczenie->query($sql2)) === TRUE) {
header('Location: errors/favorably.php');
} else {
header('Location: errors/error3.php');
}
}
}
}
The input of the function mysqli_num_rows should be a mysqli_query.
I have created a json for getting mysql data for a news app in android & ios. Whenever I am parsing the json.php file it returns "No tag defined" and the app stopped working both android and ios. Here is the code sample that I was trying to work out.
<?php
header('content-type: application/json; charset=utf-8');
$con = mysql_connect("localhost","####","###");
if (!$con){
die('Could not connect: ' . mysql_error());
}
mysql_select_db("###", $con);
$date = date('Y-m-d');
//$date = '2014-02-01';
$year = substr($date, 0, -6);
$month = substr($date, 5, -3);
$day = substr($date,-2, 10);
if($month==01) $month1="january";
else if($month==02) $month1="february";
else if($month==03) $month1="march";
else if($month==04) $month1="april";
else if($month==05) $month1="may";
else if($month==06) $month1="june";
else if($month==07) $month1="july";
else if($month==08) $month1="august";
else if($month==09) $month1="september";
else if($month==10) $month1="october";
else if($month==11) $month1="november";
else if($month==12) $month1="december";
$table=$month1.$year;
//$table = $february2014;
if(isset($_REQUEST['tag']) && $_REQUEST['tag'] != ''){
$tag = $_REQUEST['tag'];
if($tag =='category_page' && isset($_REQUEST['menu_id']) && $_REQUEST['menu_id'] !='' ) {
$menu_id = $_REQUEST['menu_id'];
try{
$i=0;
$query = mysql_query("SELECT * FROM $table WHERE menu_id=1 AND news_date ='$date'");
if($query === FALSE) {
die(mysql_error());
}
while($data=mysql_fetch_array($query)){
$responce[$i]['news_id'] = $data['news_id'];
$responce[$i]['news_title'] = str_replace("\t",'',str_replace("\r\n\t",'', substr(strip_tags($data['news_title']),0,110)));
$responce[$i]['news_reporter'] = str_replace("\t",'',str_replace("\r\n\t",'', substr(strip_tags($data['news_reporter']),0,110)));
$responce[$i]['news_details'] = str_replace("\t",'',str_replace("\r\n\t",'', substr(strip_tags($data['news_details']),0,110)));
$responce[$i]['photo'] = $data['photo'];
$responce[$i]['path'] = 'admin/'.str_replace('\\','',$data['path']);
$responce[$i]['menu_id'] = $data['menu_id'];
$responce[$i]['menu_type'] = $data['menu_type'];
$responce[$i]['news_publish_status'] = $data['news_publish_status'];
$responce[$i]['news_order'] = $data['news_order'];
$responce[$i]['news_date'] = $data['news_date'];
$responce[$i]['news_time'] = $data['news_time'];
$responce[$i]['added_by'] = $data['added_by'];
$responce[$i]['directory'] = $data['directory'];
$responce[$i]['read_number'] = $data['read_number'];
$responce[$i]['comment_number'] = $data['comment_number'];
$responce[$i]['news_comment_table_name'] = $data['news_comment_table_name'];
$i++;
}
} catch(Exception $e) {
$responce = 'Exception: '.$e->getMessage();
}
}else{
$responce = "category or Menu id is not Defined";
}
echo json_encode($responce);
}else{
echo json_encode("No tag Defined");
}
?>
not getting any way to fix it up. can any one help me out.Would appreciate your kind assistance.
Try this
if(isset($_REQUEST['tag'])){
Instead of
if(isset($_REQUEST['tag']) && $_REQUEST['tag'] != ''){
I'm making an intranet.
Only admin have access to the page i want to build now :
I have a page with a textarea. When they click on the send button, it comming to a PHP page to send a req like "UPDATE ... " or "SELECT ...".
He can write the SQL request he want. It's supposed to works.
I want it to work : If it's an update i need to return he if it's ok, if its a select i need to return a table.
But i need it to be able to exec complex request like :
SELECT numfou,
(SELECT COUNT(*)
FROM PROPOSER P
WHERE P.numfou = F.numfou) AS NB_PROD
FROM FOURNISSEUR F;
(net exemple).<br/>
Do you know a PHP code to exec any SQL req?
I suggest this code i make (If you think it can be update say it :D) :
<?php
function requette($req){
$premierMot = explode(" ", $req)[0];
switch(strtoupper($premierMot)){
case "SELECT":
return select($req);
break;
case "UPDATE":
case "DELETE":
case "INSERT":
return updateDeleteInsert($req);
break;
}
}
function select($req){
$bdd = new PDO('mysql:host=localhost;dbname=spb', 'root', '');
// ON DETERMINE SI LE CLIENT RECHERCHE DANS CHAMPS EN PARTICULIER OU TOUT
$explosion = preg_split('/[;, \n]+/', $req);
$veuxTout = false;
for($cpt=0;$cpt<count($explosion);$cpt++){
if(strtoupper($explosion[$cpt]) == "*"){
$veuxTout = true;
break;
}
}
// SI IL NE VEUX PAS TOUT ON PREVOI UN TABLEAU DE DEMANDE
$demande = array();
for($cpt=1;$cpt<count($explosion);$cpt++){
if(strtoupper($explosion[$cpt]) == "FROM"){
break;
}
else{
array_push($demande,$explosion[$cpt]);
}
}
// ON CHERCHE LE NOM DE LA TABLE
$table = "";
for($cpt=0;$cpt<count($explosion);$cpt++){
if(strtoupper($explosion[$cpt]) == "FROM"){
$table = $explosion[$cpt+1];
break;
}
}
// ON CHERCHE LES TITRES DE LA TABLE
$sql = "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='$table';";
$res = $bdd->query($sql);
$titres = array();
while($resultat = $res->fetch()){
array_push($titres,$resultat['COLUMN_NAME']);
}
$res = $bdd->query($req);
$table = "<table>";
while($resultat = $res->fetch()){
$table .= "<tr>";
if($veuxTout == true){
for($cpt=0;$cpt<count($titres);$cpt++){
$table .= "<td>".$resultat[$titres[$cpt]]."</td>";
}
}
else{
$ok = false;
for($cpt1=0;$cpt1<count($titres);$cpt1++){
for($cpt2=0;$cpt2<count($demande);$cpt2++){
if(strtoupper($titres[$cpt1]) == strtoupper($demande[$cpt2])){
$table .= "<td>".$resultat[$titres[$cpt1]]."</td>";
$ok = true;
}
}
}
}
$table .= "</tr>";
}
$table .= "</table>";
return $table;
}
function updateDeleteInsert($req){
$bdd = new PDO('mysql:host=localhost;dbname=spb', 'root', '');
try {
$req = $bdd->prepare($req);
$req->execute();
return "oui";
}
catch(PDOException $e){
return "non";
}
}
$req = htmlentities($_POST['req']);
echo requette($req);
?>
I want to save datas from an fopen link into my database .. i get some help to use explode .. for that i got some code which should work .. but it doesn´t.
i have an error somewhere but i cannot find it (i cut out the database connection part to save space on screen)
stg_interface have the columns "uid, tan, kid, ziel, banner, verdienst, preis, aufendhalt, menge, reload, sponsor, werbeart, status, beschreibung, mailtext, gueltig"
// ***** Database Connection ***** //
// Interfacedaten laden
$sql_interface = mysql_query("SELECT * FROM stg_interface WHERE sponsor = 'allads4you' AND Werbeart = 'forcedbanner' LIMIT 1");
$output_interface = mysql_fetch_assoc($sql_interface);
$id_betreiber = $output_interface['id_betreiber'];
$id_seite = $output_interface['id_seite'];
$schnittstellencode = $output_interface['schnittstellencode'];
$max_reload = $output_interface['max_reload'];
$max_verguetung = $output_interface['max_verguetung'];
$min_verguetung = $output_interface['min_verguetung'];
$min_aufenthalt = $output_interface['min_aufenthalt'];
$restmenge = $output_interface['restmenge'];
$umrechnung = $output_interface['umrechnung'];
$eigenverdienst = $output_interface['eigenverdienst'];
$verguetungsoption = $output_interface['verguetungsoption'];
$eigenverdienst = $output_interface['eigenverdienst'];
$aufenthalt_zusatz = $output_interface['$aufenthalt_zusatz'];
$max_reload = $output_interface['max_reload'];
$restmenge = $output_interface['restmenge'];
$verhalten = $output_interface['verhalten'];
// extra vars for database values
$uid = '0';
$beschreibung = 'Allads4you Kampagne';
$mailtext = '';
$gueltig = '';
// Link öffnen
$fb=#fopen('http://www.allads4you.de/interface/?typ=forcedbanner&id='.$id_betreiber.'&sid='.$id_seite.'&pw='.$schnittstellencode.'&uebrig='.$restmenge.'&reload='.$max_reload.'&verguetung='.$min_verguetung.'','r');
// From here something works wrong and i cannot find the error
// standard vars to calculate
$file1 = "";
$file_fein = "";
$nummer = 0;
$spalten = 5;
$position = 0;
$einbuchen = true;
if($fb){
while($line=fgets($fb,1000)) {
$file_fein.= $line;
}
fclose($fb);
} // part to get data
$ausgabe = explode("|", $file_fein);
$for_zaehler = (count($ausgabe)/$spalten)-1;
for ($zaehler=0;$zaehler <= $for_zaehler;$zaehler++) {
$einbuchen = true;
//Reines einlesen vom Interface ANFANG
$k_id = (int)$ausgabe[$position];
$k_tan = md5('aa4y'.$k_id.'fb');
$k_name = addslashes($ausgabe[$position+1]);
$k_reload = (int)$ausgabe[$position+2]*3600;
$k_menge = (int)$ausgabe[$position+3];
$verguetung_check = $ausgabe[$position+4];
$verguetung_user = round(($ausgabe[$position+4]*$umrechnung) - (($ausgabe[$position+4]*$umrechnung) / 100 * $eigenverdienst),2);
$verguetung_webm = round($ausgabe[$position+4]*$umrechnung,2);
$k_banner_link = "http://www.allads4you.de/codes/forcedbannerview.php?id=".$id_betreiber."&bid=".$ausgabe[$position]."&aid=".$id_seite."";
$k_ziel_link = "http://www.allads4you.de/codes/forcedbannerklick.php?id=".$id_betreiber."&bid=".$ausgabe[$position]."&aid=".$id_seite."";
$k_aufenthalt = $min_aufenthalt;
//Reines einlesen vom Interface ENDE
//Prüfungsroutinen ANFANG only to check if the values are ok to put into database
//Vergütung
if($verguetung_webm >= $max_verguetung){
if($verguetungsoption == '2'){
$verguetung_webm = $max_verguetung;
$verguetung_user = round(($max_verguetung) - (($max_verguetung) / 100 * $eigenverdienst),2);
$einbuchen = true;
}else{
$einbuchen = false;
}
}
//Aufenthalt
if($einbuchen == true){
if($k_aufenthalt > $max_aufenthalt){
$einbuchen = false;
}
if($einbuchen = true){
if($k_aufenthalt < $min_aufenthalt){
$k_aufenthalt = $min_aufenthalt;
}
$k_aufenthalt+= $aufenthalt_zusatz;
}
}
//Reload
if($einbuchen == true){
if($k_reload > ($max_reload*3600)){
$einbuchen = false;
}elseif($k_reload == ''){
$einbuchen = false;
}elseif($k_reload == 0){
//24 Stunden reload falls 0 Stunden Reload
$k_reload = 86400;
}
}
//Menge
if($einbuchen == true){
if($k_menge < $restmenge){
$einbuchen = false;
}
}
//Prüfungsroutinen ENDE
//Vorberteiten für Ausgabe falls vorhanden ANFANG
if($einbuchen == true){
$nummer++;
}
if($verhalten <= '2' && $einbuchen == true){
$anzeige.='<tr bgcolor="#90EE90">
<td align="center">'.$nummer.'</td>
<td align="center">'.$k_id.'</td>
<td align="right">'.number_format($verguetung_webm,2,",",".").'</td>
<td align="right">'.number_format($verguetung_user,2,",",".").'</td>
<td align="center">'.($k_reload/3600).'</td>
<td align="right">'.number_format($k_menge,0,",",".").'</td>
<td align="center">'.$k_aufenthalt.'</td>
<td>'.substr($k_name,0,64).'</td>
</tr>';
}
//Vorbereiten für Ausgabe falls vorhanden ENDE
//Einbinden in die Datenbank falls eingestellt ANFANG
if($verhalten >= '2' && $einbuchen == true){
$vorhanden = db_query ("SELECT * FROM vms_gebuchte_werbung WHERE sponsor = 'allads4you' and `werbeart` = 'forcedbanner' and kid = '".$k_id."' LIMIT 1");
if (mysql_num_rows($vorhanden) > 0){
db_query ("UPDATE vms_gebuchte_werbung SET status = '1', banner = '".$k_banner_link."', ziel = '".$k_ziel_link."', menge = '".$k_menge."', preis = '".$verguetung_webm."', verdienst = '".$verguetung_user."', reload = '".$k_reload."', aufendhalt = '".$k_aufenthalt."' WHERE sponsor = 'allads4you' and `werbeart` = 'forcedbanner' and kid = '".$k_id."' and status = '0' LIMIT 1");
}else{
// part to save data into database
db_query ("INSERT INTO vms_gebuchte_werbung (uid,tan,kid,ziel,banner,preis,verdienst,aufendhalt,menge,reload,sponsor,werbeart, status, beschreibung, mailtext, gueltig) VALUES ('".$uid."', '".$k_tan."','".$k_id."','".$k_ziel_link."','".$k_banner_link."','".$verguetung_webm."','".$verguetung_user."','".$k_aufenthalt."','".$k_menge."','".$k_reload."','allads4you','forcedbanner','".$status."','".$beschreibung."','".$mailtext."','".$gueltig."')");
}
}
//Einbinden in die Datenbank falls eingestellt ENDE
$position=$position+$spalten;
}
db_close();
?>
I read it many times if i forget and ; or something like that but nothing .. can anyone give me some advice how to fix it ?