Defining A Varible

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
nathus
Forum Commoner
Posts: 49
Joined: Thu Dec 12, 2002 6:23 pm

Post by nathus »

how are you trying to enter the email into the news_news table?
kkurkowski
Forum Commoner
Posts: 53
Joined: Mon Dec 09, 2002 4:44 pm
Location: Michigan

Post 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.
User avatar
nathus
Forum Commoner
Posts: 49
Joined: Thu Dec 12, 2002 6:23 pm

Post 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?
kkurkowski
Forum Commoner
Posts: 53
Joined: Mon Dec 09, 2002 4:44 pm
Location: Michigan

Post 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);
User avatar
nathus
Forum Commoner
Posts: 49
Joined: Thu Dec 12, 2002 6:23 pm

Post 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.
kkurkowski
Forum Commoner
Posts: 53
Joined: Mon Dec 09, 2002 4:44 pm
Location: Michigan

Post 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
User avatar
nathus
Forum Commoner
Posts: 49
Joined: Thu Dec 12, 2002 6:23 pm

Post 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.
kkurkowski
Forum Commoner
Posts: 53
Joined: Mon Dec 09, 2002 4:44 pm
Location: Michigan

Post 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";
                        }}
?>
User avatar
nathus
Forum Commoner
Posts: 49
Joined: Thu Dec 12, 2002 6:23 pm

Post 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.)
kkurkowski
Forum Commoner
Posts: 53
Joined: Mon Dec 09, 2002 4:44 pm
Location: Michigan

Post 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.
User avatar
nathus
Forum Commoner
Posts: 49
Joined: Thu Dec 12, 2002 6:23 pm

Post 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.
kkurkowski
Forum Commoner
Posts: 53
Joined: Mon Dec 09, 2002 4:44 pm
Location: Michigan

Post 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!!!
Post Reply