Jump to content


Photo

SQL Help needed


  • Please log in to reply
16 replies to this topic

#1 marcus

marcus
  • Members
  • PipPipPip
  • Advanced Member
  • 1,842 posts
  • LocationRochester, NY

Posted 07 October 2006 - 03:22 PM

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

};
?>

it doesnt SQL the information

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 07 October 2006 - 03:28 PM

And you got error messages???

Remove the ; 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:

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

Legend has it that reading the manual never killed anyone.
My site

#3 marcus

marcus
  • Members
  • PipPipPip
  • Advanced Member
  • 1,842 posts
  • LocationRochester, NY

Posted 07 October 2006 - 03:32 PM

i'm not getting error messages, it just doesnt wanna sql

now it just echos the smiley

#4 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 07 October 2006 - 04:01 PM

i'm not getting error messages, it just doesnt wanna sql


"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?
Legend has it that reading the manual never killed anyone.
My site

#5 marcus

marcus
  • Members
  • PipPipPip
  • Advanced Member
  • 1,842 posts
  • LocationRochester, NY

Posted 07 October 2006 - 04:25 PM

i'm not listing my database stuff :o

it doesnt want to insert a new row into the database

yes i did

#6 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 07 October 2006 - 04:30 PM

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 your code 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.
Legend has it that reading the manual never killed anyone.
My site

#7 marcus

marcus
  • Members
  • PipPipPip
  • Advanced Member
  • 1,842 posts
  • LocationRochester, NY

Posted 07 October 2006 - 04:34 PM

i'll show the whole code then :P

:)



#8 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 07 October 2006 - 04:36 PM

This has no real meaning:
if(mysql_num_rows)

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

Orio.
Think you're smarty?

(Gone until 20 to November)

#9 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 07 October 2006 - 04:37 PM


Also the input field needs a name and how are you posting this information?
name?
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#10 marcus

marcus
  • Members
  • PipPipPip
  • Advanced Member
  • 1,842 posts
  • LocationRochester, NY

Posted 07 October 2006 - 04:39 PM

Woah, thanks Orio, that works! Thanks alot!

#11 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 07 October 2006 - 04:42 PM

still got no idear about the code theo i have corrected some.?



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

}
?>


Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#12 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 07 October 2006 - 04:43 PM

i'll show the whole code then :P

:)


Thank you. I'll add you to my list of people who would like help.
Legend has it that reading the manual never killed anyone.
My site

#13 marcus

marcus
  • Members
  • PipPipPip
  • Advanced Member
  • 1,842 posts
  • LocationRochester, NY

Posted 07 October 2006 - 04:43 PM

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!

#14 marcus

marcus
  • Members
  • PipPipPip
  • Advanced Member
  • 1,842 posts
  • LocationRochester, NY

Posted 07 October 2006 - 04:44 PM

i'll show the whole code then :P

:)


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


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

#15 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 07 October 2006 - 04:48 PM

This is not any good for any website as an ip chages all the time you got to use the members id ok.


Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#16 marcus

marcus
  • Members
  • PipPipPip
  • Advanced Member
  • 1,842 posts
  • LocationRochester, NY

Posted 07 October 2006 - 04:49 PM

But I've disabled user registration, it's for people who haven't or don't want to register.

#17 marcus

marcus
  • Members
  • PipPipPip
  • Advanced Member
  • 1,842 posts
  • LocationRochester, NY

Posted 07 October 2006 - 04:51 PM

is it possible to do this wtih cookies?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users