I am pretty new to using mysql and variables in php.
I have this code
mysql_query("INSERT INTO `forum_threads` (`name`, `byid`, `cid`,
`content`, `time`, `lastreplied_time`, `lastreplier_id`) VALUES
('{$title}', '{$uid}', '{$cid}', '{$content}', '" . time() . "', '" .
time() . "', '{$uid}');") or die(mysql_error());
In my php file, I want byid
to be the value of id
in my table forum_users
. So can I replace {$uid}
with something that will get the value from forum_users
. Because I don't think {$uid} is working correct.
I found this code
/* Non-existant forum account */ final public function
createForumAccount($uid) {
$getHabboUser = mysql_query("SELECT * FROM
`users` WHERE `id` = '{$uid}' LIMIT 1");
I assume that the function of that code is to get the {$uid}
equal the id
from the users
table, I want to make the {$uid}
to equal the id from the forum_users
table.
Then I found this code:
final public function getUserData($uid, $var) {
if($this->checkForAccount($uid) == true) {
$check = mysql_query("SELECT `{$var}` FROM `forum_users` WHERE `uid` = '{$uid}' LIMIT 1") or die(mysql_error());
return mysql_result($check, 0);
}
}
That code wants the {$uid}
to equal forum_users id
. And that is exactly what I want, but it doesn't equal that, it equals the id
from the users
table instead, I assume it might collide with eachother or something.
How can I solve this? Can I replace {$uid}
in my first code, so byid
is selected instantly from forum_users
? Can I make a new variable that equals forum_users.id
?
First of all this sql query makes no sense. However I am also not sure your question either. If your wanting to change byid
to id
in your table then you must alter the table. But here is a cleaner version of your sql query. try:
mysql_query("INSERT INTO forum_threads SET name=\"".$title."\",byid=\"".$uid."\",cid=\"".$cid."\",content=\"".$content."\",time=\"".time()."\",lastreplied_time=\"".time()."\",lastreplier_id=\"".$uid."\" WHERE id=\"".$uid."\" LIMIT 1") or die("Error: ".mysql_error());
//You Change ID to byid
to change byid to ID
mysql_query("ALTER TABLE `forum_threads` CHANGE `byid` `id` int NOT NULL")or die("Error: ".mysql_error());
// this will change the column byid to id
Just Remember Mysql_connect()
and mysql API
are old and not used after php 7 so start to learn mysqli api