Jump to content

Archived

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

marcus

SQL Help needed

Recommended Posts

[code]
<?php
$ip = $_SERVER[REMOTE_ADDR];
echo "<input type=hidden value='$ip'>";
$connection = mysql_connect(localhost,$dbuser,$dbpass;

$db = mysql_select_db($dbname, $connection);

$query="SELECT * FROM `theme` WHERE `ip`='$ip'";
$result44=mysql_query($query);
if(mysql_num_rows){

echo ":)";

}else
{
$query2 ="INSERT INTO `theme` (`ip` , `theme` ) VALUES ('$ip', '1');";
$sql1888 = mysql_query($query2);

};
?>
[/code]

it doesnt SQL the information

Share this post


Link to post
Share on other sites
And you got error messages???

Remove the [b];[/b] from the closing curly brace.

Let's assume that all of the database connection constants are actually known to your code (otherwise it's never going to work).

Extend your SQL statements so that you see any error messages ... for example:

[code]$sql1888 = mysql_query($query2) or die("Error ". mysql_error(). " with query ". $query2);[/code]

Share this post


Link to post
Share on other sites
i'm not getting error messages, it just doesnt wanna sql

now it just echos the smiley

Share this post


Link to post
Share on other sites
[quote author=mgallforever link=topic=110795.msg448514#msg448514 date=1160235126]
i'm not getting error messages, it just doesnt wanna sql
[/quote]

"doesnt wanna sql" means what exactly?

The code you posted is incomplete. Where are the database connection variables defined?

What is the generated html output?

Did you add the error trapping that I posted - to both your sql calls?

Share this post


Link to post
Share on other sites
i'm not listing my database stuff :o

it doesnt want to insert a new row into the database

yes i did

Share this post


Link to post
Share on other sites
How much help you get depends entirely on how willing you are to share information and how willing 'we' are to make wild guesses.  I don't expect you to actually post your database connection details, but [b]your code[/b] doesn't even show any method of connecting to a database, etc. So perhaps the absence of any database connection variables being defined is why it "doesn't sql anything".

If you want to post a more complete version of what you are presently trying to make work, that would be a giant step in the direction of solving your problem.

Share this post


Link to post
Share on other sites
i'll show the whole code then :P

[code]
:)

[/code]

Share this post


Link to post
Share on other sites
This has no real meaning:
if(mysql_num_rows)

I think you mean:
if(mysql_num_rows($result44) > 0)

Orio.

Share this post


Link to post
Share on other sites

Also the input field needs a name and how are you posting this information?
name?

Share this post


Link to post
Share on other sites
Woah, thanks Orio, that works! Thanks alot!

Share this post


Link to post
Share on other sites
still got no idear about the code theo i have corrected some.?


[code]

<?php
$ip = $_SERVER[REMOTE_ADDR];
echo "<input name='ip' type='hidden' value='$ip'>";
$connection = mysql_connect(localhost,neoblob_users,silver101);

$db = mysql_select_db(neoblob_users, $connection);

$query="SELECT * FROM `theme` WHERE `ip`='$ip'";
$result44=mysql_query($query) or die("Error ". mysql_error(). " with query ". $query);

if(mysql_num_rows($result44)>0){

echo ":";

}else{

$query2 ="INSERT INTO `theme` (`ip` , `theme` ) VALUES ('$ip', '1');";
$sql1888 = mysql_query($query2) or die("Error ". mysql_error(). " with query ". $query2);

}
?>

[/code]

Share this post


Link to post
Share on other sites
[quote author=mgallforever link=topic=110795.msg448540#msg448540 date=1160238896]
i'll show the whole code then :P

[code]
:)

[/code]
[/quote]

Thank you. I'll add you to my list of people who would like help.

Share this post


Link to post
Share on other sites
It doesnt post, it's for a theme, once a new user comes to the website they will automatically be inserted into the database w/ their IP and theme, sooner or later they can change this theme, but it's working now, thanks anyway!

Share this post


Link to post
Share on other sites
[quote author=AndyB link=topic=110795.msg448545#msg448545 date=1160239395]
[quote author=mgallforever link=topic=110795.msg448540#msg448540 date=1160238896]
i'll show the whole code then :P

[code]
:)

[/code]
[/quote]

Thank you. I'll add you to my list of people who would like help.
[/quote]

What do you mean, haha, I only edited it.

Share this post


Link to post
Share on other sites
This is not any good for any website as an ip chages all the time you got to use the members id ok.

Share this post


Link to post
Share on other sites
But I've disabled user registration, it's for people who haven't or don't want to register.

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.