/    Sign up×
Community /Pin to ProfileBookmark

variable not populating

Having an issue with $thisrow not returning a value, i am attempting to do some flash/sql/php guest book stuff and this is somewhat screwing me over on line 47 and 52

SQL table is named Guest with field Name

[code=php]<?php

include (“connect_proj2_gbook.inc”);

$name = $HTTP_POST_VARS[‘userName’];
$location = $HTTP_POST_VARS[‘userLoc’];
$comments = $HTTP_POST_VARS[‘userComm’];

if (isset($name)){
mysql_query(“INSERT INTO Guest(Name,Location,Comments) values (‘$name’,’$location’,’$comments’)”);
}
require_once(‘connectgbooki.inc’);

$link = mysql_connect($mysql[‘host’],
$mysql[‘username’],
$mysql[‘password’]);

mysql_select_db(“clouatre_guestbook”, $link);

$names = “SELECT Name FROM Guest”;
$result = mysql_query($names, $link);

//trouble shooting to make sure $result has a value
while ($query_data = mysql_fetch_row($result)) {
foreach ($query_data as $entry) {
echo $entry.”<br>”;
}
}

echo “test data stops here<br><br><br>”;

if(!result) {
die(“query failed” .mysql_error());
}

$numrows_name = mysql_num_rows($result);
$alldata = “guestcount=”;
$alldata .= $numrows_name;
$alldata .=”&”;

for ($i=1; $i<=$numrows_name; $i++){
$thisrow = mysql_fetch_array($result);
$alldata .=”Name”;
$alldata .=$i;
$alldata .=”=”;
$alldata .=urlencode($thisrow[‘Name’]);
if ($i<$numrows_name) {
$alldata .= “&”;
}
}
echo “this is thisrow”.$thisrow[‘Name’].”<br>”;
echo $alldata;
mysql_close($link);

?>[/code]

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@Phill_PaffordMar 24.2009 — Try something like this
[code=php]
<?php

include ("connect_proj2_gbook.inc");

$name = $HTTP_POST_VARS['userName'];
$location = $HTTP_POST_VARS['userLoc'];
$comments = $HTTP_POST_VARS['userComm'];

if (isset($name)){
// Should validate data before enetring into database
$sql = "INSERT INTO Guest(Name,Location,Comments)
VALUES ('" . $name . "','" . $location . "','" . $comments . "') ";

mysql_query($sql);
}

require_once('connectgbooki.inc');

$link = mysql_connect($mysql['host'],
$mysql['username'],
$mysql['password']);

mysql_select_db("clouatre_guestbook", $link);

$names = "SELECT Name FROM Guest";
$result = mysql_query($names, $link);

//trouble shooting to make sure $result has a value
while ($query_data = mysql_fetch_row($result)) {
foreach ($query_data as $entry) {
echo $entry."<br>";
}
}

echo "test data stops here<br><br><br>";

if(!result) {
die("query failed" .mysql_error());
}

$numrows_name = mysql_num_rows($result);
$alldata = "guestcount=";
$alldata .= $numrows_name;
$alldata .="&";


// Use while instead of for loop
while($thisrow = mysql_fetch_array($result)) {
// Print out the contents of each row into a table
$alldata .="Name";
$alldata .=$i;
$alldata .="=";
$alldata .=urlencode($thisrow['Name']);

echo "this is thisrow".$thisrow['Name']."<br>"; // Testing to see the data

if($i<$numrows_name) {
$alldata .= "&";
}
}

echo $alldata;
mysql_close($link);

?>
[/code]
×

Success!

Help @dethis 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.19,
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,
)...