Jump to content

Recommended Posts

Does this code make sence.......

 

you enter the page the database updates with the last inserted id,

 

it updates with a new number in md5 format.......

 

then you post a number to match the database  via mysql_num_rows

if the number is correct it echos...

 

am i coding the md5 for the query correctly.........

 

am i aslso matching the numbers correctly with mysql_num_rows......

 

 

<?php

// database connection....

$db=mysql_connect("localhost","username","password");
$res=mysql_connect_db("database_name",$db);

// post number....

$number=$_POST['number'];

// manke number rand...

$number=rand(000000,999999);	


// if number there add to database.....
if($number){

//update the database by the last id and make number md5........	

$query="UPDATE sec set number=MD5('$number') WHERE insert_id()";
$result=mysql_query($query);	
}


//if post submit from form.....


if($_POST['submit']){


// post varable $num......

$num=($_POST['num']);


// select varable $num with md5......

    $query2="SELECT * FROM sec WHERE md5($num)='$number'";
$resul2=mysql_query($query2);

//if $num exist	

if(mysql_num_rows($result2)==1){

	// say this...

	echo"Number was there!";

	// else this...

}else{

	echo "Number wasent there!";
}
}
?>


<form method="POST" action=" ">
<br></br>
<?php echo $number; ?>
<br><br>
Type Number
<br><br>
<input type="text" name="num">
<br><br>
<input  type="submit name="submit" value="Submit Form">
</form>

Link to comment
https://forums.phpfreaks.com/topic/93830-help-php-code-mysql_num_rows/
Share on other sites

why dosent this work please cheers..

 

 

it like the while loop not working the rest does but it dosent match correctly...


<?php

// database connection....

$db=mysql_connect("192.168.0.10","xxxxxx","xxxxxxxx");
mysql_select_db("captcha",$db);

// post number....


$number=$_POST['number'];

$id=$_POST['id'];

// manke number rand...

$number=rand(000000,999999);	


// if number there add to database.....
if($number){

$numbers=MD5($number);

//update the database by the last id and make number md5........	

$query="INSERT INTO sec (number) values('$numbers')";
$result=mysql_query($query)or die(mysql_error());	
}




//if post submit from form.....

if($_POST['submit']){
// post varable $num......


$num=MD5($_POST['num']);

// select varable $num with md5......

$query2="SELECT number FROM sec";


$result2=mysql_query($query2);


while($row=mysql_fetch_assoc($result2)){


if($num==$row['number']){


	$v="correct";

}else{

	$v="wrong";
}
}

}

echo $v;
?>

<form method="POST" action=" ">
<br></br>
<?php echo $number; ?>
<br><br>
Type Number
<br><br>
<input type="text" name="num">
<br><br>
<input  type="submit" name="submit" value="Submit Form">
</form>


SOLVED correct way sorry everyone...

 

it was my select query lol

 


<?php

// database connection....

$db=mysql_connect("192.168.0.10","xxx","xxx");
mysql_select_db("captcha",$db);

// post number....


$number=$_POST['number'];


// manke number rand...

$number=rand(000000,999999);	


// if number there add to database.....
if($number){

$numbers=MD5($number);

//update the database by the last id and make number md5........	

$query="INSERT INTO sec (number) values('$numbers')";
$result=mysql_query($query)or die(mysql_error());	
}



//if post submit from form.....

if($_POST['submit']){
// post varable $num......


$num=MD5($_POST['num']);


// select varable $num with md5......

$query2="SELECT * FROM sec where number='$num'";


$result2=mysql_query($query2);


if(mysql_num_rows($result2)==1){


	$v="correct";

}else{

$v="wrong";

  }
}

echo $v;

?>

<form method="POST" action=" ">
<br></br>
<?php echo $number; ?>
<br><br>
Type Number
<br><br>
<input type="text" name="num">
<br><br>
<input  type="submit" name="submit" value="Submit Form">
</form>

deleting data

 

why dosent this work please dosent delete

 

i wont to dalete all the entrys where the date is 30 secounds from now....

<?php
$date=time();
$delete="DELETE from sec WHERE ($date - INTERVAL 30 SECOND)";
$delete_result=mysql_query($delete) or die (mysql_error());
?>

i tried it like this can you show me how thank you.........

<?php
if($number){

$date=$_POST['date'];	

$date=time();	

$numbers=MD5($number);

$query="INSERT INTO sec (number,date) values('$numbers',$date)";
$result=mysql_query($query)or die(mysql_error());	

$delete="DELETE from sec WHERE number='$number' AND ($date - INTERVAL 30 SECOND)";
$delete_result=mysql_query($delete) or die (mysql_error());
echo $delete;
}
?>

