my portion of code doesnt work [closed] - php

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Improve this question
I am trying to distribute a value into 3 input fields so the sum of all 3 cannot exceed the set dynamic value. I tried it in JSFiddle it works fine. Here is the demo: http://jsfiddle.net/k2QVV/
Here is my code:
<!DOCTYPE html>
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script type="text/javascript">
var
total = parseInt($('#quantityRequired').text()),
inputs = $('input[type="number"]');
inputs
.attr('max', total)
.change(function() {
//Make sure that current value is in range
if($(this).val() > parseInt($(this).attr('max'))) {
$(this).val($(this).attr('max'));
} else if ($(this).val() < parseInt($(this).attr('min'))) {
$(this).val($(this).attr('min'));
}
//Get currently available total
var current = available();
//Now update max on each input
$('input').each(function(indx) {
$(this).attr('max', parseInt($(this).val()) + total - current);
});
});
</script>
</head>
<body>
Quantity Required : <span id='quantityRequired'>20</span><br />
<input type='number' name='val1' min='0' value='0' required /> <br />
<input type='number' name='val2' min='0' value='0' required /> <br />
<input type='number' name='val3' min='0' value='0' required />
</body>
</html>

Your code works on jsfiddle because the jQuery lib is loaded before your code is called.
You should load the library before calling your script, by adding this line:
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
right after:
<meta name="viewport" content="width=device-width, initial-scale=1.0">

Related

