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';
?>
<?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';
?>