isint this suppose to delete all rows except the row

that is more then 30 secounds of date...

 

it dosent work please help............

 

tried everythink now.........

 

<?php

$delete="DELETE from sec WHERE date=('$date' - INTERVAL 30 SECOND)";

$delete_result=mysql_query($delete) or die (mysql_error());

echo $delete;
}
?>

here my database entry how can you delete all entrys by date

less the 30 secounds old...

 

i can not seem to do it.........

 

please help cheers.......

 

        Full Texts  	id 	number                                                  	date
Edit 	Delete 	00003 	9bf8a31d0b17522f141fd28d1c413a6a 	1204377708
Edit 	Delete 	00004 	e69c6f677c3dfa8d5f6c40b27fe2d4a5 	1204377741
Edit 	Delete 	00005 	ac4a8f857f89b0fd3fc2d9d7e1c3bdcd 	1204377786
Edit 	Delete 	00006 	a46e2f747091e6846ab789619b78fc96 	1204377843
Edit 	Delete 	00007 	1cef56366ee324b0576d7dc45d13e151 	1204377923
Edit 	Delete 	00008 	0d8f48b67f3225c201aabb174f406a28 	1204377964

Here all the info for some reason

i can not delete all entrys via the date....

 

i can delete manually setting the date row info or using any other info

but it not deleting as presented.....

 

please help cheers.........

 

i can not use the id so i am stuck.....

 

how do you delete entrys that were just created i thort

you use INTERVAL but it not true so how do you do it.......

 

code

<?php

$s1="SELECT date FROM sec";
$s2=mysql_query($s1);

while($d=mysql_fetch_assoc($s2)){

$delete="DELETE from sec WHERE date=".$d['date']." - INTERVAL 1 SECOND";

$delete_result=mysql_query($delete) or die (mysql_error());

echo "<br>$delete<br>";
}
}
?>

 

result with while loop



DELETE from sec WHERE date='1204377708' - INTERVAL 1 SECOND

DELETE from sec WHERE date='1204377741' - INTERVAL 1 SECOND

DELETE from sec WHERE date='1204377786' - INTERVAL 1 SECOND

DELETE from sec WHERE date='1204377843' - INTERVAL 1 SECOND

DELETE from sec WHERE date='1204377923' - INTERVAL 1 SECOND

DELETE from sec WHERE date='1204377964' - INTERVAL 1 SECOND

DELETE from sec WHERE date='1204378813' - INTERVAL 1 SECOND

DELETE from sec WHERE date='1204378882' - INTERVAL 1 SECOND

DELETE from sec WHERE date='1204379145' - INTERVAL 1 SECOND

 

database

id 	number                                                  	date
Edit 	Delete 	00003 	9bf8a31d0b17522f141fd28d1c413a6a 	1204377708
Edit 	Delete 	00004 	e69c6f677c3dfa8d5f6c40b27fe2d4a5 	1204377741
Edit 	Delete 	00005 	ac4a8f857f89b0fd3fc2d9d7e1c3bdcd 	1204377786
Edit 	Delete 	00006 	a46e2f747091e6846ab789619b78fc96 	1204377843
Edit 	Delete 	00007 	1cef56366ee324b0576d7dc45d13e151 	1204377923
Edit 	Delete 	00008 	0d8f48b67f3225c201aabb174f406a28 	1204377964

finally solved got to add gd now yeeeee har............

 

SOLVED

 

<?php

$db=mysql_connect("localhost","root","password");
mysql_select_db("database",$db);

$number=$_POST['number'];

$number=rand(000000,999999);	

if($number){

$numbers=MD5($number);

$query="INSERT INTO sec (number,date) values('$numbers')";
$result=mysql_query($query)or die(mysql_error());	

}

if($_POST['submit']){

$num=MD5($_POST['num']);


$query2="SELECT * FROM sec where number='$num'";


$result2=mysql_query($query2);


if(mysql_num_rows($result2)==1){

// get rid off this varable $v in real life situation....

$v="correct";


$delete1="DELETE from sec WHERE number='$num'";

$delete_result1=mysql_query($delete1) or die (mysql_error());


// add your page name.php here to let user login.....	

//header("location: http://");  	

}else{

// get rid off this varable $v in real life situation....

$v="wrong";

$delete2="DELETE from sec";

$delete_result2=mysql_query($delete2) or die (mysql_error());

// add your page name.php here	

header("location: http://");   
     
}
}

// get rid off this varable $v in real life situation....

echo $v;

?>

<form method="POST" action=" ">

<br></br>

<?php echo $number; ?>

<br><br>

Type Number

<br><br>

<input type="text" name="num">

<br><br>

<input  type="submit" name="submit" value="Submit Form">

</form>

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.