my_sql_fetch problem
- leverkusen
- Posts: 69
- Joined: Sun Nov 18, 2012 10:09 pm
- Location: Belgrade
- Contact:
my_sql_fetch problem
I did user profile registration system but when i want to go to profile.php or profile.php?uid=3 i get
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in public_html/core/inc/user.inc.php on line 33
That user does not exist.
Now i dont know, is it a problem with a profile.php code, user,inc.php code or maybe hosting?
Profile.php code
[syntax=php]<?php
include('core/init.inc.php');
$user_info = fetch_user_info($_get['uid']);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>Global Betting</title>
</head>
<body>
<div>
<?php
if ($user_info === false){
echo 'That user does not exist.';
}else{
?>
<h1><?php echo $user_info['website'] ?> <?php echo $user_info['titles']; ?></h1>
<p>Username: <?php echo $user_info['username']; ?></p>
<p>Grad: <?php echo $user_info['grad']; ?></p>
<p>Drzava: <?php echo $user_info['drzava']; ?></p>
<p>Fan of: <?php echo $user_info['fan']; ?></p>
<p>Website: <?php echo $user_info['website']; ?></p>
<p>Titles: <?php echo $user_info['titles']; ?></p>
<p></p>
<?php
}
?>
</div>
</body>
</html>
[/syntax]
User.inc.php code
[syntax=php]<?php
function fetch_users (){
$result = mysql_query('SELECT `userID` AS `id`, `username` AS `username` FROM `users`');
$users = array();
while (($row = mysql_fetch_assoc($result)) != false){
$users[] = $row;
}
return $users;
}
function fetch_user_info($uid){
$uid = (int)$uid;
$sql = "SELECT
`username` AS `username`,
`grad` AS `grad`,
`drzava` AS `drzava',
`fan` AS `fan`,
`Website` AS `Website`,
`Titles` AS `Titles`
FROM users
WHERE `userID` = '$uid'";
$result = mysql_query($sql);
return mysql_fetch_assoc($result);
}
function set_profile_info($grad, $drzava, $fan, $website, $titles){
$grad = mysql_real_escape_string(htmlentities($grad));
$drzava = mysql_real_escape_string(htmlentities($drzava));
$fan = mysql_real_escape_string(htmlentities($fan));
$website = mysql_real_escape_string(htmlentities($website));
$titles = mysql_real_escape_string(htmlentities($titles));
$uid = $_SESSION['uid'];
$sql = "UPDATE users SET
grad='$grad'
drzava='$drzava'
fan='$fan'
website='$website'
titles='$titles'
WHERE UserID = '$uid'";
mysql_query($sql);
}
?>[/syntax]
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in public_html/core/inc/user.inc.php on line 33
That user does not exist.
Now i dont know, is it a problem with a profile.php code, user,inc.php code or maybe hosting?
Profile.php code
[syntax=php]<?php
include('core/init.inc.php');
$user_info = fetch_user_info($_get['uid']);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>Global Betting</title>
</head>
<body>
<div>
<?php
if ($user_info === false){
echo 'That user does not exist.';
}else{
?>
<h1><?php echo $user_info['website'] ?> <?php echo $user_info['titles']; ?></h1>
<p>Username: <?php echo $user_info['username']; ?></p>
<p>Grad: <?php echo $user_info['grad']; ?></p>
<p>Drzava: <?php echo $user_info['drzava']; ?></p>
<p>Fan of: <?php echo $user_info['fan']; ?></p>
<p>Website: <?php echo $user_info['website']; ?></p>
<p>Titles: <?php echo $user_info['titles']; ?></p>
<p></p>
<?php
}
?>
</div>
</body>
</html>
[/syntax]
User.inc.php code
[syntax=php]<?php
function fetch_users (){
$result = mysql_query('SELECT `userID` AS `id`, `username` AS `username` FROM `users`');
$users = array();
while (($row = mysql_fetch_assoc($result)) != false){
$users[] = $row;
}
return $users;
}
function fetch_user_info($uid){
$uid = (int)$uid;
$sql = "SELECT
`username` AS `username`,
`grad` AS `grad`,
`drzava` AS `drzava',
`fan` AS `fan`,
`Website` AS `Website`,
`Titles` AS `Titles`
FROM users
WHERE `userID` = '$uid'";
$result = mysql_query($sql);
return mysql_fetch_assoc($result);
}
function set_profile_info($grad, $drzava, $fan, $website, $titles){
$grad = mysql_real_escape_string(htmlentities($grad));
$drzava = mysql_real_escape_string(htmlentities($drzava));
$fan = mysql_real_escape_string(htmlentities($fan));
$website = mysql_real_escape_string(htmlentities($website));
$titles = mysql_real_escape_string(htmlentities($titles));
$uid = $_SESSION['uid'];
$sql = "UPDATE users SET
grad='$grad'
drzava='$drzava'
fan='$fan'
website='$website'
titles='$titles'
WHERE UserID = '$uid'";
mysql_query($sql);
}
?>[/syntax]
-
- Posts: 205
- Joined: Mon Jul 09, 2012 11:13 pm
Re: my_sql_fetch problem
There is most likely a problem with your query. Add [syntax=php]echo mysql_error();[/syntax]
<?php while(!$succeed = try()); ?>
- leverkusen
- Posts: 69
- Joined: Sun Nov 18, 2012 10:09 pm
- Location: Belgrade
- Contact:
Re: my_sql_fetch problem
hmm reply on this post again plz i didnt understand in which of these two scripts to add (i guesss user.inc.php) and what to add?Echo only or $succeed too?
- leverkusen
- Posts: 69
- Joined: Sun Nov 18, 2012 10:09 pm
- Location: Belgrade
- Contact:
Re: my_sql_fetch problem
ohh yea i get echo 'That user does not exist' but exists mhm
Re: my_sql_fetch problem
leverkusen wrote:ohh yea i get echo 'That user does not exist' but exists mhm
That is a result of the failing query so don't worry about that for now.
If you add the echo mysql_error() after the query that is failing it will hopefully tell you a bit more about what is wrong, so you want to add it after the mysql_query() line.
- leverkusen
- Posts: 69
- Joined: Sun Nov 18, 2012 10:09 pm
- Location: Belgrade
- Contact:
Re: my_sql_fetch problem
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'fan` AS `fan`, `Website` AS `Website`, ' at line 4
grad and drzava dont have this problem, i have all of these in phpmyadmin Users table
grad and drzava dont have this problem, i have all of these in phpmyadmin Users table
-
- Posts: 205
- Joined: Mon Jul 09, 2012 11:13 pm
Re: my_sql_fetch problem
[syntax=php]`drzava` AS `drzava',[/syntax]
You have an apostrophe after drzava instead of a backtick
You have an apostrophe after drzava instead of a backtick
<?php while(!$succeed = try()); ?>
- leverkusen
- Posts: 69
- Joined: Sun Nov 18, 2012 10:09 pm
- Location: Belgrade
- Contact:
Re: my_sql_fetch problem
That helped alot, the only problem now is that i get registered user in user_list, but when i want to visit his profile i just get echo 'That user does not exist'.
but he is registered :S
should i post register script?
but he is registered :S
should i post register script?
-
- Posts: 205
- Joined: Mon Jul 09, 2012 11:13 pm
Re: my_sql_fetch problem
Has uid been set in the url? Profile.php?uid=1234
<?php while(!$succeed = try()); ?>
- leverkusen
- Posts: 69
- Joined: Sun Nov 18, 2012 10:09 pm
- Location: Belgrade
- Contact:
Re: my_sql_fetch problem
yea i click on user profile page and it is mysite.com/profile.php?uid=4
Re: my_sql_fetch problem
leverkusen wrote:yea i click on user profile page and it is mysite.com/profile.php?uid=4
On this line
[syntax=php]$user_info = fetch_user_info($_get['uid']);[/syntax]
$_get should be $_GET. If you had E_NOTICE level errors on it should have told you about this
- leverkusen
- Posts: 69
- Joined: Sun Nov 18, 2012 10:09 pm
- Location: Belgrade
- Contact:
Re: my_sql_fetch problem
Haha incredible!Tnx alot that was the main problem now it works !
Re: my_sql_fetch problem
leverkusen wrote:Haha incredible!Tnx alot that was the main problem now it works !
No problem Glad you got it sorted.