error with $_POST [closed] - php

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 7 years ago.
Improve this question
Well, I have the problem narrowed down to one group of code, and here it is:
<?php
if( isset($_POST['submit'])){
**if($_POST['shortsitename'] == ""){$newshortsitename = $shortsitename;}else{ $newshortsitename = $_POST['shortsitename'];}
if($_POST['organization'] == ""){$neworganization = $organization;}else{$neworganization = $_POST['organization'];}
if($_POST['city'] == ""){$newcity = $city;}else{$newcity = $_POST['city'];}
if($_POST['state'] == ""){$newstate = $state;}else{$newstate = $_POST['state'];}**
$user_lvl = \Fr\LS::getUser("user_lvl");
$updateGroup = \Fr\LS::updateGroupinfo(
array(
"shortsitename" => $newshortsitename,
"organization" => $neworganization,
"city" => $newcity,
"state" => $newstate
), $user_lvl
);
if($updateGroup === "success"){
echo "<label>Success.</label>";
}elseif($updateGroup === false){
echo "<label>Update failed.";
}
?>
Basicly, I have a form that lets user change the information about their organization in a database. However, when I have this code in the site, it returns internal server error 500. When I removed this block of code, the site displays fine. My main question is, is the code that is bolded correct, or did I miss word it?
**Edit: It's not letting me bold the code, but there are "stars" around the code I am talking about.

Your Update failed <label> tag does not have a closing </label> and I think you are missing 2 } on the end. Is $shortsitename defined above?
<?php
if( isset($_POST['submit'])){
//**
if($_POST['shortsitename'] == ""){
$newshortsitename = $shortsitename;
}else{
$newshortsitename = $_POST['shortsitename'];
}
if($_POST['organization'] == ""){
$neworganization = $organization;
}else{
$neworganization = $_POST['organization'];
}
if($_POST['city'] == ""){
$newcity = $city;
}else{
$newcity = $_POST['city'];
}
if($_POST['state'] == ""){
$newstate = $state;}else{
$newstate = $_POST['state'];
}
//**
$user_lvl = \Fr\LS::getUser("user_lvl");
$updateGroup = \Fr\LS::updateGroupinfo(
array(
"shortsitename" => $newshortsitename,
"organization" => $neworganization,
"city" => $newcity,
"state" => $newstate
), $user_lvl
);
if($updateGroup === "success"){
echo "<label>Success.</label>";
}elseif($updateGroup === false){
echo "<label>Update failed.";
}
?>
Above is reformatted version of your code.

Related

How can i make PHP to wait for a variable to be initialized? [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 7 years ago.
Improve this question
I need a PHP block to be run only when a variable is already set, do i need to do something with JavaScript or PHP is able to do it?
Details: My variable is only set when the HTML form is submitted.
if(!empty($_FILES['file']['tmp_name'])){
$caminho = $_FILES['file']['tmp_name'];
$data = new Spreadsheet_Excel_Reader();
$data->setOutputEncoding('CP1251');
$data->read("$caminho");
$conn = mysqli_connect("localhost","root","","pessoas");
mysqli_select_db($conn,"pessoas");
for ($x = 1; $x <= count($data->sheets[0]["cells"]); $x++) {
$nome = $data->sheets[0]["cells"][$x][1];
$matricula = $data->sheets[0]["cells"][$x][2];
$nascimento = $data->sheets[0]["cells"][$x][3];
$celular = $data->sheets[0]["cells"][$x][4];
$sql = "INSERT INTO info (nome,matricula,datanasc,celular)
VALUES ('$nome','$matricula','$nascimento','$celular')";
echo $sql."\n";
mysqli_query($conn, $sql);}
}else {
echo "Selecione um arquivo vĂ¡lido";
}
You can check if the variable was set using the function isset
if(isset($var)){
// do something
}
try using isset() function.
if( isset( $your_variable ) )
{
#your code here...this block works only if '$your_variable' is set..
} else { #do nothing. }

cant get string into a variable [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
so i am pretty new to OOP PHP.
i am trying to get a feel for it,
i am makeing a simple class with 2 functions
one for speed of the car(he try's te see if the speed is a good value)
and one for color of the car(check if the color is vailid)
the error i got:
Catchable fatal error: Object of class Auto could not be converted to string in E:\Site peter+usbweb\root\stage\oef\Auto.php on line 44
here is my code:
<?php
class Auto {
public $mKleur = "";
public $mSpeed = "";
public function speed ($var){
if(is_numeric($var)){
if($var < 0 OR $var == 0)
{
$this->mSpeed = ("$var kmpu rijd die waggie niet eens?!");
}
elseif ($var > 206 OR $var == 206)
{
$$this->mSpeed = ("$var kmpu haalt de auto niet!");
}
elseif($var > 0 AND $var < 206)
{
$$this->mSpeed = ("de auto reed met $var kmpu langs!");
}
}
else
{
$$this->mSpeed = ( " $var dat niet eens een getal....");
}
}
private $sKleur = "";
public function __set( $sAttribuut, $sValue ){
switch( $sAttribuut ){
case 'sKleur':
$aValideKleuren = array('groen', 'rood', 'blauw', 'paars', 'geel', 'wit', 'zwart','grijs','oranje' );
if( !in_array( strtolower( $sValue ), $aValideKleuren ) ){
$$this->mKleur = ("Kleur niet bekend: $sValue");
}
else{
$$this->mKleur = ("kleur is bekent namelijk: $sValue");
}
$this->sKleur = $sValue;
break;
default:
break;
}
}
public function __get( $sAttribuut ){
if( isset( $this->$sAttribuut ) ){
return $this->$sAttribuut;
}
}
public function kk()
{
$message = array('gSpeed' => $this->mSpeed, 'gKleur' => $this->mKleur);
return($message);
}
}
?>
it does work if i use echo but i cant get it te return the value's
anyone know why?
You have a mistake. You put double $ before "this". Change $$this to $this

why isnt this equal function 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
im trying to make something to change password.
nkode is the new password
gkode is the old password
if($_GET[rediger] == 'ja'){
$nkode = md5($_POST[nkode]);
$gkode = md5($_POST[gkode]);
if($nkode !== ''){
if($gkode !== ''){
$nukode = $udskrivprofil[Kodeord];
if($gkode == '$nukode'){
echo "success";
} else {
echo "fail";
}
}
}
echo "<br>$gkode <br> $nukode";
}
both $gkode and $nukode outputs the 100% same, yet i get the fail error... whats wrong?
if($gkode == '$nukode'){
Look at those quotes. You're comparing the contents of $gkode against a string which has the characters $, n, u, etc... in it...
Maybe you wanted
if($gkode == $nukode){
instead?
remove quotes from $nukode variable...
if($_GET[rediger] == 'ja'){
$nkode = md5($_POST['nkode']);
$gkode = md5($_POST['gkode']);
if($nkode !== ''){
if($gkode !== ''){
$nukode = $udskrivprofil[Kodeord];
if($gkode == $nukode){
echo "success";
} else {
echo "fail";
}
}
}
echo "<br>$gkode <br> $nukode";
}

php reading only first line of list [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
I am new at php and I am not sure what I am doing wrong. I am trying to list all the records from a txt file. However, my code is only displaying the first line. How can I get the code to display all the records from the file?
$count = 0;
$soldOut = 0;
$eventFile = fopen("performances.txt", "r");
$event = fgets($eventFile);
while ( feof($eventFile));
{
list ($dateEvent, $performer, $ticketprice, $status) = explode(":", $event);
if($status == "Yes")
{
$status = "Tickets are still available";
$count = $status +1;
}
else
{
$status = "***SOLD OUT***";
$soldOut = $status +1;
}
print("<tr><td>$dateEvent </td>");
print("<td>$performer </td>");
print("<td>$ticketprice </td>");
print("<td>$status</td></tr>");
$event = fgets($eventFile);
}
Pay attention to the docs, you'll notice that your loop should be:
while( !feof($eventFile)) {
$event = fgets($eventFile); // THIS is where you get the current line
// do stuff here
}
you can read file this way. You can find more on this http://us1.php.net/function.file-get-contents
<?php
$data = file_get_contents("performances.txt",FILE_USE_INCLUDE_PATH); //read the file
$convert = explode(":", $data); //create array separate by new line
for ($i=0;$i<count($convert);$i++)
{
echo $convert[$i].', '; //write value by index
}
?>
Looping as instructed at http://www.php.net/manual/en/function.fgets.php
Basically, keep looping until fgets nolonger returns anything, and then check if pointer matches with end of file.
I also suggest you take a look at http://www.php.net/manual/en/function.stream-get-line.php
the comments make a case for performance gains.
$count = $soldOut = 0;
$eventFile = fopen("performances.txt", "r");
if ($eventFile) {
# Keep reading as long as fgets returns content
while ( ($event = fgets($eventFile)) !== false ) {
list ($dateEvent, $performer, $ticketprice, $status) = explode(":", $event);
if($status == "Yes") {
$status = "Tickets are still available";
++$count; # increase count with one
} else {
$status = "***SOLD OUT***";
++$soldOut; # increase soldout with one
}
echo '<tr>',
'<td>',$dateEvent,'</td>',
'<td>',$performer,'</td>',
'<td>',$ticketprice,'</td>',
'<td>',$status,'</td>',
'</tr>';
}
# something went wrong
if (!feof($eventFile)) {
echo "Error: unexpected fgets() fail\n";
}
# remember to close them files
fclose($eventFile);
} else {
# failed to open
}

What is $chk in the following code.I am unable to find it out [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
function addValueToList(elemlist,elemhidden,elemval,elemlab,elemcheck) {
alert(elemlist);
if ($chk($(elemlist)) && $chk($(elemhidden)) && $chk($(elemval)) && $chk($(elemlab)) && $chk($(elemcheck))) {
var value = $(elemval).getProperty('value');
var label = $(elemlab).getProperty('value');
var check = 0;
if (value != '') {
value = value + "||" + label;
if ($(elemcheck).checked) {
value = value + ' [default]';
check = 1;
cleanOptions(elemlist);
}
if (editValue == null) {
addOption(elemlist,value,elemval,elemcheck);
} else {
if ($chk($(editValue))) {
$(editValue).setProperty('value',value);
$(editValue).setText(value);
editValue = null;
}
}
$(elemval).setProperty('value','');
$(elemlab).setProperty('value','');
$(elemcheck).checked = false;
buildHiddenField(elemlist,elemhidden);
} else {
window.alert("Value field cannot be empty !");
}
} else {
window.alert("addValueToList : Problem to retreive values ");
}
}
I am calling this function from my coding. but, when the javascript is being called, js error is being caught. "referenceerror, $chk is not defined". I am unable to post total js file. it is causing problem. What is $chk in this coding? and how to make this error free.... means, have i to define it at top? or how can i get rid of this error?
As far as I know, it was a MooTools function to check whether the value existed (the value was not null, and was not false or equivalent) and it returned true/false depending on it's given value (Whether it was true or not).
However it has been deprecated now, so if you have updated your MooTools library then it probably won't work anymore as they have decided to not create an alternative.
The only other option is to try:
if( ($(elemlist) && $(elemlist).length > 0) && ($(elemhidden) && $(elemhidden).length > 0) && ($(elemval) && $(elemval).length > 0) && ($(elemlab) && $(elemlab).length > 0){
// Some code here
}
It is globally defined anywhere in your page.
like $chk = $; or $chk = jQuery;
you can use $ or jQuery instead of $chk
Hope it will help to understand.

Categories