todayme Posted March 2, 2007 Share Posted March 2, 2007 I have the following lines of code I need to valuate what is in $data and if it doesnt match the string I need it to exit execution. I am a newbie any ideas? $data = mysql_query("SELECT * FROM _User WHERE Email = '$dbemail' AND Password = '$dbpassword'") or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/40833-authentication-and-an-event-and-if-statment-to-stop-execution/ Share on other sites More sharing options...
itsmeArry Posted March 2, 2007 Share Posted March 2, 2007 $data = mysql_query("SELECT * FROM _User WHERE Email = '$dbemail' AND Password = '$dbpassword'") or die(mysql_error()); $result = mysql_fetch_array($data); if(mysql_num_rows($result) < 1) exit(); Link to comment https://forums.phpfreaks.com/topic/40833-authentication-and-an-event-and-if-statment-to-stop-execution/#findComment-197693 Share on other sites More sharing options...
todayme Posted March 2, 2007 Author Share Posted March 2, 2007 $data = mysql_query("SELECT * FROM _User WHERE Email = '$dbemail' AND Password = '$dbpassword'") or die(mysql_error()); $result = mysql_fetch_array($data); if(mysql_num_rows($result) < 1) exit(); I have tried the mysql_num_rows before but it didnt like it. I just tried your code and got this error. Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/admin/domains/sold.au.com/public_html/test.php on line 27 Link to comment https://forums.phpfreaks.com/topic/40833-authentication-and-an-event-and-if-statment-to-stop-execution/#findComment-197697 Share on other sites More sharing options...
itsmeArry Posted March 2, 2007 Share Posted March 2, 2007 ooops sorry my mistake it should be mysql_num_rows($data) and not mysql_num_rows($result) Link to comment https://forums.phpfreaks.com/topic/40833-authentication-and-an-event-and-if-statment-to-stop-execution/#findComment-197698 Share on other sites More sharing options...
todayme Posted March 2, 2007 Author Share Posted March 2, 2007 ooops sorry my mistake it should be mysql_num_rows($data) and not mysql_num_rows($result) I have the code below it works if authentication fails, but if authentication is okay it doesnt do anything.......... do your if statments have end if in the syntax? I cant see that it does, thats what I know from VB........ I tried elseif = 1 keep going but that doesnt work either ...........any ideas.........by the way thanks heaps for help Link to comment https://forums.phpfreaks.com/topic/40833-authentication-and-an-event-and-if-statment-to-stop-execution/#findComment-197704 Share on other sites More sharing options...
itsmeArry Posted March 2, 2007 Share Posted March 2, 2007 you can use if(mysql_num_rows($result) < 1) exit(); else { /// your code goes here what you want to if there is record in db.... } Link to comment https://forums.phpfreaks.com/topic/40833-authentication-and-an-event-and-if-statment-to-stop-execution/#findComment-197707 Share on other sites More sharing options...
todayme Posted March 2, 2007 Author Share Posted March 2, 2007 you can use if(mysql_num_rows($result) < 1) exit(); else { /// your code goes here what you want to if there is record in db.... } Parse error: syntax error, unexpected T_ELSE in /home/admin/domains/sold.au.com/public_html/test.php on line 33 Sorry to be a pain but any ideas on that the code looks all good to me ........not that that means alot ha ha Link to comment https://forums.phpfreaks.com/topic/40833-authentication-and-an-event-and-if-statment-to-stop-execution/#findComment-197710 Share on other sites More sharing options...
itsmeArry Posted March 2, 2007 Share Posted March 2, 2007 post the code of test.php then I can tell where is the problem Link to comment https://forums.phpfreaks.com/topic/40833-authentication-and-an-event-and-if-statment-to-stop-execution/#findComment-197712 Share on other sites More sharing options...
todayme Posted March 2, 2007 Author Share Posted March 2, 2007 post the code of test.php then I can tell where is the problem <? //set the variables as required $dbhost = "localhost"; $dbuser = "admin_sex"; $dbpass = "sex"; $dbname = "admin_sex"; $dbemail = $_POST['email']; $dbpassword = $_POST['password']; //do not edit this, it connects the script $db = mysql_pconnect($dbhost,$dbuser,$dbpass); mysql_select_db($dbname) or die(mysql_error()); // Collects data from "friends" table //$data = mysql_query("SELECT * FROM _User") $data = mysql_query("SELECT * FROM _User WHERE Email = '$dbemail' AND Password = '$dbpassword'") or die(mysql_error()); $result = mysql_fetch_array($data); if(mysql_num_rows($data) < 1) Print "Authentication Failed"; exit(); elseif { // puts the "friends" info into the $info array $info = mysql_fetch_array( $data ); // Print out the contents of the entry Print "<b>Account ID:</b> ".$info['ID'] . " <br>"; $userid = $info['ID']; Print "<b>Name:</b> ".$info['Name'] . " "; Print "<b>Email:</b> ".$info['Email'] . " "; Print "<b>Password:</b> ".$info['Password'] . " <br>"; unset($info); Print "<br>"; Print "<br>"; // Collects data from "friends" table $data = mysql_query("SELECT * FROM _Leads WHERE LINKID = '$userid'") or die(mysql_error()); // puts the "friends" info into the $info array for($i = 0; $i < 3; $i++) { $info = mysql_fetch_array( $data ); // Print out the contents of the entry Print "<b>ID:</b> ".$info['ID'] . " "; Print "<b>Link ID:</b> ".$info['LINKID'] . " "; Print "<b>Industry:</b> ".$info['Industry'] . " "; Print "<b>Location:</b> ".$info['Location'] . " "; Print "<br>"; } unset($info); mysql_close($db); } ?> Link to comment https://forums.phpfreaks.com/topic/40833-authentication-and-an-event-and-if-statment-to-stop-execution/#findComment-197717 Share on other sites More sharing options...
todayme Posted March 2, 2007 Author Share Posted March 2, 2007 I thought it was else instead of elseif so I tried that but didnt work either Link to comment https://forums.phpfreaks.com/topic/40833-authentication-and-an-event-and-if-statment-to-stop-execution/#findComment-197722 Share on other sites More sharing options...
itsmeArry Posted March 2, 2007 Share Posted March 2, 2007 here is the error if(mysql_num_rows($data) < 1) Print "Authentication Failed"; exit(); use this if(mysql_num_rows($data) < 1) { print "Authentication Failed"; exit(); } Link to comment https://forums.phpfreaks.com/topic/40833-authentication-and-an-event-and-if-statment-to-stop-execution/#findComment-197738 Share on other sites More sharing options...
todayme Posted March 2, 2007 Author Share Posted March 2, 2007 Thanks dude it works well, I better get a book on php maybe php for dummies and learn the beginners syntax........ I just go off what I learned in VB and try to adapt Link to comment https://forums.phpfreaks.com/topic/40833-authentication-and-an-event-and-if-statment-to-stop-execution/#findComment-197748 Share on other sites More sharing options...
itsmeArry Posted March 2, 2007 Share Posted March 2, 2007 its better late than never........ Link to comment https://forums.phpfreaks.com/topic/40833-authentication-and-an-event-and-if-statment-to-stop-execution/#findComment-197754 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.