Jump to content

why is this not working


Danny620

Recommended Posts

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>

Link to comment
Share on other sites

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) {

Link to comment
Share on other sites

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.

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.