Danny620 Posted July 28, 2009 Share Posted July 28, 2009 i have excuted this script and it does what it should do for the first time but when i click it again it should echo tho because the user does exsit in the db echo "<b>Sorry you have allready activeted your profile</b>"; heres the code <?php require_once ('mysqli_connect.php'); $userid = 1; echo $userid; if(isset($_POST['new'])){ // Query the database: $q = "SELECT * FROM construction WHERE user_id = $userid"; $r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc)); if (@mysqli_num_rows($r) == 1) { // A match was made. echo "<b>Sorry you have allready activeted your profile</b>"; }else{ $q = "INSERT INTO construction(user_id, complete, hqlevel, progress ) VALUES ($userid,'0000-00-00 00:00:00',1,0)"; $r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc)); } } ?> <form name="form1" method="post" action=""> <label> <input type="submit" name="new" id="new" value="Activate Space City"> </label> </form> Quote Link to comment https://forums.phpfreaks.com/topic/167818-why-is-this-not-working/ Share on other sites More sharing options...
gevans Posted July 28, 2009 Share Posted July 28, 2009 Do you mean the second time round it should echo "<b>Sorry you have allready activeted your profile</b>"; but doesnt? Quote Link to comment https://forums.phpfreaks.com/topic/167818-why-is-this-not-working/#findComment-885077 Share on other sites More sharing options...
Danny620 Posted July 28, 2009 Author Share Posted July 28, 2009 well it should do that if there is a match in the db Quote Link to comment https://forums.phpfreaks.com/topic/167818-why-is-this-not-working/#findComment-885160 Share on other sites More sharing options...
fooDigi Posted July 28, 2009 Share Posted July 28, 2009 by the looks of your posted code, $userid is always set to 1, so any new user will have the same id... so maybe there are more than 1 rows with that userid, and you are only testing if the record count == 1... maybe try... if (@mysqli_num_rows($r) >= 1) { Quote Link to comment https://forums.phpfreaks.com/topic/167818-why-is-this-not-working/#findComment-885189 Share on other sites More sharing options...
Psycho Posted July 28, 2009 Share Posted July 28, 2009 I think the problem is that the page must load three times to go through a cycle. The first page load will do nothing except display the form since $_POST['new'] is not set. The second page load, after submitting the form, will add the record. Then the third page load, after again submitting the form, will display the error condition. Quote Link to comment https://forums.phpfreaks.com/topic/167818-why-is-this-not-working/#findComment-885235 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.