Jump to content

[SOLVED] Warning message when I try to run script


mariocesar

Recommended Posts

hi here is the script, I receiving a warning message:

Warning: mysql_query(): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) in /home/content/C/o/p/Copymail/html/fns.php on line 35

 

Warning: mysql_query(): A link to the server could not be established in /home/content/C/o/p/Copymail/html/fns.php on line 35

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/content/C/o/p/Copymail/html/fns.php on line 37

 

 

<?
function userexist($username){
include('config.php');
$result=mysql_query("Select * from user where uname='$username'") or die(mysql_error());


if(mysql_num_rows($result)>0)

return true;//username exist
else
return false;//username not in db
}

function sendpass($user){
include("config.php");
$result =mysql_query("Select pw from user where uname='$user'") or die(mysql_error());

if(mysql_num_rows($result)>0)
return true;//password exist
else
return false;//password not in db
}

function filledin($form_vars){
foreach($form_vars as $key=> $value)
{
if(!isset($key) || ($value == ''))
return false;
}
return true;
}

function changepw($name){
$query="Select pw from user where uname='$name'" or die(mysql_error());
$result= mysql_query($query); 

if(mysql_num_rows($result)>0){
for ($i=0; $i<mysql_num_rows($result); $i++) {
$row = mysql_fetch_assoc($result);

$pass=$row['pw'];
echo '
<center><form name="form1" method="post" action="forgotten.php">';
echo 'Please fill in the following:<br>';
   
echo ' <table width="445" border="0">';
echo ' <tr>
    <td width="187"><div align="left">Old Password</div></td>
    <td width="242"><input name="oldpass" type="text" size="40" value="'.$pass.'"></td>
  </tr>
  <tr>
    <td><div align="left">New Password  </div></td>
    <td><input name="newpass" type="text" size="40"></td>
  </tr>';
  
echo '</table>';
echo '<br>
  <input name="submit" type="submit" value="Save">';
echo '</form>'; 

}
}
}
function update($newpass,$uname){
if(isset($_POST['submit'])){

if (!filledin($form_vars)){
echo "Please ensure that you have filled in ALL fields.";
exit;
}else{
$newpass=$_POST['newpass'];


}

include "config.php";
$query="Update user SET pw='$newpass' Where uname=$uname Limit 1 ";
$result=mysql_query($query);
if(mysql_affected_rows()==1){
echo "Record number <b>$id</b> has been updated";
}else{
echo "Could not update record number <b>$id</b> because " .mysql_error() . "";
}
}
}
?>

 

here is line 35:

 

$result= mysql_query($query);

 

here is line 37:

 

if(mysql_num_rows($result)>0){

 

thanks.

Link to comment
Share on other sites

assuming your code for actually connecting to the database is in your config.php, if you are calling your changepw function before your other functions that include config.php, no connection is being established, because you are having it be included in your other functions.  Based on the code you have provided, I think if you simply include the config.php inside your changepw function, it should work.... assuming config.php is in fact where you connect to the db.

 

p.s. -

$query="Select pw from user where uname='$name'" or die(mysql_error());
$result= mysql_query($query); 

 

I think you probably meant to do this:

$query="Select pw from user where uname='$name'";
$result= mysql_query($query) or die(mysql_error()); 

 

The way you have it now, the only way a mysql_error will be executed is if the assignment of your query string to your $query variable somehow fails...

Link to comment
Share on other sites

Yes the connection is in config.php here it is:

 

<?php 
$dbhost='test.net';
$dbusername='test';
$dbuserpass='test';
$dbname='test';
// connect to the mysql database server.
mysql_connect ($dbhost, $dbusername, $dbuserpass);
mysql_select_db($dbname) or die('I cannot select the database because: ' . mysql_error());

?>

Link to comment
Share on other sites

yes is allready there, what happen this script comes from  welcome.php when you hit change password gives you all the messages I mentioned before, this is the welcome.php that work together with the script I allready posted before:

 

[<? echo $_SESSION['username'];?>,WELCOME TO MY PAGE<br>
  You have passed all security checks!<br>
  <?
  echo "You've been logged in since" . $_SESSION['time'] . "<br>";
  
  echo '<a href="logout.php">Click here to logout</a>';
  echo "<br>";
  echo '<a href="' .$_SERVER['PHP_SELF']. '?action=change"> Change Password</a>';
  ?>
  <?
  include "fns.php";
  $action=$_GET['action'];
  if($action=="change"){
  changepw($_SESSION['username']);
  update($newpass,$_SESSION['username']);
  }else{
  
  }
    ?>/code]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.