/    Sign up×
Community /Pin to ProfileBookmark

Having issues returing data from a database.

The notes and version fields populate, but the rest don’t.

What is not shown because it is in the CSS file:
If the system is online, an online image will display
If the system is offline, an offline image will display
If the system is in maintenence, an exclamation image will display.

Also I’m getting PHP Notice: Undefined variable: shopping_cart on lines 115 & 122

I left the database connection values blank (for security reasons) but in realy time they are there.

Any ideas?

[upl-file uuid=fb4536d3-1fd2-47a8-98a7-45fd88ac619b size=1kB]status-demo.zip[/upl-file]

to post a comment
PHP

8 Comments(s)

Copy linkTweet thisAlerts:
@Matt_DMar 16.2011 — First, there is no defined variable "server_status" which you are checking.

You have defined a varaible called "status".

$status = $_POST['status'];

When de-bugging, personally, I use "echo" to find out what values PHP is seeing. ie:

[CODE]
echo "version: ".$version. " || <br />
status: ".$status." || <br />
helpdesk: ".$helpdesk." || <br />
shopping_cart: ".$shopping_cart." || <br />
backup_server: ".$backup_server." || <br />
notes: ".$notes." || <br />";
[/CODE]


That way you can check & see that you are getting the results you are expecting. Easy to make typing mistakes, so this is good to find them quickly.

Also, PHP, sometimes treats numerical values as text. Therefore, "if ($helpdesk == 0)" may not work but "if ($helpdesk == '0')" can.

make sure that the value is numerical, use things like "intval()" function. It ensures you get only the integer value as well as get rid of any [i]bad stuff[/i] as user could insert.

[CODE]
if(!empty($_POST)){
$version = $_POST['version'];
$status = intval($_POST['status']);
$helpdesk = intval($_POST['helpdesk']);
$shopping_cart = intval($_POST['shopping_cart']);
$backup_server = $_POST['backup_server'];
$notes = $_POST['notes'];
}
[/CODE]


I noticed, you also check for values twice; once to create an icon, second time to add some text. Why not do it in 1 statement?
Copy linkTweet thisAlerts:
@Matt_DMar 16.2011 — First, there is no defined variable "server_status" which you are checking.

You have defined a varaible called "status".

$status = $_POST['status'];

When de-bugging, personally, I use "echo" to find out what values PHP is seeing. ie:

[CODE]
echo "version: ".$version. " || <br />
status: ".$status." || <br />
helpdesk: ".$helpdesk." || <br />
shopping_cart: ".$shopping_cart." || <br />
backup_server: ".$backup_server." || <br />
notes: ".$notes." || <br />";
[/CODE]


That way you can check & see that you are getting the results you are expecting. Easy to make typing mistakes, so this is good to find them quickly.

Also, PHP, sometimes treats numerical values as text. Therefore, "if ($helpdesk == 0)" may not work but "if ($helpdesk == '0')" can.

make sure that the value is numerical, use things like "intval()" function. It ensures you get only the integer value as well as get rid of any [i]bad stuff[/i] as user could insert.

[CODE]
if(!empty($_POST)){
$version = $_POST['version'];
$status = intval($_POST['status']);
$helpdesk = intval($_POST['helpdesk']);
$shopping_cart = intval($_POST['shopping_cart']);
$backup_server = $_POST['backup_server'];
$notes = $_POST['notes'];
}
[/CODE]


I noticed, you also check for values twice; once to create an icon, second time to add some text. Why not do it in 1 statement?
Copy linkTweet thisAlerts:
@comptech520authorMar 16.2011 — Hi,

I did the changes.

It didn't like '0', '1', '2'

I echoed the debugging method you mentioned, and it outputted this:

version: ||

status: ||

helpdesk: ||

shopping_cart: ||

backup_server: ||

notes: ||

Any other ideas?
Copy linkTweet thisAlerts:
@Matt_DMar 18.2011 — It seems your variables are empty ?

add
[CODE]

echo empty($_POST);

[/CODE]


probably will find that it returns true.

If it says false, try echoing [i]$_POST[0][/i] see what data you are getting


Can you add the script which has your form on it
Copy linkTweet thisAlerts:
@comptech520authorMar 18.2011 — Hi,

I added "echo empty($_POST);", it returned "1"

I attached an updated copy of this.

[upl-file uuid=5090db10-48dc-4d3f-aa71-a0a6f2ac9f40 size=1kB]Status_project.zip[/upl-file]
Copy linkTweet thisAlerts:
@corics15Mar 19.2011 — Hi,

I added "echo empty($_POST);", it returned "1"

I attached an updated copy of this.[/QUOTE]


if this is what you're after then insert it after
[code=php]
if($num > 0){
//$row = mysql_fetch_array($result) or die("error");
while($row = mysql_fetch_array($result)) {
$version = $row['version'];
$status = $row['status'];
$helpdesk = $row['helpdesk'];
$shopping_cart = $row['shopping_cart'];
$backup_server = $row['backup_server'];
$notes = $row['notes'];
}
}
[/code]
Copy linkTweet thisAlerts:
@comptech520authorMar 19.2011 — Thanks! That did it.
Copy linkTweet thisAlerts:
@Matt_DMar 19.2011 — Sorry, let me explain.

The $_POST[[i]xxxx[/i]] is GLOBAL variable which stores information that has been sent to the server from the client browser.

the statement [i][COLOR="Navy"]empty($_POST)[/COLOR][/i] has returned a [COLOR="Red"]1[/COLOR] which is [i][COLOR="Red"]TRUE[/COLOR][/i].

Therefore, your script is not receiving any information.

[CODE]
if(!empty($_POST)){ [COLOR="Red"]// is evaluated as FALSE, the rest of the code is therefore ignored [/COLOR]
$version = $_POST['version'];
$status = intval($_POST['status']);
$helpdesk = intval($_POST['helpdesk']);
$shopping_cart = intval($_POST['shopping_cart']);
$backup_server = $_POST['backup_server'];
$notes = $_POST['notes'];
}
[/CODE]


The script you have provided is does not contain the necessary HTML, so I assume you have nother page which submits to Status_project.php.


You need something like this somewhere

[CODE]

<form action="Status_project.php" method="post">

<input type="text" name="version" />
<input type="text" name="status" />
<input type="text" name="helpdesk" />
<input type="text" name="shopping_cart" />
<input type="text" name="backup_server" />
<input type="text" name="notes" />

</form>

[/CODE]



... thats of course if you don't want to do what [i][COLOR="Blue"]corics15[/COLOR][/i] suggests ?
×

Success!

Help @comptech520 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...