PDA

View Full Version : Code help



MrPinkPanther
12-04-2009, 08:18 PM
This isnt writing to the database like it should. Can anyone find the problem with it? (I want to use POST with it, not GET)


<?php
require 'includes/connect.php';
if($_GET["method"] === "post") {
$name = addslashes($_POST["name"]);
} else {
$name = addslashes($_GET["name"]);
}

if(empty($name)) {
echo 'No name in variable';
exit;
}
$checkifExists = mysql_query("SELECT COUNT(*) FROM submissions WHERE name = '$name'");
$checkifExists2 = mysql_fetch_array($checkifExists);
if($checkifExists2['COUNT(*)'] === '1') {
echo 'Unable to add, that already exists!';
exit;
}
$addtoDB = mysql_query("INSERT INTO submissions (name, ip, votes) VALUES('$name', '$_SERVER[REMOTE_ADDR]' , '0')");
echo 'Added to database';
?>

Dentafrice
12-04-2009, 08:42 PM
<?php
include "includes/connect.php";

$name = mysql_real_escape_string($_REQUEST["name"]);

if(empty($name)) {
exit("No name in variable.");
}

$check_if_exists = mysql_query("SELECT * FROM `submissions` WHERE `name`='$name'");
$check_if_exists = mysql_num_rows($check_if_exists);

if(!$check_if_exists) {
exit("Unable to add, that already exists!");
}

$ip = $_SERVER["REMOTE_ADDR"];

mysql_query("INSERT INTO `submissions` (name, ip, votes) VALUES('$name', '$ip', '0')") or die(mysql_error());

echo 'Added to database';
?>

MrPinkPanther
12-04-2009, 08:49 PM
<?php
include "includes/connect.php";

$name = mysql_real_escape_string($_REQUEST["name"]);

if(empty($name)) {
exit("No name in variable.");
}

$check_if_exists = mysql_query("SELECT * FROM `submissions` WHERE `name`='$name'");
$check_if_exists = mysql_num_rows($check_if_exists);

if(!$check_if_exists) {
exit("Unable to add, that already exists!");
}

$ip = $_SERVER["REMOTE_ADDR"];

mysql_query("INSERT INTO `submissions` (name, ip, votes) VALUES('$name', '$ip', '0')") or die(mysql_error());

echo 'Added to database';
?>

Wow, thanks caleb. Genious! +Rep

Dentafrice
12-04-2009, 08:52 PM
Wow, thanks caleb. Genious! +Rep
No problem :)

MrPinkPanther
13-04-2009, 09:49 AM
Hmmm, still not working. Are you sure thats getting my variable from POST? It arrives in the form name=John or whatever. My Application is definatly working because its posting name=John or whatever to addtotext.php which is saving it to a text file. My connect.php is right too because its reading from the database using connect.php just not writing to it.

Dentafrice
13-04-2009, 08:04 PM
Is it writing anything to the database?

$_REQUEST gets it from POST, GET, or COOKIE.

Want to hide these adverts? Register an account for free!