PHP session not showing a value [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
<?php
session_start();
?>
<html>
<head>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body>
<div class="pageContainer">
<form action="second.php" class="formLayout" method="post">
<div class="formGroup">
<label>Name:</label>
<input type="text" name="first_name"><br>
<input type="hidden" name="postback" value="true"><br>
</div>
<div class="formGroup">
<label> Car model:</label>
<div class="formElements">
<input type="radio" name="model" value="Mustang">Ford Mustang<br>
<input type="radio" name="model" value="Subaru">Subaru WRX STI<br>
<input type="radio" name="model" value="Corvette">Corvette<br>
</div>
<input type="submit" name="submit">
</form>
<?php
if (isset($_POST['submit'])) {
$_SESSION["first_name"] = $_POST["first_name"];
$_SESSION["model"] = $_POST["model"];
}
?>
</div>
</body>
</html>
I set up my code to set the value of the "first_name" and "model" names into my session variables.
When I try to access the values of the stored variables in the submission page of the form:
<?php
session_start();
?>
<html>
<body>
<?php
echo $_SESSION["first_name"];
echo $_SESSION["model"];
?>
</body>
</html>
I only receive the out of the model value, not the first_name value. I don't understand what I'm doing wrong here.
Let's assume your first file is called first.php. As shown in your <form>, the second one is second.php.
It seems that you are writing the data into the session in the first.php file, but this code will never run because you are submitting your form to second.php and not first.php!
So, move the code that writes the session variables into second.php instead. To test that it really worked, you can create a third.php to display them.
(I'm not sure why see the model set, but I guess it's still there from a previous test you did.)

my php code in form doesn't execute [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
when i'm trying to run my code i come across a blank site and i don't know how to fix it
i guess my calculations aren't working
here's the codes:
<html>
<head>
<meta charset="utf-8">
<title>Kalkulator spalania paliwa</title>
</head>
<body align="center">
<h1>Kalkulator spalania paliwa.</h1><br>
<form action="get_info.php" method="get">
Podaj spalone paliwo: <input type="text" name="sp"> l<br>
Podaj przejechaną odległość: <input type="text" name="km"> km<br>
<input type="submit">
</form>
</body>
and
<html>
<body>
<?php
function spalanie(){
$sp = $_GET["sp"];
$km = $_GET["km"];
$wynik = $sp * 100 / $km;
echo $wynik;
}
?>
</body>
You have defined the function but haven't called it. Call it like this below the function like
spalanie();
beacause your input tag has no value...
<input type="text" name="km" value="km">

PHP Wamp server [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
Hey I have a database that contains information about different countries. I also have a html page where you can submit information about countries. Can someone help me to write a code that says that the information has been stored in the database instead of it just redirecting to a blank page?
Here is my html page where you submit information:
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Sett inn land</title>
</head>
<body>
<form action="geoinn.php" method="get">
Land: <input type="text" name="navn"> <br>
Hovedstad: <input type="text" name="hovedstad"> <br>
Areal: <input type="text" name="areal"> <br>
Folketall: <input type="text" name="folketall"> <br>
<input type="submit" value="Legg inn informasjon">
</form>
</body>
</html>
And here is the page that you are redirected to when you click submit on the other page. This is the page where I want to have a code saying either that "The information has been stored in our database" or that it has not:
<?php
$tjener = "localhost";
$brukernavn = "root";
$passord ="";
$database ="Geografi";
$kobling = mysqli_connect($tjener,$brukernavn,$passord,$database);
$kobling->set_charset("utf8");
?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Geografi</title>
</head>
<body>
<?php
$land = $_GET["navn"];
$hovedstad = $_GET["hovedstad"];
$areal = $_GET["areal"];
$folketall = $_GET["folketall"];
$sql ="INSERT INTO land (navn,hovedstad, areal, folketall) VALUES('$land','$hovedstad','$areal', '$folketall')";
mysqli_query($kobling, $sql);
mysqli_close($kobling);
?>
</body>
</html>
Add some output and you will get some output. The blank page you get is the page that does the updates. You add the basic HTML page tags but do not output anything inside the <body>
$sql ="INSERT INTO land
(navn,hovedstad, areal, folketall)
VALUES('$land','$hovedstad','$areal', '$folketall')";
$result = mysqli_query($kobling, $sql);
if ( $result === FALSE ) {
echo '<p>FAILED MESSAGE</p>';
} else {
echo '<p>SUCCESS MESSAGE</p>';
}
echo "<p>Land = $land</p>";
echo "<p>hovedstad = $hovedstad</p>";
// and so on
mysqli_close($kobling);
As Jay says,
Your script is at risk for SQL Injection Attacks. Learn about prepared statements for MySQLi.

Why isn't jQuery working? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Ok I can't get this jQuery to work whatsoever! And its so simple! All I want it to do is make the #main div fade in on load.
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="randomizer.js"></script>
<title>
<?php
if (isset($_POST['first']) && isset($_POST['second'])) {
echo "Randomized {$_POST['first']}-{$_POST['second']}";
}
else {
echo "Randomizer";
}
?>
</title>
<link type="text/css" rel="stylesheet" href="randomizer.css" />
<script type="text/javascript" src="randomizer.js"></script>
</head>
<body>
<?php
if (isset($_POST['first']) && isset($_POST['second'])) {
$grabFirst = strip_tags($_POST['first']);
$grabSecond = strip_tags($_POST['second']);
}
?>
<div id="main">
<center><form action="randomizer.php" method="post">
<input type="text" name="first" value="<?php if(isset($grabFirst)){ echo htmlspecialchars($grabFirst); } ?>" placeholder="First Number" /><br />
<input type="text" name="second" value="<?php if(isset($grabSecond)){ echo htmlspecialchars($grabSecond); } ?>" placeholder="Second Number" /><br />
<input type="submit" />
</form>
<?php
if (isset($_POST['first']) && isset($_POST['second'])) {
$grabFirst = strip_tags($_POST['first']);
$grabSecond = strip_tags($_POST['second']);
}
else {
print "Please enter two numbers.\n";
die;
}
if (strlen($grabFirst) < 1 or strlen($grabSecond) < 1) {
print "Please make sure you filled out both feilds.\n";
die;
}
elseif (!is_numeric($grabFirst) && !is_numeric($grabSecond)) {
print "Please make sure you entered two valid numbers.\n";
die;
}
elseif (!is_numeric($grabSecond)) {
print "Please make sure you entered two valid numbers.\n";
die;
}
elseif (!is_numeric($grabFirst)) {
print "Please make sure you entered two valid numbers.\n";
die;
}
else {
}
$rand = rand($grabFirst, $grabSecond);
print "A random number between {$grabFirst} and {$grabSecond} is {$rand}.\n";
?></center>
</div>
</body>
</html>
Heres my jQuery
$(document).ready(function(){
$('#main').fadeTo('slow', 1);
});
If anyone could help, I'd really appreciate it. I've been trying to fix it for like an hour, and I have no luck. I'm just beginning with jQuery and have no experience, maybe its a really dumb error, but I have no idea. Thanks~
You need to include jQuery in your page:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

how to do js and php validation? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I have four text boxes name
textbox1:
textbox2:
textbox3:
textbox3:
I need to validate this field by following some criteria like below :
1.If anyone put value in textbox1,he must forced to put value in textbox2.Otherwise both textbox can be empty.
2.If anyone put value in textbox3,he must forced to put value in textbox4.Otherwise both textbox can be empty.
Above this criteria,how can i make validation.
You can try this.May be it will help you.
first put the css and js library.
<link rel="stylesheet" href="http://www.position-relative.net/creation/formValidator/css/validationEngine.jquery.css" type="text/css"/>
<script src="http://www.position-relative.net/creation/formValidator/js/jquery-1.7.2.min.js" type="text/javascript"></script>
<script src="http://www.position-relative.net/creation/formValidator/js/languages/jquery.validationEngine-en.js" type="text/javascript" charset="utf-8"></script>
<script src="http://www.position-relative.net/creation/formValidator/js/jquery.validationEngine.js" type="text/javascript" charset="utf-8"></script>
this is your js function which will validate your form field while submit the form
<script type="text/javascript">
$(function(){
$("#ckForm").validationEngine();
});
</script>
Now the form
<form action="" method="post" accept-charset="utf-8" id="ckForm">
<input type="text" name="textbox1" id="textbox1" />
<input type="text" name="textbox2" id="textbox2" class="validate[condRequired[textbox1]]" />
<input type="text" name="textbox3" id="textbox3" />
<input type="text" name="textbox4" id="textbox4" class="validate[condRequired[textbox3]]" />
<input type="submit" value="GO" />
</form>
Please let me know if you need any further help.
It's just an example and not a final solution but if you've a few PHP and JS skills it should help you a lot.
PHP:
$Input = new Input();
$Input
->post("username")
->validate(Input::RULE_MINLENGTH, 4)
->validate(Input::RULE_MAXLENGTH, 20)
->post("email")
->validate(Input::RULE_NOT_EMPTY, null)
->validate(Input::RULE_IS_EMAIL, true)
->post("email2")
->validate(Input::RULE_EQUALS, "email")
->post("password")
->validate(Input::RULE_MINLENGTH, 1)
->validate(Input::RULE_MAXLENGTH, 20)
->post("password2")
->validate(Input::RULE_EQUALS, "password")
->post("random_text");
if (empty($_POST)) {
// $_POST is empty, show the template!
$Template->assign("validation_rules", $Input->get_rules_json());
$Template->show("template.tpl");
} else {
if ($Input->submit("post")) {
// everything alright
echo "No errors.";
} else {
echo "Errors: ";
print_r($Input->get_errors());
}
}
Template/JavaScript:
$("#form").ajaxForm({
"beforeSubmit": function() {
// validate
return formValidation($("#form"), '<?php echo $this->validation_rules?>');
}
});
Edit:
Check out this video: http://www.youtube.com/watch?v=Qf6o3MIcAtA
Enjoy!
I think what you are trying to say to me it seems as if you require ajax. See if you can use AJAX or not for fulfilling your requirement.
You can achive this using simple java script function.
function validate()
{
var txtBox1= document.getElementById('textbox1');
var txtBox2= document.getElementById('textbox2');
var txtBox3= document.getElementById('textbox3');
var txtBox4= document.getElementById('textbox3');
if(txtBox1.value!=""&&txtBox2.value=="")
{
alert("Enter a value in text box");
txtBox2.focus();
return;
}
if(txtBox3.value!=""&&txtBox4.value=="")
{
alert("Enter a value in text box");
txtBox4.focus();
return;
}
}
you can call this method onchange of each text box.let me know i answer your question?

Categories