Jump to content

Doesn't post it in the database :( (HELP PLEASE) ):


Recommended Posts

<?php

$con = mysql_connect("localhost", "root", "");
$name = $_GET['jente_navn'];
$name = mysql_real_escape_string($name);
$ip = $_SERVER['REMOTE_ADDR'];
mysql_select_db("name", $con);

if ( preg_match("/^[^a-z]|[^A-Z]+/i", $name) )
{
die ("Feil: Kan bare bruke gyldige tegn");
}else{
$sql = 'SELECT * FROM banned WHERE name= \'' . $name . '\' OR ip= \'' . $ip . '\'';
$result = mysql_query($sql);

if( mysql_num_rows($result) ){
		print "That Name, or your ip adress is. BANNED!";
}
}

$sql = "INSERT INTO girl ('girl','accepted','ip') VALUES ('$name', '0', '$ip');";

if ( mysql_query($sql, $con) ){
	mysql_close($con);
	header('http://localhost/takk.php');
}else{
	mysql_close($con);
	header('http://localhost/error.php');
}
?>

 

 

I don't get any errors, but it still doesn't post the name in the database, even though the name doesn't exist or ain't banned. :s

<?php
$con = mysql_connect("localhost", "root", "");
$name = $_GET['jente_navn'];
$name = mysql_real_escape_string($name);
$ip = $_SERVER['REMOTE_ADDR'];
mysql_select_db("name", $con);

if ( preg_match("/^[^a-z]|[^A-Z]+/i", $name) )
{
die ("Feil: Kan bare bruke gyldige tegn");
}else{
$cb = 'SELECT * FROM banned WHERE name= \'' . $name . '\' OR ip= \'' . $ip . '\'';
$result = mysql_query($cb);

if( mysql_num_rows($result) ){
		print "That Name, or your ip adress is. BANNED!";
}
}

$sql = "INSERT INTO girl (`girl`,`accepted`,`ip`,`sex`) VALUES ('$name', '0', '$ip', 'Female');";

if ( mysql_query($sql, $con) ){
	mysql_close($con);
	header('http://localhost/takk.php');
}else{
	mysql_close($con);
	header('http://localhost/error.php');
}
?>

still doesn't work. :s

 

Even if I did this:

<?php
$con = mysql_connect("localhost", "root", "");
$name = $_GET['jente_navn'];
$name = mysql_real_escape_string($name);
$ip = $_SERVER['REMOTE_ADDR'];
mysql_select_db("name", $con);

if ( preg_match("/^[^a-z]|[^A-Z]+/i", $name) )
{
die ("Feil: Kan bare bruke gyldige tegn");
}else{
$cb = 'SELECT * FROM banned WHERE name= \'' . $name . '\' OR ip= \'' . $ip . '\'';
$result = mysql_query($cb);

if( mysql_num_rows($result) ){
		print "That Name, or your ip adress is. BANNED!";
}
}

$sql = "INSERT INTO girl (`girl`,`accepted`,`ip`,`sex`) VALUES (`$name`, `0`, `$ip`, `Female`);";

if ( mysql_query($sql, $con) ){
	mysql_close($con);
	header('http://localhost/takk.php');
}else{
	mysql_close($con);
	header('http://localhost/error.php');
}
?>

  • 2 weeks later...

post most recent code

Sure.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Navn-Databasen.NO</title>
</head>
<body>
<?php
$con = mysql_connect("localhost", "root", "");
mysql_select_db("name", $con);
$name = $_GET['jente_navn'];
$name = mysql_real_escape_string($name);
$ip = $_SERVER['REMOTE_ADDR'];

if ( preg_match("/^[^a-z]|[^A-Z]+/i", $name) )
{
die ("Feil: Kan bare bruke gyldige tegn");
}else{
$cb = 'SELECT * FROM banned WHERE name = \'' . $name . '\' OR ip = \'' . $ip . '\'';
$result = mysql_query($cb);

if( mysql_num_rows($result) ){
		print "That Name, or your ip adress is. BANNED!";
}
}
$sql = "INSERT INTO girl (`girl`,`accepted`,`ip`,`sex`) VALUES ('$name', '0', '$ip', 'Female');";
if ( mysql_query($sql, $con) ){
	mysql_close($con);
	header('http://localhost/takk.php');
}else{
	mysql_close($con);
	header('http://localhost/error.php');
}
?>
</body>
</html>

try changing this...

 

$sql = "INSERT INTO girl (`girl`,`accepted`,`ip`,`sex`) VALUES ('$name', '0', '$ip', 'Female');";

 

to this...

 

$sql = "INSERT INTO girl (`girl`,`accepted`,`ip`,`sex`) VALUES ('$name', '0', '$ip', 'Female')";

Still doesn't work. xD

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Navn-Databasen.NO</title>
</head>
<body>
<?php
$con = mysql_connect("localhost", "root", "");
mysql_select_db("name", $con);
$name = $_GET['jente_navn'];
$name = mysql_real_escape_string($name);
$ip = $_SERVER['REMOTE_ADDR'];

if ( preg_match("/^[^a-z]|[^A-Z]+/i", $name) )
{
die ("Feil: Kan bare bruke gyldige tegn");
}else{
$cb = 'SELECT * FROM banned WHERE name = \'' . $name . '\' OR ip = \'' . $ip . '\'';
$result = mysql_query($cb);

if( mysql_num_rows($result) ){
		print "That Name, or your ip adress is. BANNED!";
}
}
$sql = "INSERT INTO girl (`girl`,`accepted`,`ip`,`sex`) VALUES ('$name', '0', '$ip', 'Female')";
if ( mysql_query($sql, $con) ){
	mysql_close($con);
	header('http://localhost/takk.php');
}else{
	mysql_close($con);
	header('http://localhost/error.php');
}
?>
</body>
</html>

Even though I think that might have been an valuable error.

Sure :)

This is what I see.

 

INSERT INTO girl (`girl`,`accepted`,`ip`,`sex`) VALUES ('Angelica', '0', '127.0.0.1', 'Female');

 

That query looks fine to me. When you say "Still doesn't work." -- what exactly do you mean. Is it not putting the data in the database (did you check), or is it not redirecting you? Since you are serving out HTML above this code, the header redirect is NOT going to work.

 

For debugging purposes only: add the following lines to the very beginning of that file (above the DOCTYPE and everything):

 

<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
?>

 

Then add the "die" line below

 

if ( mysql_query($sql, $con) ){
	mysql_close($con);
	header('http://localhost/takk.php');
}else{
	## Add this line for DEBUGGING PURPOSES ONLY
	die(mysql_error() . '<BR>' . $sql);
	mysql_close($con);
	header('http://localhost/error.php');
}

 

Those redirects are never going to work in the middle of the file like that. However, if you move ALL of the PHP above the DOCTYPE, and add exit(); after each header() call you should be very close to what you want.

 

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.