Hi all! I orginally put this up in the General Discussion forum and realised this was probably a better spot for it.
trying to debug a record insertion form for my blog page.
What i want to happen is:
-User Enters their Nickname into a form
-Then I determine the User Id based on this nickname (since they are both in the 'users' table)
-Insert the blog with user id to the 'posts' table
Pretty simple eh? So what am i doing wrong?
<?php
$username = $HTTP_POST_VARS['nickname'];
$query_1 = "SELECT USER_ID FROM users WHERE NICK_NAME = $username";
$userid = mysql_query($query_1);
?>
Note that $userid is a number. If i manually set $userid = 4, my insertion code (not shown) works great. The problem is that $userid is not being set to a valid integer, infact it remains NULL... Whats happening!
Thx in advance!
Simple mysql query not working!
Moderator: General Moderators
-
guycrossley
- Forum Newbie
- Posts: 9
- Joined: Mon May 12, 2003 8:46 pm
MySQL on php.net
Code: Select all
$query = "SELECT * FROM `table`";
$result = mysql_query($query);
// $result is now a resource handler, not a value.
$value = mysql_fetch_array($result);
// $value is not the value- coolpravin
- Forum Newbie
- Posts: 20
- Joined: Mon May 19, 2003 12:56 am
- Location: India
the solution
Hey use this one
<?php
$username = $HTTP_POST_VARS['nickname'];
$query_1 = "SELECT USER_ID FROM users WHERE NICK_NAME = $username";
$result_1 = mysql_query($query_1);
$row_1=mysql_fetch_array($result_1);
$userid=$row_1["USER_ID "];
?>
Is it works?
I know it will.
-------------BeCool
<?php
$username = $HTTP_POST_VARS['nickname'];
$query_1 = "SELECT USER_ID FROM users WHERE NICK_NAME = $username";
$result_1 = mysql_query($query_1);
$row_1=mysql_fetch_array($result_1);
$userid=$row_1["USER_ID "];
?>
Is it works?
I know it will.
-------------BeCool
-
guycrossley
- Forum Newbie
- Posts: 9
- Joined: Mon May 12, 2003 8:46 pm