Hey guys quick question. I normally use mysql_fetch_assoc but I was unable to this time so I used mysql_result. Anyhow the value I want is echoed but when the insert query is used $ip turns up blank. Anyone know why?
$ipcheck="SELECT ip FROM users WHERE username='$user'";
$ipresult = mysql_query($ipcheck);
echo $ip=mysql_result($ipresult,0);
$q = "INSERT INTO banned_users VALUES ('test', 0,'$ip')";
$qresult = mysql_query($q);
mysql_result quick problem...help appreciated
Moderator: General Moderators
-
scarface222
- Forum Contributor
- Posts: 354
- Joined: Thu Mar 26, 2009 8:16 pm
Re: mysql_result quick problem...help appreciated
What is the schema of the banned_users table? What is the datatype of ip field in the users table?
-
scarface222
- Forum Contributor
- Posts: 354
- Joined: Thu Mar 26, 2009 8:16 pm
Re: mysql_result quick problem...help appreciated
when you say schema I take it you mean structure. The headings are as follows username, timestamp, ip in the banned-users table. ip is varchar datatype in both tables.
Re: mysql_result quick problem...help appreciated
I meant exactly 'structure'.
Is this the exact structure? Doesn't the table have a primary key?
Your code works find with this exact structure. Try specifying the column names in the query:
Is this the exact structure? Doesn't the table have a primary key?
Your code works find with this exact structure. Try specifying the column names in the query:
Code: Select all
$q = "INSERT INTO banned_users(username, timestamp, ip) VALUES ('test', 0,'$ip')";-
scarface222
- Forum Contributor
- Posts: 354
- Joined: Thu Mar 26, 2009 8:16 pm
Re: mysql_result quick problem...help appreciated
Yeah that worked man. Thanks appreciate it.
Re: mysql_result quick problem...help appreciated
Use mysql_error().
-
scarface222
- Forum Contributor
- Posts: 354
- Joined: Thu Mar 26, 2009 8:16 pm
Re: mysql_result quick problem...solved
Yeah that is a good practice to get into. I will from now on. Thanks man.
Re: mysql_result quick problem...help appreciated
Oh, sorry, I didnt see your last post saying Darhazer solved it.
But yeah...it's always useful if a query is failing and you don't know what's going on.
But yeah...it's always useful if a query is failing and you don't know what's going on.