Click here to Skip to main content
12,700,567 members (30,396 online)
Rate this:
Please Sign up or sign in to vote.
See more: PHP MySQL
I am using this small line to select user id from my database , but I can't select it . I don't know why , because the browser doesn't display any error , and I cannot figure where the problem is. Please help me; Excuse me for the language used In this code , because it is Albanian language (the language I use in my country)

<title>Krijo nje artikull per kete faqe</title>
<link rel="stylesheet" href="assets/login_form/reset.css">
<link rel="stylesheet" href="assets/login_form/animate.css">
<link rel="stylesheet" href="assets/login_form/styles.css">
<script type="text/javascript" src="tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">
        // General options
        mode : "textareas",
        theme : "advanced",
        plugins : "autolink,lists,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",

        // Theme options
        theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
        theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
        theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
        theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,spellchecker,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,blockquote,pagebreak,|,insertfile,insertimage",
        theme_advanced_toolbar_location : "top",
        theme_advanced_toolbar_align : "left",
        theme_advanced_statusbar_location : "bottom",
        theme_advanced_resizing : true,

        // Skin options
        skin : "o2k7",
        skin_variant : "silver",

        // Example content CSS (should be your site CSS)
        content_css : "css/example.css",

        // Drop lists for link/image/media/template dialogs
        template_external_list_url : "js/template_list.js",
        external_link_list_url : "js/link_list.js",
        external_image_list_url : "js/image_list.js",
        media_external_list_url : "js/media_list.js",});

			header("Location: login.php");
			$author_id = mysql_query("SELECT ID FROM users WHERE username ='".stripslashes($_COOKIE['zakamezusr'])."'");
			$query = "INSERT into posts (title , post ,date_up , author_id , description) VALUES ('".$_POST['title']."', '".$_POST['post']."', '".$_POST['date_up']."', '$author_id', '".$_POST['description']."')";
<div id="container" style="removed20%;removed:relative;width:640px;">
	<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
 <h1>Krijo nje Artikull te ri</h1>
 <table border="0">

 <tr><td>Emri i Artikullit</td><td>

 <input type="text" name="title" maxlength="60">

 <tr><td>Pershkrimi i Artikuallit</td><td>

 <input type="text" name="description" maxlength="60">



 <textarea class="mult" name="post" ></textarea>
 <tr><th colspan=2><input type="submit" name="submit" 
</th></tr> </table>



Posted 19-Sep-12 9:40am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You aren't using the result from mysql_query correctly. The mysql_query function returns resource on a successful query and false otherwise. The resource is not directly the result you are after, but rather a resource which contains the result.

Long story short to get the result you're after you'll need to do the following after the first query:

$row = mysql_fetch_assoc($author_id);
$query = "INSERT into posts (title , post ,date_up , author_id , description) VALUES ('".$_POST['title']."', '".$_POST['post']."', '".$_POST['date_up']."', '$author_id".$row['ID']."', '".$_POST['description']."')";

If you look at[^], specifically example 2 it gives you code that allows you to retrieve the data from the result resource.

You should also note that use of mysql is discouraged and its recommended to use either mysqli or pdo_mysql. For a discussion on which mysql api you can look at[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170118.1 | Last Updated 19 Sep 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100