Jump to content
Updating IPB tonight Read more... ×

Archived

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

Deadman2

Checking to see if variable exists

Recommended Posts

Hey, i need some help with this

 

I need my script to be able to check to see if an ip exists before it inserts it into the mysql database any ideas? heres my script.

 

[!--PHP-Head--][div class=\'phptop\']PHP[/div][div class=\'phpmain\'][!--PHP-EHead--]

[span style=\"color:#0000BB\"]<?php

extract [/span][span style=\"color:#007700\"]( [/span][span style=\"color:#0000BB\"]$_POST [/span][span style=\"color:#007700\"]);

[/span][span style=\"color:#0000BB\"]mysql_connect [/span][span style=\"color:#007700\"]( [/span][span style=\"color:#DD0000\"]\'host\'[/span][span style=\"color:#007700\"], [/span][span style=\"color:#DD0000\"]\'user\'[/span][span style=\"color:#007700\"], [/span][span style=\"color:#DD0000\"]\'password\' [/span][span style=\"color:#007700\"]);

[/span][span style=\"color:#0000BB\"]mysql_select_db[/span][span style=\"color:#007700\"]( [/span][span style=\"color:#DD0000\"]\'database\'[/span][span style=\"color:#007700\"]);

[/span][span style=\"color:#0000BB\"]mysql_query [/span][span style=\"color:#007700\"]( [/span][span style=\"color:#DD0000\"]\"INSERT INTO banned VALUES ( \'$ip\', \'$date\',\'$reason\' )\" [/span][span style=\"color:#007700\"]);

[/span][span style=\"color:#0000BB\"]mysql_close [/span][span style=\"color:#007700\"]();

 

echo [/span][span style=\"color:#DD0000\"]\"IP Added\"

[/span][span style=\"color:#0000BB\"]?>[/span]

[/span][!--PHP-Foot--][/div][!--PHP-EFoot--]

 

if the ip had allready been added it would say:

 

"IP Address has allready been banned."

 

but if ip has not been enterd befor the script would insert the ip to the database and say:

 

"IP Added."

 

>.< i need some help!!!

Share this post


Link to post
Share on other sites

ok ive made an "attempt" to make this work and i keep drawing a blank.

 

[!--PHP-Head--][div class=\'phptop\']PHP[/div][div class=\'phpmain\'][!--PHP-EHead--]

[span style=\"color:#0000BB\"]<?php

extract [/span][span style=\"color:#007700\"]( [/span][span style=\"color:#0000BB\"]$_POST [/span][span style=\"color:#007700\"]);

[/span][span style=\"color:#0000BB\"]mysql_connect [/span][span style=\"color:#007700\"]( [/span][span style=\"color:#DD0000\"]\'blah\'[/span][span style=\"color:#007700\"], [/span][span style=\"color:#DD0000\"]\'blah\'[/span][span style=\"color:#007700\"], [/span][span style=\"color:#DD0000\"]\'blah\' [/span][span style=\"color:#007700\"]);

[/span][span style=\"color:#0000BB\"]mysql_select_db[/span][span style=\"color:#007700\"]( [/span][span style=\"color:#DD0000\"]\'blah\'[/span][span style=\"color:#007700\"]);

 

[/span][span style=\"color:#0000BB\"]$ip[/span][span style=\"color:#007700\"]=(isset([/span][span style=\"color:#0000BB\"]$_POST[/span][span style=\"color:#007700\"][[/span][span style=\"color:#DD0000\"]\'ip\'[/span][span style=\"color:#007700\"]]))? [/span][span style=\"color:#0000BB\"]$_POST[/span][span style=\"color:#007700\"][[/span][span style=\"color:#DD0000\"]\'ip\'[/span][span style=\"color:#007700\"]]: [/span][span style=\"color:#DD0000\"]\'\'[/span][span style=\"color:#007700\"];

[/span][span style=\"color:#0000BB\"]$date[/span][span style=\"color:#007700\"]=(isset([/span][span style=\"color:#0000BB\"]$_POST[/span][span style=\"color:#007700\"][[/span][span style=\"color:#DD0000\"]\'date\'[/span][span style=\"color:#007700\"]]))? [/span][span style=\"color:#0000BB\"]$_POST[/span][span style=\"color:#007700\"][[/span][span style=\"color:#DD0000\"]\'date\'[/span][span style=\"color:#007700\"]]: [/span][span style=\"color:#DD0000\"]\'\'[/span][span style=\"color:#007700\"];

[/span][span style=\"color:#0000BB\"]$reason[/span][span style=\"color:#007700\"]=(isset([/span][span style=\"color:#0000BB\"]$_POST[/span][span style=\"color:#007700\"][[/span][span style=\"color:#DD0000\"]\'reason\'[/span][span style=\"color:#007700\"]]))? [/span][span style=\"color:#0000BB\"]$_POST[/span][span style=\"color:#007700\"][[/span][span style=\"color:#DD0000\"]\'reason\'[/span][span style=\"color:#007700\"]]: [/span][span style=\"color:#DD0000\"]\'\'[/span][span style=\"color:#007700\"];

if (empty([/span][span style=\"color:#0000BB\"]$ip[/span][span style=\"color:#007700\"]) || empty([/span][span style=\"color:#0000BB\"]$date[/span][span style=\"color:#007700\"]) || empty([/span][span style=\"color:#0000BB\"]$time[/span][span style=\"color:#007700\"])){

die([/span][span style=\"color:#DD0000\"]\'Please, fill all fields\'[/span][span style=\"color:#007700\"]);

}

if ([/span][span style=\"color:#0000BB\"]mysql_num_rows[/span][span style=\"color:#007700\"]([/span][span style=\"color:#0000BB\"]$result[/span][span style=\"color:#007700\"])>[/span][span style=\"color:#0000BB\"]0[/span][span style=\"color:#007700\"]) {

die([/span][span style=\"color:#DD0000\"]\'This IP Address Is Allready Banned!\'[/span][span style=\"color:#007700\"]);

} else {

[/span][span style=\"color:#0000BB\"]mysql_query [/span][span style=\"color:#007700\"]( [/span][span style=\"color:#DD0000\"]\"INSERT INTO banned VALUES ( \'$ip\', \'$date\',\'$reason\' )\" [/span][span style=\"color:#007700\"]);

[/span][span style=\"color:#0000BB\"]mysql_close [/span][span style=\"color:#007700\"]();

 

echo [/span][span style=\"color:#DD0000\"]\"<center><b>IP Address Added</b></center>\"

[/span][span style=\"color:#007700\"]}

[/span][span style=\"color:#0000BB\"]?>

[/span]

[/span][!--PHP-Foot--][/div][!--PHP-EFoot--]

 

what am i doing wrong? can anyone help fix up this code????

Share this post


Link to post
Share on other sites

here

 

[!--PHP-Head--][div class=\'phptop\']PHP[/div][div class=\'phpmain\'][!--PHP-EHead--]

[span style=\"color:#0000BB\"]<?php

extract [/span][span style=\"color:#007700\"]( [/span][span style=\"color:#0000BB\"]$_POST [/span][span style=\"color:#007700\"]);

[/span][span style=\"color:#0000BB\"]mysql_connect [/span][span style=\"color:#007700\"]( [/span][span style=\"color:#DD0000\"]\'blah\'[/span][span style=\"color:#007700\"], [/span][span style=\"color:#DD0000\"]\'blah\'[/span][span style=\"color:#007700\"], [/span][span style=\"color:#DD0000\"]\'blah\' [/span][span style=\"color:#007700\"]);

[/span][span style=\"color:#0000BB\"]mysql_select_db[/span][span style=\"color:#007700\"]( [/span][span style=\"color:#DD0000\"]\'blah\'[/span][span style=\"color:#007700\"]);

 

[/span][span style=\"color:#0000BB\"]$resultsearch [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#0000BB\"]mysql_query[/span][span style=\"color:#007700\"]([/span][span style=\"color:#DD0000\"]\"SELECT ip FROM banned WHERE ip=\'$ip\'\"[/span][span style=\"color:#007700\"]);

if([/span][span style=\"color:#0000BB\"]mysql_num_rows[/span][span style=\"color:#007700\"]([/span][span style=\"color:#0000BB\"]$resultsearch[/span][span style=\"color:#007700\"]) == [/span][span style=\"color:#0000BB\"]1[/span][span style=\"color:#007700\"]) {

{

echo [/span][span style=\"color:#DD0000\"]\"<center><b>IP Address Allready Banned</b></center>\"

[/span][span style=\"color:#007700\"]} else {

[/span][span style=\"color:#0000BB\"]$result [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#0000BB\"]mysql_query [/span][span style=\"color:#007700\"]( [/span][span style=\"color:#DD0000\"]\"INSERT INTO banned VALUES ( \'$ip\', \'$date\',\'$reason\' )\" [/span][span style=\"color:#007700\"]);

if([/span][span style=\"color:#0000BB\"]$result[/span][span style=\"color:#007700\"]!=[/span][span style=\"color:#0000BB\"]FALSE[/span][span style=\"color:#007700\"])

{

echo [/span][span style=\"color:#DD0000\"]\"<center><b>IP Address Banned!</b></center>\"

[/span][span style=\"color:#007700\"]}

[/span][span style=\"color:#0000BB\"]mysql_close [/span][span style=\"color:#007700\"]();

[/span][span style=\"color:#0000BB\"]?>[/span] [/span][!--PHP-Foot--][/div][!--PHP-EFoot--]

 

i change it abit..

Share this post


Link to post
Share on other sites

w00t after some time ive gotten it to work :)

 

[!--PHP-Head--][div class=\'phptop\']PHP[/div][div class=\'phpmain\'][!--PHP-EHead--]

[span style=\"color:#0000BB\"]<?php

[/span][span style=\"color:#007700\"]include([/span][span style=\"color:#DD0000\"]\'dbconnect.php\'[/span][span style=\"color:#007700\"]);

[/span][span style=\"color:#0000BB\"]?>

[/span]<html>

<head>

<title>Banning System!</title>

<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">

</head>

 

<body>

<form name=\"register\" method=\"post\" action=\"[span style=\"color:#0000BB\"]<?php $php_self ?>[/span]\">

<table width=\"50%\" border=\"0\" cellspacing=\"1\" cellpadding=\"2\">

<tr>

<td>Ip Address:</td>

<td><input name=\"ip\" type=\"text\" id=\"ip\"></td>

</tr>

<tr>

<td>Date:<br>

</td>

<td><input name=\"date\" type=\"text\" id=\"date\"></td>

</tr>

<tr>

<td>Reason:</td>

<td><input name=\"reason\" type=\"text\" id=\"reason\" size=\"38\"></td>

</tr>

<tr>

<td> </td>

<td><input name=\"submit\" type=\"submit\" id=\"submit\" value=\"Submit\"></td>

</tr>

</table>

</form>

[span style=\"color:#0000BB\"]<?php

[/span][span style=\"color:#007700\"]if(isset([/span][span style=\"color:#0000BB\"]$_POST[/span][span style=\"color:#007700\"][[/span][span style=\"color:#DD0000\"]\'submit\'[/span][span style=\"color:#007700\"]])) {

[/span][span style=\"color:#0000BB\"]$ip [/span][span style=\"color:#007700\"]= ([/span][span style=\"color:#0000BB\"]$_POST[/span][span style=\"color:#007700\"][[/span][span style=\"color:#DD0000\"]\'ip\'[/span][span style=\"color:#007700\"]]);

[/span][span style=\"color:#0000BB\"]$date [/span][span style=\"color:#007700\"]= ([/span][span style=\"color:#0000BB\"]$_POST[/span][span style=\"color:#007700\"][[/span][span style=\"color:#DD0000\"]\'date\'[/span][span style=\"color:#007700\"]]);

[/span][span style=\"color:#0000BB\"]$reason [/span][span style=\"color:#007700\"]= ([/span][span style=\"color:#0000BB\"]$_POST[/span][span style=\"color:#007700\"][[/span][span style=\"color:#DD0000\"]\'reason\'[/span][span style=\"color:#007700\"]]);

[/span][span style=\"color:#0000BB\"]$check [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#0000BB\"]mysql_query[/span][span style=\"color:#007700\"]([/span][span style=\"color:#DD0000\"]\"SELECT * FROM banned WHERE ip=\'$ip\'\"[/span][span style=\"color:#007700\"]);

if([/span][span style=\"color:#0000BB\"]mysql_num_rows[/span][span style=\"color:#007700\"]([/span][span style=\"color:#0000BB\"]$check[/span][span style=\"color:#007700\"])==[/span][span style=\"color:#0000BB\"]0[/span][span style=\"color:#007700\"]) {

echo [/span][span style=\"color:#0000BB\"]mysql_error[/span][span style=\"color:#007700\"]();

[/span][span style=\"color:#0000BB\"]mysql_query[/span][span style=\"color:#007700\"]([/span][span style=\"color:#DD0000\"]\"INSERT INTO banned VALUES (\'$ip\',\'$date\',\'$reason\')\"[/span][span style=\"color:#007700\"]);

echo [/span][span style=\"color:#DD0000\"]\'<p>Ip Address Banned!</p>\'[/span][span style=\"color:#007700\"];

}

else {

echo [/span][span style=\"color:#DD0000\"]\"Sorry, but the ip address, $ip has already been banned.\"[/span][span style=\"color:#007700\"];

}

}

[/span][span style=\"color:#0000BB\"]?>

[/span]</body>

</html>

[/span][!--PHP-Foot--][/div][!--PHP-EFoot--]

Share this post


Link to post
Share on other sites

×

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.