Page 2 of 2

Posted: Fri Dec 13, 2002 4:19 pm
by nathus
how are you trying to enter the email into the news_news table?

Posted: Fri Dec 13, 2002 10:55 pm
by kkurkowski
I am making it so that when someone post a news article it puts the email into a table in MySQL so that it can be opened and viewable on the webpage. That seems to be not working though. I have tried a whole bunch of ways and it doesn't want to add it into the table.

Posted: Fri Dec 13, 2002 11:21 pm
by nathus
could you post a schema of the news_news table? and possibly the part of code where you're trying to put it into the table?

Posted: Fri Dec 13, 2002 11:25 pm
by kkurkowski
I have the code, but what do you mean by schema of news_news????
I was trying to add email into the cookie so that it will read it from the cookie, but it doesn't want to load the email from news_users.

Code: Select all

$result = mysql_query($sql)
	or die ("Can't execute query.");
$num = mysql_numrows($result);
$email = $resultї"email"];



if ($num != 0) { 

	$cookie_name_auth = "status";
	$cookie_value_auth = "ok";
	$cookie_expire_auth = 0;
	$cookie_domain_auth = ".bve.32k.org";
	
	setcookie($cookie_name_auth, $cookie_value_auth, $cookie_expire_auth, "/" , $cookie_domain_auth, 0);

	$cookie_name_user = "user";
	$cookie_value_user = "$username";
	$cookie_expire_user = time()+86400;
	$cookie_domain_user = ".bve.32k.org";
	
	setcookie($cookie_name_user, $cookie_value_user, $cookie_expire_user, "/" , $cookie_domain_user, 0);

	$cookie_name_email = "email";
	$cookie_value_email = "$email";
	$cookie_expire_email = time()+86400;
	$cookie_domain_email = ".bve.32k.org";

	setcookie($cookie_name_email, $cookie_value_email, $cookie_expire_email, "/" , $cookie_domain_email, 0);

Posted: Fri Dec 13, 2002 11:33 pm
by nathus
first off, this chunk of code

Code: Select all

$result = mysql_query($sql) 
   or die ("Can't execute query."); 
$num = mysql_numrows($result); 
$email = $result["email"];
should be

Code: Select all

$result = mysql_query($sql) 
   or die ("Can't execute query."); 
$num = mysql_num_rows($result); 
$result = mysql_fetch_array($result);
$email = $result["email"];
when doing a query you need to run the query, then need to extract the data from the result object.

a schema is the layout of the table in the mysql database.

Posted: Fri Dec 13, 2002 11:39 pm
by kkurkowski
id headline news link user timestamp email

Thats what the news_news looks like. But when I add a post it is not adding anything into email. It adds into everything else but email.

Ok, I got it to add to the cookie now. But now it just isn't adding it into the table of news_news

Posted: Fri Dec 13, 2002 11:42 pm
by nathus
whats your code for putting the info into the news_news table look like? maybe I can spot the problem with the query.

Posted: Fri Dec 13, 2002 11:46 pm
by kkurkowski

Code: Select all

<?php
                        require("news_connect.php");
						if(@$action=="submit")
                        {
						if ((!$news_headline) || (!$news_news) || (!$news_link)) {
	                    echo "Please fill in all fields<br>\n";
						} else {
                        mysql_query("INSERT INTO news_news (headline,news,link,user,timestamp,email) VALUES ('$news_headline','$news_news','$news_link','$user','$email',".time().")");
                        echo "News added<br>\n";
                        }}
?>

Posted: Fri Dec 13, 2002 11:53 pm
by nathus
you have your field/value pairs in the wrong order for the email, and timestamp. its adding the timestamp to the email spot, but it can't format the email address into a date. they need to be in the same order in each place. (a mistake I make every now and then.)

Posted: Fri Dec 13, 2002 11:58 pm
by kkurkowski
Ok, I changed it to

Code: Select all

mysql_query("INSERT INTO news_news (headline,news,link,user,timestamp,email) VALUES ('$news_headline','$news_news','$news_link','$user',".time()."),'$email'");
and it still isn't adding anything into the email table.It is just being left blank.

Posted: Sat Dec 14, 2002 12:09 am
by nathus

Code: Select all

mysql_query("INSERT INTO news_news (headline,news,link,user,timestamp,email) VALUES ('$news_headline','$news_news','$news_link','$user',".time().",'$email')");
you had a misplaced ) in there, try the above code.

Posted: Sat Dec 14, 2002 12:11 am
by kkurkowski
Right when you wrote that I just figured out what to do. I just switch email and timestamp around it it added it in there.
Thanks for all the help!!!