Here is what I have so far:
Age: <input type="text" name="age">
Canoe<input type="radio" name="ck">
Kayak<input type="radio" name="ck">
<input type="submit" style=" margin-bottom: 30px;">
</form>
You are <?php $_POST["age"];
if ($_POST["age"]<"11")
echo "an Atom.";
elseif ($_POST["age"]<"13")
echo "a Peewee.";
elseif ($_POST["age"]<"15")
echo "a Bantam.";
elseif ($_POST["age"]<"17")
echo "a Midget.";
elseif ($_POST["age"]<"19")
echo "a Juvenile.";
elseif ($_POST["age"]<"21")
echo "a Junior.";
elseif ($_POST["age"]<"120")
echo "a Senior.";
elseif ($_POST["age"]>"120")
echo "too old to race";
?>
I want to be able to include the canoe and kayak radio buttons in this to make the output be like: You are a Peewee canoeist and your opponents this year are: | or, you are a midget kayak er. You're opponents this year are:
Are you trying to echo the CK value into your output? Does this help?
Age: <input type="text" name="age">
Canoe<input type="radio" name="ck" value="canoeist">
Kayak<input type="radio" name="ck" value="kayakist">
<input type="submit" style=" margin-bottom: 30px;">
</form>
<?php
$ck = $_POST["ck"];
?>
You are <?php $_POST["age"];
if ($_POST["age"]<"11")
echo "a $ck Atom.";
elseif ($_POST["age"]<"13")
echo "a $ck Peewee.";
elseif ($_POST["age"]<"15")
echo "a $ck Bantam.";
elseif ($_POST["age"]<"17")
echo "a $ck Midget.";
elseif ($_POST["age"]<"19")
echo "a $ck Juvenile.";
elseif ($_POST["age"]<"21")
echo "a $ck Junior.";
elseif ($_POST["age"]<"120")
echo "a $ck Senior.";
elseif ($_POST["age"]>"120")
echo "too old to race";
?>
The values of the form radio must be canoeist and "kayakist". Just add the $ck = $_POST['ck']; and your sentence is like echo "a $ck Atom.";
You should use some variables here.
(I'm not that good at php, but I'll give it a try)
Age: <input type="text" name="age">
Canoe<input type="radio" name="ck" value="canoe"/>
Kayak<input type="radio" name="ck" value="kayak"/>
<input type="submit" style=" margin-bottom: 30px;">
</form>
$boat = "";
if ($_POST["ck"] == "canoe")
{
$boat = "canoeist";
} else if ($_POST["ck"] == "kayak")
{
$boat = "kayak er";
}
$rank = "";
You are <?php $_POST["age"];
if ($_POST["age"]<"11")
$rank = "an Atom.";
elseif ($_POST["age"]<"13")
$rank = "a Peewee.";
elseif ($_POST["age"]<"15")
$rank = "a Bantam.";
elseif ($_POST["age"]<"17")
$rank = "a Midget.";
elseif ($_POST["age"]<"19")
$rank = "a Juvenile.";
elseif ($_POST["age"]<"21")
$rank = "a Junior.";
elseif ($_POST["age"]<"120")
$rank = "a Senior.";
elseif ($_POST["age"]>"120")
$rank = "too old to race";
echo "You are " . $rank . " " . $boat;
?>
Related
The program is working fine except for the number changing command.
If someone could spot my error that would be greatly appreciated.
The change form comes up but the submit button does not POST to the variable.
change.php
<form class="" action="index.php" method="post">
<p>Min:<input type="number" name="min" value=""></p>
<p>Max:<input type="number" name="max" value=""></P>
<input type="submit" name="valuechange" value="Change">
</form>
index.php
<?php session_start();
?>
<center>
<?php
$minn = 1;
$maxx = 3;
if (isset($_GET["change"])) {
if (isset($_POST["valuechange"])) {
$minn = $_POST["min"];
$maxx = $_POST["max"];
}else {
include("change.php");
}
}
echo "<h1>Guess a number between ". $minn ." and ". $maxx . "</h1>";
if (!isset($_SESSION["number"])) {
$_SESSION["number"] = mt_rand($minn,$maxx);
$_SESSION["counter"] = 0;
}
if (isset($_POST["guess"])) {
if ($_POST['guess']== $_SESSION['number']) {
echo "<br><br><br><br>Correct<br>"."Your number was ". $_SESSION["number"]."<br>"."<a href='reset.php'>Play Again </a>";
session_destroy();
echo "<br><a href='index.php?change=true'>Change Numbers</a>";
}else {
$_SESSION["counter"] = $_SESSION["counter"] + 1;
include("form.php");
echo $_SESSION["counter"]. " Guesses<br>";
if ($_POST["guess"] > $_SESSION["number"]) {
echo "Incorrect your number is too big try a smaller number.";
} else if ($_POST["guess"] < $_SESSION["number"]) {
echo "Incorrect your number is too small try a larger number.";
}
echo "<br><a href='reset.php'>RESET </a>";
}
}else {
include("form.php");
}
?>
</center>
hello please help me i have a problem outputting all the values of checkbox it outputs only one i need to show all the checked checkbox and output them please help me here is the code it only shows one whenever i checked them all i need this
<html>
<head>
<title>Cake Form</title>
<link rel="stylesheet" href="cakeform.css">
</head>
<body>
<?php
$nameErr = $addErr = $phoneErr = $scake = $flavorcake = $fill = "";
$name = $address = $phone = $rcake = $fillr = $cakeflavor = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["name"])) {
$nameErr = "Name is required";
} else {
$name = test_input($_POST["name"]);
}
if (empty($_POST["address"])) {
$addErr = "Email is required";
} else {
$address = test_input($_POST["address"]);
}
if (empty($_POST["phone"])) {
$phoneErr = "Gender is required";
} else {
$phone = test_input($_POST["phone"]);
}
if(isset($_POST['SelectedCake'])){
$x=$_POST['SelectedCake'];
}
if(isset($_POST['CakeFlavor'])){
$y=$_POST['CakeFlavor'];
}
if(isset($_POST['Filling'])){
$z=$_POST['Filling'];
}
if(empty($x)){
$scake='Select one Cake';
}else{
$rcake= $x;
}
if(empty($y) OR $y == 'Flavor'){
$flavorcake='Select one flavor';
}else{
$cakeflavor= $y;
}
if(empty($z)){
$fill='Select at least one Fillings';
}else{
foreach($z as $item){
$fillr=$item;
}
}
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<div id="wrap">
<div class="cont_order">
<fieldset>
<legend>Make your own Cake</legend>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post">
<h4>Select size for the Cake:</h4>
<input type="radio" name="SelectedCake" value="Round6">Round cake 6" - serves 8 people</br>
<input type="radio" name="SelectedCake" value="Round8">Round cake 8" - serves 12 people</br>
<input type="radio" name="SelectedCake" value="Round10">Round cake 10" - serves 16 people</br>
<input type="radio" name="SelectedCake" value="Round12">Round cake 12" - serves 30 people</br>
<span class="error">*<?php echo $scake;?></span>
<h4>Select a Cake Flavor: </h4>
<select name="CakeFlavor">
<option value="Flavor" selected="selected">Select Flavor</option>
<option value="Carrot" >Carrot</option>
<option value="Chocolate" >Chocolate</option>
<option value="Banana" >Banana</option>
<option value="Red Velvet" >Red Velvet</option>
<option value="Strawberry" >Strawberry</option>
<option value="Vanilla" >Vanilla</option>
<option value="Combo" >Combo</option>
</select>
<span class="error">*<?php echo $flavorcake;?></span>
<h4>Select Fillings:</h4>
<label><input type="checkbox" name="Filling[]" value="Cream"/>Cream</label><br>
<label><input type="checkbox" name="Filling[]" value="Fudge"/>Fudge</label><br>
<label><input type="checkbox" name="Filling[]" value="Ganache"/>Ganache</label><br>
<label><input type="checkbox" name="Filling[]" value="Hazelnut"/>Hazelnut</label><br>
<label><input type="checkbox" name="Filling[]" value="Mousse"/>Mousse</label><br>
<label><input type="checkbox" name="Filling[]" value="Pudding"/>Pudding</label><br>
<span class="error">*<?php echo $fill;?></span>
</fieldset>
</div>
<div class="cont_order">
<fieldset>
<legend>Contact Details</legend>
<label for="name">Name</label><br>
<input type="text" name="name" id="name"><span class="error">*<?php echo $nameErr;?></span>
<br>
<label for="address">Address</label><br>
<input type="text" name="address" id="address"><span class="error">*<?php echo $addErr;?></span>
<br>
<label for="phonenumber">Phone Number</label><br>
<input type="text" name="phone" id="phone"><span class="error">*<?php echo $phoneErr;?></span><br>
</fieldset>
<input type="submit" name="submitted" id="submit" value="Submit"/>
</div>
</form>
<div class="cont_order">
<?php
echo $name.'<br>';
echo $address.'<br>';
echo $phone.'<br>';
echo $rcake.'<br>';
echo $cakeflavor.'<br>';
echo $fillr.'<br>';
?>
</div>
</div>
</body>
</html>
You can do this:
var_dump($_POST['Filling']);
Or just this:
<?php
if(!empty($_POST['Filling'])) {
foreach($_POST['Filling'] as $check) {
echo $check;
}
}
?>
Tell me if it works =)
Fact is, you accept a list for filling.
In your code you do this :
foreach($z as $item){
$fillr=$item;
}
Replace it by :
$fillr = '';
foreach($z as $item){
$fillr .= '- ' . $item . '<br/>';
}
It should work better.
For comment :
#so let's say $z is an array :
$z = [1,2,3,4];
#then you say, for each element of the array as you will call $item, I do something
foreach($z as $item){
$fillr=$item; #here you say : for each element of $z (1,2,3,4), I put this value into $fillr.
}
#so let's do the loop together.
# First pass, $item == 1, so $fillr == 1.
# Second pass, $item == 2, so $fillr == 2.
# ...
# Last pass, $item == 4, so $fillr == 4.
# so then when you show $fillr it's the last item of the list (here 4).
# using PHP, .= means concatenate.
# for instance :
$a = "hello ";
$a .= "world";
echo $a;
> hello world
So basically, what I'm doing is :
Having an empty string I'll call $fillr.
For every element of the list,
Append "the_element plus a <br/>" to $fillr
so then when you output $fillr it looks sexy.
Do you get it bud?
I have written a page that displays a load of data from MySQL database and all works perfect EXCEPT that when i click the Home link (the title of the page) it logs out and i need to log back in, im probably missing something stupid or not doing something i need, code below
<?php
session_start();
?><title>Vend365 Monitor (Beta test)</title>
<h1><u>Vend 365 online monitor (Beta test)<p></p></u></h3>
<?php
require_once ("V365Connect.php");
//Following if 'update' is clicked
if (isset($_POST['lastseen'])){?><p>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 1px;
text-align: left;
}
</style>
<h1>Vend 'Last Seen' times: Page loaded at <?php echo date("d/m/Y G:i:s"); ?></h1>
<?php
$result1 = mysql_query("SELECT distinct customer FROM vends order by customer") or die(mysql_error());
while($row = mysql_fetch_assoc($result1))
{ echo '<table><th>';
?><font size = "5">Customer - '<?php echo $row[customer];?>'</font><?php
echo '</th>';
$result2 = mysql_query("SELECT * FROM vends where customer ='".$row[customer]."'") or die(mysql_error());
while($row1 = mysql_fetch_assoc($result2))
{
echo '<tr><td>';
?>Machine <b>'<?php echo $row1[machine];?>'</b> last seen online at <b>'<?php echo $row1[lastseen];?>'</b> running version <b>'<?php echo $row1[myversion];?>'</b><?php
$today = date("d/m/Y G:i:s");
$lastseentime = $row1[lastseen];
$diff = $today-$lastseentime;
if ($diff == "1"){
?><b> <font color = "red"> -- Last seen online yesterday</font></b> <?php ;}
if ($diff > "1"){
?> <b><font color = "red"> -- Last seen online BEFORE yesterday</font></b> <?php ;}
echo '</td></tr><p>' ;
}
}?></table>
<?php
}else{
if (isset($_POST['update'])){
if ($_POST['checkbox']=='checked'){
$isalive = 1;
} else {
$isalive = 0;
}
if ($_POST['checkbox1']=='checked'){
$hb800 = 1;
} else {
$hb800 = 0;
}
if ($_POST['checkbox2']=='checked'){
$hb1100 = 1;
} else {
$hb1100 = 0;
}
if ($_POST['checkbox3']=='checked'){
$hb1400 = 1;
} else {
$hb1400 = 0;
}
if ($_POST['checkbox4']=='checked'){
$hb1700 = 1;
} else {
$hb1700 = 0;
}
if ($_POST['checkbox5']=='checked'){
$gcmreboot = 1;
} else {
$gcmreboot = 0;
}
if ($_POST['checkbox6']=='checked'){
$emailreboot = 1;
} else {
$emailreboot = 0;
}
if ($_POST['checkbox7']=='checked'){
$hbgcm = 1;
} else {
$hbgcm = 0;
}
if ($_POST['checkbox8']=='checked'){
$hbemail = 1;
} else {
$hbemail = 0;
}
if ($_POST['checkbox9']=='checked'){
$edigcm = 1;
} else {
$edigcm = 0;
}
if ($_POST['checkbox10']=='checked'){
$ediemail = 1;
} else {
$ediemail = 0;
}
if ($_POST['checkbox11']=='checked'){
$reportgcm = 1;
} else {
$reportgcm = 0;
}
if ($_POST['checkbox12']=='checked'){
$reportemail = 1;
} else {
$reportemail = 0;
}
if ($_POST['checkbox13']=='checked'){
$pingmailgcm = 1;
} else {
$pingmailgcm = 0;
}
if ($_POST['checkbox14']=='checked'){
$pingmailemail = 1;
} else {
$pingmailemail = 0;
}
if ($_POST['checkbox15']=='checked'){
$internetgcm = 1;
} else {
$internetgcm = 0;
}
if ($_POST['checkbox16']=='checked'){
$internetemail= 1;
} else {
$internetemail = 0;
}
if ($_POST['checkbox17']=='checked'){
$sqlgcm = 1;
} else {
$sqlgcm = 0;
}
if ($_POST['checkbox18']=='checked'){
$sqlemail = 1;
} else {
$sqlemail = 0;
}
if ($_POST['checkbox19']=='checked'){
$backupgcm = 1;
} else {
$backupgcm = 0;
}
if ($_POST['checkbox20']=='checked'){
$backupemail = 1;
} else {
$backupemail = 0;
}
$sqlupdate = "update vends set isalive='".$isalive."',customer='".$_POST['customer']."',machine='".$_POST['machine']."',mailserver='".$_POST['smtp']."',emails='".$_POST['emails']."',gcm='".$_POST['gcm']."',hb800='".$hb800."',hb1100='".$hb1100."',hb1400='".$hb1400."',hb1700='".$hb1700."',sqlserver='".$_POST['sqlserver']."',sqlport='".$_POST['sqlport']."',sqlinstance='".$_POST['sqlinstance']."',sqldatabase='".$_POST['sqldatabase']."',sqlname='".$_POST['sqlname']."',sqlpassword='".$_POST['sqlpassword']."',rebootgcm='".$gcmreboot."',rebootemail='".$emailreboot."',hbgcm='".$hbgcm."',hbemail='".$hbemail."',edigcm='".$edigcm."',ediemail='".$ediemail."',reportgcm='".$reportgcm."',reportemail='".$reportemail."',mailpinggcm='".$pingmailgcm."',mailpingemail='".$pingmailemail."',internetgcm='".$internetgcm."',internetemail='".$internetemail."',sqlgcm='".$sqlgcm."',sqlemail='".$sqlemail."',backupgcm='".$backupgcm."',backupemail='".$backupemail."',lastseen='".$lastseen."' where mac='".$_SESSION['mac']."'";
mysql_query($sqlupdate) or die(mysql_error());?><h1>
--->Customer - <font color = blue><?php echo $_SESSION['customer'];?></font>
<br />
--->Machine - <font color = blue><?php echo $_SESSION['machine'];?></font>
<p>
<?php
echo "Request sent";
}
else
{
//First load screen to select customer when correct details are entered
if (!isset($_POST['update'])){
if (!isset($_POST['customer'])){
if (!isset($_POST['machine'])){
if (isset($_POST['submit'])){
$result = mysql_query("SELECT * FROM users where user='".$_POST['user']."' and pass='".$_POST['pass']."'") or die(mysql_error());
$count = mysql_num_rows($result);
if ($count == 1){
?><p><p> <table style="border:1px solid black;"><tr><td><h1>Welcome '<?php echo $_POST['user'];?>'</td></tr></table><?php
$_SESSION['customer'];
$_SESSION['machine'];
$_SESSION['mac'];
if (!isset($_POST['customer'])) {
if (!isset($_POST['machine'])) {
echo "<h1><form action ='' method='post'>";
echo "Please Select Your Customer<br />";
$result1 = mysql_query("SELECT distinct customer FROM vends order by customer") or die(mysql_error());
echo "<select name='customer'>";
while($row = mysql_fetch_assoc($result1))
{
echo "<option value = '".$row[customer]."'>".$row[customer]."</option>";
}
echo "</select>";
echo "<input type='submit' value='Go'>";
echo "</form>";
echo "";
echo "Show all 'Last Seen' times";
?>
<form method='post'>
<input type='submit' value='Show Last Seen Status' name ='lastseen' />
</form>
<?php
}
}}else {
// If wrong details entered
echo "Sorry, wrong username or password, please go back and try again";
}
} else {
// Following is first time load screen
?>
<!DOCTYPE HTML> <html>
<head>
<link rel="stylesheet" type="text/css" href="style-sign.css">
</head><h1>
<title>Vend 365 Monitor</title>
<body id="body-color">
<div id="Sign-In">
<fieldset style="width:30%">
<legend>LOG-IN HERE</legend>
<form method="POST"> User <br><input type="text" style="font-size: 30px;" name="user" size="20"><br> Password <br><input type="password" style="font-size: 30px;" name="pass" size="20"><br>
<input id="button" type="submit" style="font-size: 30px; "name="submit" value="Log-In"> </form> </fieldset>
</div>
</body>
</html>
<?php
}}}
} else {
}
?>
<?php
// Select a vending machine
if (!isset($_POST['submit'])){
if (isset($_POST['customer'])) {
$example = $_POST['customer'];
$_SESSION['customer'] = $example;
$result2 = mysql_query("SELECT * FROM vends where customer='".$example."'") or die(mysql_error());
?><h1>
<font color = black>--->Customer - <font color = blue><?php
echo $_SESSION['customer'];?><p></font></font><?php
echo "<form action ='' method='post'>";
echo "Please Select Your Machine<br />";
echo "<select name='machine'>";
while($row = mysql_fetch_assoc($result2))
{
echo "<option value = '".$row[machine]."'>".$row[machine]."</option>";
}
echo "</select>";
echo "<input type='submit' value='Go'>";
echo "</form>";
}}
// show all customer/machine info
if (isset($_POST['machine'])) {
$example1 = $_POST['machine'];
$_SESSION['machine'] = $example1;?>
<h1><font color = black>--->Customer - <font color = blue><?php
echo $_SESSION['customer'];?><br /></font></font><br /><font color = black>--->Machine - <font color = blue><?php
echo $_SESSION['machine']; ?><p><?php
$result3 = mysql_query("SELECT * FROM vends where customer='".$_SESSION['customer']."' and machine ='".$_SESSION['machine']."'") or die(mysql_error());
while ($rows = mysql_fetch_assoc($result3))
{
$tag1 = $rows['hb800'];
$checkedstatus1 = '';
if($tag1 == '1')
{
$checkedstatus1 = 'checked';
} else {
$checkedstatus1 = 'unchecked';
}?><font color = black><form method='post'>
0800 Heartbeat check - <input type='checkbox' value='checked' name='checkbox1' <?php echo $checkedstatus1; ?> />
<br /><?php
$tag2 = $rows['hb1100'];
$checkedstatus2 = '';
if($tag2 == '1')
{
$checkedstatus2 = 'checked';
} else {
$checkedstatus2 = 'unchecked';
}?>
1100 Heartbeat check- <input type='checkbox' value='checked' name='checkbox2' <?php echo $checkedstatus2; ?> />
<br />
<?php $tag3 = $rows['hb1400'];
$checkedstatus3 = '';
if($tag3 == '1')
{
$checkedstatus3 = 'checked';
} else {
$checkedstatus3 = 'unchecked';
}?>
1400 Heartbeat check - <input type='checkbox' value='checked' name='checkbox3' <?php echo $checkedstatus3; ?> />
<br />
<?php
$tag4 = $rows['hb1700'];
$checkedstatus4 = '';
if($tag4 == '1')
{
$checkedstatus4 = 'checked';
} else {
$checkedstatus4 = 'unchecked';
}?>
1700 Heartbeat check - <input type='checkbox' value='checked' name='checkbox4' <?php echo $checkedstatus4; ?> /><br />
<?php
$tag5 = $rows['rebootgcm'];
$checkedstatus5 = '';
if($tag5 == '1')
{
$checkedstatus5 = 'checked';
} else {
$checkedstatus5 = 'unchecked';
}?>
Send GCM when rebooted - <input type='checkbox' value='checked' name='checkbox5' <?php echo $checkedstatus5; ?> /><br />
<?php
$tag6 = $rows['rebootemail'];
$checkedstatus6 = '';
if($tag6 == '1')
{
$checkedstatus6 = 'checked';
} else {
$checkedstatus6 = 'unchecked';
}?>
Send email when rebooted - <input type='checkbox' value='checked' name='checkbox6' <?php echo $checkedstatus6; ?> /><br />
<?php
$tag7 = $rows['hbgcm'];
$checkedstatus7 = '';
if($tag7 == '1')
{
$checkedstatus7 = 'checked';
} else {
$checkedstatus7 = 'unchecked';
}?>
Heartbeat check GCM - <input type='checkbox' value='checked' name='checkbox7' <?php echo $checkedstatus7; ?> /><br />
<?php
$tag8 = $rows['hbemail'];
$checkedstatus8 = '';
if($tag8 == '1')
{
$checkedstatus8 = 'checked';
} else {
$checkedstatus8 = 'unchecked';
}?>
Heartbeat check Email - <input type='checkbox' value='checked' name='checkbox8' <?php echo $checkedstatus8; ?> /><br />
<?php
$tag9 = $rows['edigcm'];
$checkedstatus9 = '';
if($tag9 == '1')
{
$checkedstatus9 = 'checked';
} else {
$checkedstatus9 = 'unchecked';
}?>
EDI fail check GCM - <input type='checkbox' value='checked' name='checkbox9' <?php echo $checkedstatus9; ?> /><br />
<?php
$tag10 = $rows['ediemail'];
$checkedstatus10 = '';
if($tag10 == '1')
{
$checkedstatus10 = 'checked';
} else {
$checkedstatus10 = 'unchecked';
}?>
EDI fail check Email - <input type='checkbox' value='checked' name='checkbox10' <?php echo $checkedstatus10; ?> /><br />
<?php
$tag11 = $rows['reportgcm'];
$checkedstatus11 = '';
if($tag11 == '1')
{
$checkedstatus11 = 'checked';
} else {
$checkedstatus11 = 'unchecked';
}?>
Report fail GCM - <input type='checkbox' value='checked' name='checkbox11' <?php echo $checkedstatus11; ?> /><br />
<?php
$tag12 = $rows['reportemail'];
$checkedstatus12 = '';
if($tag12 == '1')
{
$checkedstatus12 = 'checked';
} else {
$checkedstatus12 = 'unchecked';
}?>
Report fail Email - <input type='checkbox' value='checked' name='checkbox12' <?php echo $checkedstatus12; ?> /><br />
<?php
$gcm = $rows[gcm];
$tag13 = $rows['mailpinggcm'];
$checkedstatus13 = '';
if($tag13 == '1')
{
$checkedstatus13 = 'checked';
} else {
$checkedstatus13 = 'unchecked';
}?>
Ping email server GCM - <input type='checkbox' value='checked' name='checkbox13' <?php echo $checkedstatus13; ?> /><br />
<?php
$tag14 = $rows['mailpingemail'];
$checkedstatus14 = '';
if($tag14 == '1')
{
$checkedstatus14 = 'checked';
} else {
$checkedstatus14 = 'unchecked';
}?>
Ping email server Email - <input type='checkbox' value='checked' name='checkbox14' <?php echo $checkedstatus14; ?> /><br />
<?php
$tag15 = $rows['internetgcm'];
$checkedstatus15 = '';
if($tag15 == '1')
{
$checkedstatus15 = 'checked';
} else {
$checkedstatus15 = 'unchecked';
}?>
Ping internet fail GCM - <input type='checkbox' value='checked' name='checkbox15' <?php echo $checkedstatus15; ?> /><br />
<?php
$tag16 = $rows['internetemail'];
$checkedstatus16 = '';
if($tag16 == '1')
{
$checkedstatus16 = 'checked';
} else {
$checkedstatus16 = 'unchecked';
}?>
Ping internet fail email - <input type='checkbox' value='checked' name='checkbox16' <?php echo $checkedstatus16; ?> /><br />
<?php
$tag17 = $rows['sqlgcm'];
$checkedstatus17 = '';
if($tag17 == '1')
{
$checkedstatus17 = 'checked';
} else {
$checkedstatus17 = 'unchecked';
}?>
Failed SQL ping GCM - <input type='checkbox' value='checked' name='checkbox17' <?php echo $checkedstatus17; ?> /><br />
<?php
$tag18 = $rows['sqlemail'];
$checkedstatus18 = '';
if($tag18 == '1')
{
$checkedstatus18 = 'checked';
} else {
$checkedstatus18 = 'unchecked';
}?>
Failed SQL ping email - <input type='checkbox' value='checked' name='checkbox18' <?php echo $checkedstatus18; ?> /><br />
<?php
$tag19 = $rows['backupgcm'];
$checkedstatus19 = '';
if($tag19 == '1')
{
$checkedstatus19 = 'checked';
} else {
$checkedstatus19 = 'unchecked';
}?>
Backup fail GCM - <input type='checkbox' value='checked' name='checkbox19' <?php echo $checkedstatus19; ?> /><br />
<?php
$tag20 = $rows['backupemail'];
$checkedstatus20 = '';
if($tag20 == '1')
{
$checkedstatus20 = 'checked';
} else {
$checkedstatus20 = 'unchecked';
}?>
Backp fail email - <input type='checkbox' value='checked' name='checkbox20' <?php echo $checkedstatus20; ?> /><br />
<u><b><p>Details</b></u><p>
<?php $_SESSION['mac'] = $rows[mac]; ?>
Mac address - '<?php echo $_SESSION['mac']; ?>'<br />
Customer name - '<?php echo $rows[customer]; ?>'<br />
Machine name - '<?php echo $rows[machine]; ?>'<br />
Current version - '<?php echo $rows[myversion]; ?>'<br />
GCM app code - <input type='text' value='<?php echo $gcm; ?>' size=150 rows=4 name='gcm' />......<br />
SMTP server - '<?php echo $rows[mailserver]; ?>'<br />
Email addresses (seperate by commas) - '<?php echo $rows[emails]; ?>'<br /><p>
<u><b>SQL Credentials</b></u><p>
SQL server - '<?php echo $rows[sqlserver]; ?>'<br />
SQL Port - '<?php echo $rows[sqlport]; ?>'<br />
SQL Instance - '<?php echo $rows[sqlinstance] ?>'<br />
SQL Database - '<?php echo $rows[sqldatabase]; ?>'<br />
SQL User name - '<?php echo $rows[sqlname]; ?>'<br />
SQL Password - '<?php echo $rows[sqlpassword]; ?>' <br /><p>
<p>
<u><b>Alive status</u></b><p>
Last seen online - '<?php echo $rows[lastseen]; ?>'<br />
<?php
$tag = $rows['isalive'];
$checkedstatus = '';
if($tag == '1')
{
$checkedstatus = 'checked';
} else {
$checkedstatus = 'unchecked';
}?>
Request 'IsAlive' status - <input type='checkbox' value='checked' name='checkbox' <?php echo $checkedstatus; ?> /> - This will send a GCM and Email if alive.<p>
<input type='submit' value='Update account details' name ='update' /><p>
</form><p>
<?php
}}}}
?>
Well, I just bought a sms api which is created by php. They provide me this 2 lines:
http://fahimit.com/smsapi.php?
user=username&pass=pass&phone=mobile_numer&senderid=sender_name&message=my_message
\well now i'm using a html form to send sms. But after message send it's not showing full sender name and message.
For example if i use "Test Sender" as sender_name and "Test message test message" as my_message then it's only showing First word like: Test as sender_name and Test as my_message. I don't understand why it's not showing full message and sender name
PHP code:
<?php
if(isset($_POST['Submit']) && $_POST['Submit'] == "Send SMS")
{
$write_numer = $_POST['write_number'];
$sender = inputvalid($_POST['sender']);
$type = inputvalid($_POST['type']);
$select_msg = inputvalid($_POST['select_msg']);
$msg = $_POST['txt'];
$length = strlen($msg);
$err = array();
$ip = $_SERVER['REMOTE_ADDR'];
if(isset($write_numer) && isset($sender) && isset($type) && isset($select_msg) && isset($msg))
{
if(empty($write_numer) && empty($sender) && empty($type) && empty($select_msg) && empty($msg))
$err[] = "All field require";
else
{
if(empty($write_numer))
$err[] = "Write your mobile number";
elseif(strlen($write_numer) > 13 || strlen($write_numer) < 13)
$err[] = "Your mobile number format is not correct";
elseif(!is_numeric($write_numer))
$err[] = "Your mobile number format is not correct";
elseif (!preg_match("/^8801(6|5|7|8|9|1)\d{8}/", $write_numer))
$err[] = "Invalid mobile number";
if(empty($sender))
$err[] = "Select sender name";
if(empty($type))
$err[] = "Select your message type";
if(empty($select_msg) && empty($msg))
$err[] = "Select your message";
}
}
//error count
if(!empty($err))
{
echo "<div class='error'>";
foreach($err as $er)
{
echo "<font color=red>$er.</font><br/>";
}
echo "</div>";
echo "<br/>";
}
else
{
$sms = "http://fahimit.com/smsapi.php?user=MYUSERNAME&pass=MYPASS&phone=".$write_numer."&senderid=".$sender."&message=".$msg."";
$sms = file_get_contents($sms);
if($sms)
{
echo "<div class='success'>Successfully sent your message to $write_numer. Thank You.</div>";
$sql = mysql_query("INSERT INTO e_sent_sms VALUES('', '', '', '$write_numer', '$msg', '', '', '$length', '$type', '$sender', '$current_date', '$ip' )");
}
else
{
mysql_error();
}
}
}
?>
HTML CODE:
<form name="frm" method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']) ?>">
<table width="800" border="0" cellspacing="10" cellpadding="0" style="float:left; position:relative;">
<tr>
<td>Write Number</td>
<td><input type="text" name="write_number" placeholder="Write your mobile number" class="td3" value="<?php if(isset($_POST['write_number'])) echo $_POST['write_number']; ?>" /><span style="color:#033;">* Mobile number must start with 8801XXXXXXXXX</span></td>
</tr>
<tr>
<td>Sender</td>
<td><input type="text" name="sender" placeholder="Sender name" class="td3" value="<?php if(isset($_POST['sender'])) echo $_POST['sender']; ?>" /></td>
</tr>
<tr>
<td>Message type</td>
<td>
<select name="type" class="select">
<option value="">--Select--</option>
<option value="5" <?php if(isset($_POST['type']) && $_POST['type'] == "5") echo 'selected = "selected"'; ?>>Text</option>
<option value="1" <?php if(isset($_POST['type']) && $_POST['type'] == "1") echo 'selected = "selected"'; ?>>Flash</option>
<option value="3" <?php if(isset($_POST['type']) && $_POST['type'] == "3") echo 'selected = "selected"'; ?>>Arabic</option>
<option value="2" <?php if(isset($_POST['type']) && $_POST['type'] == "2") echo 'selected = "selected"'; ?>>Unicode</option>
<option value="6" <?php if(isset($_POST['type']) && $_POST['type'] == "6") echo 'selected = "selected"'; ?>>Unicode Flash</option>
<option value="4" <?php if(isset($_POST['type']) && $_POST['type'] == "4") echo 'selected = "selected"'; ?>>Wap Push</option>
</select>
</td>
</tr>
<tr>
<td>Select message</td>
<td>
<select name="select_msg" class="select" id="carDealer">
<option value="">--Select Message--</option>
<?php
$sql = mysql_query("SELECT DISTINCT msg FROM e_sms_draft");
while($res = mysql_fetch_array($sql))
{
$draft = inputvalid($res['msg']);
$draft = stripslashes($draft);
if(isset($_POST['select_msg']) && $_POST['select_msg'] == "$draft")
$sel = 'selected = "selecteds"';
else
$sel = "";
echo "<option value='$draft' $sel>$draft</option>";
}
?>
</select>
</td>
</tr>
<td valign="top">Message</td>
<td><textarea class="textarea2" id="carPark" placeholder="Your message" name="txt" onkeyup="counter(this);"><?php if(isset($_POST['txt'])) echo $_POST['txt']; ?></textarea>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script>
function putIt(e) {
$("#carPark").val(e.target.value);
}
$("#carDealer").on("change", putIt);
</script>
<br/><input type="" name="lbl" style="border:none;"><br/></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="Submit" value="Save SMS" class="view"/>
<input type="submit" name="Submit" value="Send SMS" class="submit"/></td>
</tr>
</table>
</form>
Can you tell me what's wrong in my code ?
You need to urlencode your text before passing it to the URL. Do like this
$sender = urlencode($sender);
$msg = urlencode($msg);
$sms = "http://fahimit.com/smsapi.php?user=MYUSERNAME&pass=MYPASS&phone=".$write_numer."&senderid=".$sender."&message=".$msg."";
Do this for all the variables that you are going to send it to the URL.
My intention is to retrieve data from a database and have created the following functions but receive an undefined function, grades, error message. The code is as follows:
<form action="processor.php" method="post">
<h4>Question # 1</h4>
<p>What grade are you in?</p>
<label class="checkbox"><input type="checkbox" name="grade" value="1"> Freshmen</label>
<label class="checkbox"><input type="checkbox" name="grade" value="2"> Sophomore</label>
<label class="checkbox"><input type="checkbox" name="grade" value="3"> Junior</label>
<label class="checkbox"><input type="checkbox" name="grade" value="4"> Senior</label>
<h4>Question # 2</h4>
<p>What is your current GPA?</p>
<select name="gpa">
<option value="4">3.5 or above</option>
<option value="3">3.0-3.4</option>
<option value="2">2.5-2.9</option>
<option value="1">2.0-2.4</option>
<option value="0">Lower</option>
</select>
<h4>Question # 3</h4>
<p>Where do you excel the most academically?</p>
<select name="school" multiple="multiple">
<option value ="1">Mathematics</option>
<option value ="2">Literature</option>
<option value ="3">History</option>
<option value ="4">Humanities</option>
<option value ="5">Science</option>
</select>
Then the PHP file that processes the form submission:
<?php
require_once('processor.php');
class Processor {
#code
function get_response($id) {
$dsn = "mysql:host=localhost;dbname=user";
$username = "root"; // database username
$password = "stewie12"; // database password
try {
$enter = new PDO($dsn, $username, $password);
$sql = "SELECT response FROM recommendations WHERE id = ? ";
$new_item = $enter->prepare($sql);
$new_item->setFetchmode(PDO::FETCH_ASSOC);
$new_item->execute(array($id));
foreach($new_item as $nw) {
return $nw['response'];
}
} catch (Exception $e) {
echo $e->getMessage();
exit;
}
return "";
}
function GetWeird () {
$santiago="1992";
if ($santiago="1992") {
$id = 1;
} else {
$id = 2;
}
echo $this->get_response($id);
}
function Grades () {
$grade = $_POST['grade'];
if ($grade =="1") {
echo "You're a freshmen";
} elseif ($grade == "2") {
echo "You're a sophomore";
} elseif ($grade == "3") {
echo "You're a junior.";
} elseif ($grade == "4") {
echo "You're a senior.";
} else {
echo "Something is wrong.";
}
}
function Gpa () {
$gpa = $_POST['gpa'];
if ($gpa =="1") {
echo "You strongly need to up your GPA.";
} elseif ($gpa == "2") {
echo "You're an average student.";
} elseif ($gpa == "3") {
echo "You're an above average student.";
} elseif ($gpa == "4") {
echo "You're an excellent sudent.";
} else {
echo "Something is wrong.";
}
}
function School () {
$school = $_POST['school'];
if ($school =="1") {
echo "You're into Math";
} elseif ($school == "2") {
echo "You're into Lit";
} elseif ($school == "3") {
echo "You're into history.";
} elseif ($school == "4") {
echo "You're into humanities.";
} elseif ($school == "5") {
echo "You're into science.";
} else {
echo "Something is wrong.";
}
}
And the view page:
<?php $processor = new Processor(); ?>
<h4>Question # 1</h4>
<p><?php Grades($grade); ?></p>
<h4>Question # 2</h4>
<p><?php Gpa($gpa); ?></p>
<h4>Question # 3</h4>
<p><?php School($school); ?></p>
To access the class function use below code,
You have to use it like this $class_variable->function_name()
<?php $processor = new Processor(); ?>
<h4>Question # 1</h4>
<p><?php $processor->Grades($grade); ?></p>
<h4>Question # 2</h4>
<p><?php $processor->Gpa($gpa); ?></p>
<h4>Question # 3</h4>
<p><?php $processor->School($school); ?></p>