Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

php coding problems


  • Please log in to reply

#1
sieur_drewry

sieur_drewry

    Member

  • Member
  • PipPip
  • 18 posts
I get this error:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/s7654478/public_html/dmorris/projects/druvianism/includes/profile_info.php on line 6
User Name:
Security Level:

for this code:

<?
$db = mysql_connect("localhost", "xxxxx","xxxxx");
mysql_select_db("xxxxx",$db);

$result = mysql_query("SELECT * FROM login WHERE id=$number",$db);
$myrow = mysql_fetch_array($result);
echo "User Name: ".$myrow["id"];
echo "<br>Security Level: ".$myrow["type"];

?>

site
  • 0

Advertisements


#2
cobhcf

cobhcf

    Member

  • Member
  • PipPip
  • 81 posts
Try this,

$query = "SELECT * FROM login WHERE id=$number";
$result = mysql_query($query);
$nrows = mysql_num_rows($result);
$i=0;
while($i<$nrows)
{
$id = mysql_result($result,$i,"id");
echo "$id";
$security_level = mysql_result($result,$i,"type");
echo "$security_level";
$i = $i+1;
}


Hope this helps,

Cheers! :tazz:
  • 0

#3
sieur_drewry

sieur_drewry

    Member

  • Topic Starter
  • Member
  • PipPip
  • 18 posts
:tazz: nope didnt help

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/s7654478/public_html/dmorris/projects/druvianism/includes/profile_info.php on line 7

This is the error i get, its same error just a different line.
  • 0

#4
cobhcf

cobhcf

    Member

  • Member
  • PipPip
  • 81 posts
hmm try this,

$db=mysql_connect("localhost","xxxxx","xxxxx");

if(!$db)
{ //if database cant be opened
echo "<p><font color=red>Couldn't connect to database</font></p>";
} //if database cant be opened

else
{ //if database can be opened

echo "connected to database";
mysql_select_db("xxxxx");

} //if database can be opened


In the above case, we will know if it is getting connected to the database or not. If it is connecting well (if it says 'conected to database') and still pops out the error you are encountering, try putting another output statement for the select_db statement and see if it is selecting the database properly.

Hope that works.

Cheers! :tazz:
  • 0

#5
bdlt

bdlt

    Member

  • Member
  • PipPipPip
  • 876 posts
if it is connecting to the database(previous post), then you might look at $result. this seems to be the argument that is causing the error. could $result be null or of improper format?
  • 0

#6
sieur_drewry

sieur_drewry

    Member

  • Topic Starter
  • Member
  • PipPip
  • 18 posts
It says connected to database.
  • 0

#7
bdlt

bdlt

    Member

  • Member
  • PipPipPip
  • 876 posts

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource


you might want to look at $result which is passed to mysql_fetch_array() and
$number which is used to define $result

$result = mysql_query("SELECT * FROM login WHERE id=$number",$db);
  • 0

#8
sieur_drewry

sieur_drewry

    Member

  • Topic Starter
  • Member
  • PipPip
  • 18 posts
aye i talked to one of my old coding friends, he helped me out. it turns out i had the link as view.php?id=1 or id=2 etc, and it should have been view.php?number=1 etc

thanks for all the help

i might need some more soon, im making a change password script and right now its changing everyones password :tazz:

Edited by sieur_drewry, 02 May 2005 - 10:14 PM.

  • 0

#9
sieur_drewry

sieur_drewry

    Member

  • Topic Starter
  • Member
  • PipPip
  • 18 posts
I am trying to make a change password script, but it doesnt change the password. Everything else seems to work except that it doesnt change the password to what it is supposed to.

<?php
//connection
$db = mysql_connect("localhost", "xxxxx","xxxx");
mysql_select_db("xxxxx",$db);

//getting info
$old = md5($_POST["old"]);
$new = md5($_POST["new"]);

//cookie
$cookie = $_COOKIE["number"];

//query the db
$sql = mysql_query("SELECT * FROM login WHERE pass = "'. $old .'" AND number = '$cookie' ");

//check if its the right person logged in
if ($cookie == $number)
{

//check if its right old pass
if ( mysql_num_rows($sql) == 0 )
{
die("You entered the wrong old password. <a href=/dmorris/projects/druvianism/change.php>go back</a>");
}

//change password now
$change = "UPDATE login SET pass='$new' WHERE pass='$old' AND id='$id'";
$result = mysql_query($change);
echo "Thank you! Information updated.<a href='http://www.axedio.com/dmorris/projects/druvianism/my/'>back</a>";
}
else
{
echo "Your ID does not much this old password";
}
?>
Here is the form page that goes with this

<form method="post"action="/dmorris/projects/druvianism/my/datain.php">
Old Password: <input type="password" name="old"><br>
New Password: <input type="password" name="new"><br>
<input type="Submit" name="update" value="Update information"></form>
<p><a href="http://www.axedio.co.../">back</a></p>

Edited by sieur_drewry, 04 May 2005 - 12:21 AM.

  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP