kayz
02-19-2008, 01:31 AM
Hi all i have a basic php website where the user logs in and etc.
Now i have a small form where when the user logs in they put in an article title and the article itself.
Now this works fine, but i also want the users first name and surname along with another variable to go into the database.. as the article was submited by etc etc without the user having to fill the form in with their name whilst their logged in.. do you see what i mean?
I have the following in place already.
The form page where the session is working fine and is as follows:
<?
session_start();
if(!session_is_registered(myusername)){
header("location:wronglogin.php");
}
?>
Below is the processing script where the form goes through:
<?php
// Make a MySQL Connection
include "../config.php";
$submission_date = date("D M j Y G:i:s");
// Insert a row of information into the table "example"
mysql_query("INSERT INTO article
(firstname, surname, username, title, article, submission_date) VALUES('$firstname', '$surname', '$username', '$title', '$article', '$submission_date')")
or die(mysql_error());
echo "Data Inserted!";
?>
Thats all.
Now another thing, i sort of cheated so take a look below what i did with the form..
<form action="articleinsert.php" method="post">
title: <input type="text" name="title" />
article: <input type="text" name="article" />
**** THIS WORKS **** <input type="hidden" name="username" value="<?php echo "$myusername"; ?>" />
**** THIS DOSENT **** <input type="hidden" name="firstname" value="<?php echo "$firstname"; ?>" />
<input type="submit" name="register" value="submit" />
</form>
I tried this.. and it works with only the username being submmited into the database as you can see the username variable here is $myusername which is the same as the page session hence it works im guessing.. i then tried many things to get the username in automatically but i failed.
I need to put in the session variables i believe..?
Any help will be much much appreciated really, and thankyou.
Now i have a small form where when the user logs in they put in an article title and the article itself.
Now this works fine, but i also want the users first name and surname along with another variable to go into the database.. as the article was submited by etc etc without the user having to fill the form in with their name whilst their logged in.. do you see what i mean?
I have the following in place already.
The form page where the session is working fine and is as follows:
<?
session_start();
if(!session_is_registered(myusername)){
header("location:wronglogin.php");
}
?>
Below is the processing script where the form goes through:
<?php
// Make a MySQL Connection
include "../config.php";
$submission_date = date("D M j Y G:i:s");
// Insert a row of information into the table "example"
mysql_query("INSERT INTO article
(firstname, surname, username, title, article, submission_date) VALUES('$firstname', '$surname', '$username', '$title', '$article', '$submission_date')")
or die(mysql_error());
echo "Data Inserted!";
?>
Thats all.
Now another thing, i sort of cheated so take a look below what i did with the form..
<form action="articleinsert.php" method="post">
title: <input type="text" name="title" />
article: <input type="text" name="article" />
**** THIS WORKS **** <input type="hidden" name="username" value="<?php echo "$myusername"; ?>" />
**** THIS DOSENT **** <input type="hidden" name="firstname" value="<?php echo "$firstname"; ?>" />
<input type="submit" name="register" value="submit" />
</form>
I tried this.. and it works with only the username being submmited into the database as you can see the username variable here is $myusername which is the same as the page session hence it works im guessing.. i then tried many things to get the username in automatically but i failed.
I need to put in the session variables i believe..?
Any help will be much much appreciated really, and thankyou.
