Page 1 of 1
mysql_result quick problem...help appreciated
Posted: Sun Sep 06, 2009 4:14 pm
by scarface222
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);
Re: mysql_result quick problem...help appreciated
Posted: Sun Sep 06, 2009 4:33 pm
by Darhazer
What is the schema of the banned_users table? What is the datatype of ip field in the users table?
Re: mysql_result quick problem...help appreciated
Posted: Sun Sep 06, 2009 4:41 pm
by scarface222
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
Posted: Sun Sep 06, 2009 4:49 pm
by Darhazer
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:
Code: Select all
$q = "INSERT INTO banned_users(username, timestamp, ip) VALUES ('test', 0,'$ip')";
Re: mysql_result quick problem...help appreciated
Posted: Sun Sep 06, 2009 5:07 pm
by scarface222
Yeah that worked man. Thanks appreciate it.
Re: mysql_result quick problem...help appreciated
Posted: Sun Sep 06, 2009 5:14 pm
by jackpf
Use mysql_error().
Re: mysql_result quick problem...solved
Posted: Sun Sep 06, 2009 5:57 pm
by scarface222
Yeah that is a good practice to get into. I will from now on. Thanks man.
Re: mysql_result quick problem...help appreciated
Posted: Sun Sep 06, 2009 6:10 pm
by jackpf
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.