mariocesar Posted February 1, 2007 Share Posted February 1, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/36596-solved-warning-message-when-i-try-to-run-script/ Share on other sites More sharing options...
redarrow Posted February 1, 2007 Share Posted February 1, 2007 where the dastabase connection? Quote Link to comment https://forums.phpfreaks.com/topic/36596-solved-warning-message-when-i-try-to-run-script/#findComment-174306 Share on other sites More sharing options...
spfoonnewb Posted February 1, 2007 Share Posted February 1, 2007 That error is sayting that it cannot connect to your database, are database settings in config.php.. and are they correct? Does it include a connect string in config.php? Quote Link to comment https://forums.phpfreaks.com/topic/36596-solved-warning-message-when-i-try-to-run-script/#findComment-174310 Share on other sites More sharing options...
.josh Posted February 1, 2007 Share Posted February 1, 2007 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... Quote Link to comment https://forums.phpfreaks.com/topic/36596-solved-warning-message-when-i-try-to-run-script/#findComment-174316 Share on other sites More sharing options...
mariocesar Posted February 1, 2007 Author Share Posted February 1, 2007 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()); ?> Quote Link to comment https://forums.phpfreaks.com/topic/36596-solved-warning-message-when-i-try-to-run-script/#findComment-174317 Share on other sites More sharing options...
.josh Posted February 1, 2007 Share Posted February 1, 2007 so did you try including your config.php in your changepw function? Quote Link to comment https://forums.phpfreaks.com/topic/36596-solved-warning-message-when-i-try-to-run-script/#findComment-174326 Share on other sites More sharing options...
mariocesar Posted February 1, 2007 Author Share Posted February 1, 2007 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] Quote Link to comment https://forums.phpfreaks.com/topic/36596-solved-warning-message-when-i-try-to-run-script/#findComment-174344 Share on other sites More sharing options...
mariocesar Posted February 1, 2007 Author Share Posted February 1, 2007 Thanks Crayon Violent, I include my config.php in the function, and now is OK. Quote Link to comment https://forums.phpfreaks.com/topic/36596-solved-warning-message-when-i-try-to-run-script/#findComment-174360 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.