Jump to content

SQL newbie help


hoponhiggo

Recommended Posts

ok, so thats worked.

 

But im not getting an error when trying to post a message:

 

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/chiggo12/public_html/test/insertarNoticia.php:3) in /home/chiggo12/public_html/test/insertarNoticia.php on line 7

 

any ideas?

Muddy

 

I have had a number of problems trying to get the code you kindly provided to work, but i have manged to take bits of it and mix it with bits i already had to get things to a stage which is further on from my original post!

 

I now have a message posting system which displays the message on my homepage and posts a message id, message text and userid to my database which i believe is ideal.

 

I am still having the original problem tho of displaying only the profile pic of the user who posted the message.

 

The code to display the message and send the data to the database is now:

 

<?php

//initialize the session
if (!isset($_SESSION)) {
  session_start();
}
include("db.php");
// if content has been sent
if(isset($_POST["textarea_noticia"])){
	$msg = $_POST["textarea_noticia"];
	$username = $_SESSION['MM_Username'];
	$userid = $_SESSION['MM_userid'];
	// Insert information
	$sql = mysql_query("INSERT INTO messages(message,username,id_fk)values('$msg','$username','$userid')");
	$result = mysql_query("SELECT * FROM messages order by msg_id desc");
	$row = mysql_fetch_assoc($result);
	$id = $row["msg_id"];
	$msg = $row["message"];
}
?>

 

The following code is used to display the profile pic of the user that is logged in

 

<?php
//to display image from source
$dir = "profpics";

$sql = "SELECT prof_pic FROM users WHERE username = '{$_SESSION['MM_Username']}'";
$res = mysql_query($sql) or die(mysql_error());
if(mysql_num_rows($res) == 0) die("Username not found in database.");

$row = mysql_fetch_array($res);
echo "<img src='$dir/{$row['prof_pic']}' width='38' height='38'><br>";
?>

 

Can this, inparticular the

 

 "SELECT prof_pic FROM users WHERE username = '{$_SESSION['MM_Username']}'"

 

just be changed from who is logged in, to who posted the message??

 

Im sorry if this has gone in a massive circle!!

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.