Jump to content

Custum PHP error help


pratkal

Recommended Posts

Hi guys need help again :)code first

<?phpinclude 'config.php';$con = mysql_connect("$dbhost","$dbuser","$dbpass");if (!$con) {	echo "Unable to connect to DB: " . mysql_error();	exit;}mysql_select_db("$dbname");if (!mysql_select_db("$dbname")) {	echo "Unable to select mydbname: " . mysql_error();	exit;}$activate = $_GET["act"];echo $activate;$sql = "UPDATE userSET STATUS='2', activate ='0'WHERE activate ={$activate}  ";$result = mysql_query($sql);if (!$result) {	echo "There was a Problem activating your account if you think its by mistake please email the error code to email $adminemail " . "<BR>" . mysql_error();;	exit;}else{	echo " account is activated now you can now login  continue to login page "; echo '<META HTTP-EQUIV="Refresh" Content="10; URL=index.php">';  }?>

this code work fine but i want to add a feature where if no mysql feild found where activation code is found then a message come No activation code found or account already activate how to do this

Link to comment
Share on other sites

error come new code

<?phpinclude 'config.php';$con = mysql_connect("$dbhost","$dbuser","$dbpass");if (!$con) {	echo "Unable to connect to DB: " . mysql_error();	exit;}mysql_select_db("$dbname");if (!mysql_select_db("$dbname")) {	echo "Unable to select mydbname: " . mysql_error();	exit;}$activate = $_GET["act"];echo $activate;$sql = "UPDATE userSET STATUS='1', activate ='0'WHERE activate ={$activate}  ";$result = mysql_query($sql);if(mysql_num_rows($result)){		echo " account is activated now you can now login  continue to login page "; echo '<META HTTP-EQUIV="Refresh" Content="25; URL=index.php">';  }else{echo " there was an issue activating your account either activation code $act is not valid or account already activated";}?>

errorWarning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/goaddwor/public_html/mytest/activate.php on line 21

Link to comment
Share on other sites

you need to use mysql_affected_rows() to determine the affected rows in the case of UPDATE,REPLACE,INSERT,DEELTEmysql_num_rows() return the number of rows from SELECT,EXPLAIN,SHOW..etcif you pass UPDATE in mysql_query, it does not return resultset resource it will return true or false.more details herehttp://php.net/function.mysql_queryhttp://php.net/function.mysql_num_rows

Link to comment
Share on other sites

mysql num rows didnt worked as i am not looking for result i am editing it the correct solution was http://in.php.net/manual/en/function.mysql-affected-rows.phpanyways thanks birbal

<?phpinclude 'config.php';$con = mysql_connect("$dbhost","$dbuser","$dbpass");if (!$con) {	echo "Unable to connect to DB: " . mysql_error();	exit;}mysql_select_db("$dbname");if (!mysql_select_db("$dbname")) {	echo "Unable to select mydbname: " . mysql_error();	exit;}$activate = $_GET["act"];echo $activate;$sql = "UPDATE userSET STATUS='1', activate ='0'WHERE activate ={$activate}  ";$result = mysql_query($sql);$row=mysql_affected_rows();if($row=='0'){	echo " there was an issue activating your account either activation code $act is not valid or account already activated";}else{		echo " account is activated now you can now login  continue to login page "; 		echo '<META HTTP-EQUIV="Refresh" Content="25; URL=index.php">';  }?>

Link to comment
Share on other sites

nvm didnt work

<?phpinclude "config.php";$con = mysql_connect("$dbhost","$dbuser","$dbpass");if (!$con)  {  die("Could not connect: " . mysql_error());  }mysql_select_db("$dbname");if (!mysql_select_db("$dbname")) {	echo "Unable to select mydbname: " . mysql_error();	exit;}//login process checker//$username = mysql_real_escape_string($_POST['username']);$password = mysql_real_escape_string($_POST['password']);$npassword = md5($password); $sql = "SELECT * FROM user WHERE username = '$username' AND password = '$npassword' ";$result = mysql_query($sql);if (!$result){	echo "error in ". mysql_error();;	exit;}$row = mysql_fetch_assoc($result);if ($status == '6' ){	echo " you are banned user if you think its a mistake please email the admin $adminemail";	die ();}if ($status == '7'){	echo " Your account is not activated if you think this is a mistake Or your didn't recieved the account activation key please email the admin at $adminemail using the email you used at the time of registration thank you ";$error = '<a href="login.html">Go back</a>';	die ();}if(mysql_num_rows($result)){	session_start(void);  $_SESSION['username'] = htmlspecialchars($username);  $_SESSION['$status'] = $status;  echo ' welcome ' . $username . 'you will be redricted in few secs';  echo '<META HTTP-EQUIV="Refresh" Content="15; URL=index.php">';  }else{  // Invalid username/password  echo '<h1>Wrong username or password</h1>';  echo $error;  exit();}	mysql_close($con);?>

it has 2 issues 1 this error is not going i have done lots of thingWarning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/goaddwor/public_html/mytest/login.php:2) in /home/goaddwor/public_html/mytest/login.php on line 402nd $_SESSION['$status'] = $status; does not store while echo $status work correct

Link to comment
Share on other sites

Make sure your code has nothing before the beginning PHP tag. There is output on line 2 of your file that is causing session_start to fail. Make sure config.php also doesn't have any blank lines or anything else before the PHP tag.

Link to comment
Share on other sites

If it's the same error about not being able to send the header, it's the same solution. The problem is that there is output before the header, and you can't send headers once you've sent output. There's a description about how to read those error messages here:http://w3schools.invisionzone.com/index.ph...ost&p=96607

Link to comment
Share on other sites

If it's the same error about not being able to send the header, it's the same solution. The problem is that there is output before the header, and you can't send headers once you've sent output. There's a description about how to read those error messages here:http://w3schools.invisionzone.com/index.ph...ost&p=96607
ye that was the issue i was echo the status for checking thanks
Link to comment
Share on other sites

ok guys need 1 help morehow to create a script which chose a random photo and echo it which satisfy a condition also when the condition is satisfied it remove 1 credit point from the image store in sql i can do the followingcheck for condition and remove a sql point but how to chose 1 single random image instead of 1 static OR echoing them all images

Link to comment
Share on other sites

How are the image resides? filesystem or database? if database is there any primary key associated with it?

Link to comment
Share on other sites

you could use code similar to below to select 1 photo from many records that meet a condition, then use unique id reference from selected record as birbal suggested, to update credit points.

$sql = "SELECT * FROM mytable WHERE field = 'criteria' ORDER BY RAND() LIMIT 1"

Link to comment
Share on other sites

the logic is same as you use mysql_query() to execute a query you can do that as many times as you want.when you condition match again prepare your UPDATE sql and execute it to add or remove point.

Link to comment
Share on other sites

you would use code similar to below

$sql = "SELECT * FROM mytable WHERE field = 'criteria' ORDER BY RAND() LIMIT 1"$result = mysql_query($sql);$row = mysql_fetch_assoc($result);$rand_id = $row['ID]; // unique id reference of record$credit_value = $row['credit]; //current credit value$new_credit_value = $credit_value -1; //new credit value// now you have all data you require for update you can use $sql again for update SQL statement$sql="UPDATE mytable SET credit='$new_credit_value' WHERE ID=$rand_id";//execute update IF valid $update_now = mysql_query($sql, $con) or die(mysql_error());?>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...