Page 1 of 1

Load Defauly Form Values From DB

Posted: Thu Oct 19, 2006 11:34 pm
by 4Boredom
I want to get the variables on http://www.4boredom.com/editbasic.php to load from the database. With PHP how would I edit what I have to load from my 'basic' database what the user entered when they registered?

Code: Select all

<?php 
ob_start();
session_start(); 
include("userinfo.php");
require("header.php"); 
include("db.php");
if(!isset($_SESSION['loggedin'])){
	header("Location: login.php?error=101");
}
?>

<center>
<b>Edit Your Basic Info</b><br><br>

<form name=signupform method=post action=update-basic.php> 
  <table width=100% border=0 cellpadding=4 cellspacing=0 align="center"> 
 
	 <tr>  
      <td align=left valign=top>Gender</td> 
      <td><input type="radio" name=gender type=text id=gender value=male> Male 
	  <input type="radio" name=gender type=text id=gender value=female> Female</td> 
    </tr>

	 <tr>  
      <td align=left valign=top>Month</td> 
      <td>
	  <select name="month">
<option value="January">January
<option value="February">February
<option value="March">March
<option value="April">April
<option value="May">May
<option value="June">June
<option value="July">July
<option value="August">August
<option value="September">September
<option value="October">October
<option value="November">November
<option value="December">December
</select>
</td> 
    </tr>
	 <tr>  
      <td align=left valign=top>Day</td> 
      <td>
	  <select name="day">
<option value="1">1
<option value="2">2
<option value="3">3
<option value="4">4
<option value="5">5
<option value="6">6
<option value="7">7
<option value="8">8
<option value="9">9
<option value="10">10
<option value="11">11
<option value="12">12
<option value="13">13
<option value="14">14
<option value="15">15
<option value="16">16
<option value="17">17
<option value="18">18
<option value="19">19
<option value="20">20
<option value="21">21
<option value="22">22
<option value="23">23
<option value="24">24
<option value="25">25
<option value="26">26
<option value="27">27
<option value="28">28
<option value="29">29
<option value="30">30
<option value="31">31
	  </td> 
    </tr>
	 <tr>  
      <td align=left valign=top>Year</td> 
      <td>
	  <select name="year">
	  <option value="1930">1930
<option value="1931">1931
<option value="1932">1932
<option value="1933">1933
<option value="1934">1934
<option value="1935">1935
<option value="1936">1936
<option value="1937">1937
<option value="1938">1938
<option value="1939">1939
<option value="1940">1940
<option value="1941">1941
<option value="1942">1942
<option value="1943">1943
<option value="1944">1944
<option value="1945">1945
<option value="1946">1946
<option value="1947">1947
<option value="1948">1948
<option value="1949">1949
<option value="1950">1950
<option value="1951">1951
<option value="1952">1952
<option value="1953">1953
<option value="1954">1954
<option value="1955">1955
<option value="1956">1956
<option value="1957">1957
<option value="1958">1958
<option value="1959">1959
<option value="1960">1960
<option value="1961">1961
<option value="1962">1962
<option value="1963">1963
<option value="1964">1964
<option value="1965">1965
<option value="1966">1966
<option value="1967">1967
<option value="1968">1968
<option value="1969">1969
<option value="1970">1970
<option value="1971">1971
<option value="1972">1972
<option value="1973">1973
<option value="1974">1974
<option value="1975">1975
<option value="1976">1976
<option value="1977">1977
<option value="1978">1978
<option value="1979">1979
<option value="1980">1980
<option value="1981">1981
<option value="1982">1982
<option value="1983">1983
<option value="1984">1984
<option value="1985" selected="selected">1985
<option value="1986">1986
<option value="1987">1987
<option value="1988">1988
<option value="1989">1989
<option value="1990">1990
<option value="1991">1991
<option value="1992">1992
<option value="1993">1993
	  </td> 
    </tr>
	
      <td align=left valign=top> </td> 
      <td><input type=submit name=Submit value=Update!></td> 
    </tr> 
  </table> 
</form>
<a href="uservars.php">Back To Your User Vars</a>
</td></tr>
</table>

</center>
</body>

</html>

Posted: Thu Oct 19, 2006 11:41 pm
by 4Boredom
I think my problem may be reading from the db... It reads users but not basic

Code: Select all

<?php
ob_start();
session_start();
require 'db.php';
// Check to see if user is logged in and what there username is 
if(isset($_SESSION['email_address']) && isset($_SESSION['loggedin'])){
	// If user is logged in SESSION session variables 
	if($_SESSION['loggedin']==1){
		$email_address = $_SESSION['email_address'];
			if(isset($_SESSION['password'])){
				$pass = $_SESSION['password'];
			 }
		$loggedin = $_SESSION['loggedin'];
			if(isset($_SESSION['time'])){
				$time = $_SESSION['time']; 
			}
	}
// now only process if user is logged in
if($loggedin == 1){
// Get user Information from users db
$info = mysql_query("SELECT * FROM `users` WHERE email_address = '{$email_address}' ");
$info2 = mysql_query("SELECT * FROM `basic` WHERE email_addy = '{$email_addy}' ");
if(!$info){
	die("Could not get user info");
}
$info = mysql_fetch_array($info);
$info2 = mysql_fetch_array($info2);


// Get other required user infomation 
$first_name = $info['first_name']; 
$last_name = $info['last_name']; 
$email_address = $info['email_address']; 
$signup_date = $info['signup_date'];
$username = $info['username'];
$gender = $info['gender'];
$month = $info['month'];
$day = $info['day'];
$year = $info['year'];
$userid = $userid['userid'];
// Fix for any place you put session instead of just the variable.
$_SESSION['first_name'] = $first_name;
$_SESSION['email_adress'] = $email_address;
$_SESSION['signup_date'] = $signup_date;
$_SESSION['last_name'] = $last_name;
$_SESSION['username'] = $username;
$_SESSION['gender'] = $gender;
$_SESSION['month'] = $month;
$_SESSION['day'] = $day;
$_SESSION['year'] = $year;

// Get user Information from basic db
$info = mysql_query("SELECT * FROM `basic` WHERE userid = '{$userid}' ");
if(!$info){
	die("Could not get user info");
}
$info = mysql_fetch_array($info);
// Get other required user infomation 

$gender = $info['gender'];
$month = $info['month'];
$day = $info['day'];
$year = $info['year'];
$email_addy = $info['email_addy'];
// Fix for any place you put session instead of just the variable.
$_SESSION['gender'] = $gender;
$_SESSION['month'] = $month;
$_SESSION['day'] = $day;
$_SESSION['year'] = $year;
$_SESSION['email_addy'] = $email_addy;

$current_time = date("Y");

//end of only process if user is logged in code 
}
//if user is not logged in:
/*} else {
	// Set user is not logged in if session is not detected
	$_SESSION['loggedin'] = 0;
	$loggedin = $_SESSION['loggedin'];
}*/
}
ob_flush();
?>

Posted: Sat Oct 21, 2006 2:56 pm
by 4Boredom
Does noone know or do you just not get my question?

Ive been stuck on this for like a month :(

Posted: Mon Oct 23, 2006 8:59 am
by 4Boredom
upping for help

Posted: Mon Oct 23, 2006 9:02 am
by JayBird
Dont really know what your asking

Posted: Mon Oct 23, 2006 9:21 am
by bokehman
Ok. The problem is you need to cut your question down. You have posted too much. Anyway just to give you an idea look at the following which is just a date example loaded from MySQL:

Code: Select all

# date_col would be type: DATE or DATETIME
$query = "SELECT `date_col` FROM `tablename` WHERE `some_col` = 'something'";
$result = mysql_query($query) or die(mysql_error());

if($row = mysql_fetch_assoc($result))
{
	$dropdown = date_drop_down(strtotime($row['date_col']));
}
else
{
	$dropdown = date_drop_down();
}

echo $dropdown;

function date_drop_down($timestamp = null /* $timestamp = unix timestamp */)
{
        $timestamp = $timestamp ? $timestamp : time();
        for($i = 1; $i < 32; $i++)
        {
                $days[] = $i;
        }
        $days = dropdown($days, date('j', $timestamp));
       
        $months = array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
                        'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
        $months = dropdown($months, date('M', $timestamp));
       
        for($i = date('Y')-2; $i < date('Y') + 4; $i++)
        {
                $years[] = $i;
        }
        $years = dropdown($years, date('Y', $timestamp));
        return '<p><label>Date:</label>'."\n".
        'Day: <select name="day" size="1">'.$days.'</select>'."\n".
        'Month: <select name="month" size="1">'.$months.'</select>'."\n".
        'Year: <select name="year" size="1">'.$years.'</select></p>'."\n";
}

function dropdown($options_array, $selected = null)
{
    $return = null;
    foreach($options_array as $option)
    {
        $return .= '<option value="'.$option.'"'.
                   (($option == $selected) ? ' selected="selected"' : null ).
                   '>'.ucfirst($option).'</option>'."\n";
    }
    return $return;
}

Posted: Mon Oct 23, 2006 1:22 pm
by 4Boredom
Ok.. I cut it down... is my problem with the $info and $info2????

Code: Select all

// Get user Information from users db 
$info = mysql_query("SELECT * FROM `users` WHERE email_address = '{$email_address}' "); 
$info2 = mysql_query("SELECT * FROM `basic` WHERE email_addy = '{$email_addy}' "); 
if(!$info){ 
        die("Could not get user info"); 
} 
$info = mysql_fetch_array($info); 
$info2 = mysql_fetch_array($info2); 


// Get other required user infomation 
$first_name = $info['first_name']; 
$last_name = $info['last_name']; 
$email_address = $info['email_address']; 
$signup_date = $info['signup_date']; 
$username = $info['username']; 
$gender = $info['gender']; 
$month = $info['month']; 
$day = $info['day']; 
$year = $info['year']; 
$userid = $userid['userid']; 
// Fix for any place you put session instead of just the variable. 
$_SESSION['first_name'] = $first_name; 
$_SESSION['email_adress'] = $email_address; 
$_SESSION['signup_date'] = $signup_date; 
$_SESSION['last_name'] = $last_name; 
$_SESSION['username'] = $username; 
$_SESSION['gender'] = $gender; 
$_SESSION['month'] = $month; 
$_SESSION['day'] = $day; 
$_SESSION['year'] = $year; 

// Get user Information from basic db 
$info = mysql_query("SELECT * FROM `basic` WHERE userid = '{$userid}' "); 
if(!$info){ 
        die("Could not get user info"); 
} 
$info = mysql_fetch_array($info); 
// Get other required user infomation 

$gender = $info['gender']; 
$month = $info['month']; 
$day = $info['day']; 
$year = $info['year']; 
$email_addy = $info['email_addy']; 
// Fix for any place you put session instead of just the variable. 
$_SESSION['gender'] = $gender; 
$_SESSION['month'] = $month; 
$_SESSION['day'] = $day; 
$_SESSION['year'] = $year; 
$_SESSION['email_addy'] = $email_addy;

Posted: Mon Oct 23, 2006 4:08 pm
by 4Boredom
its evident that noones nice enough to help....

anyone willing to take a quick look thru my system for some money?

I cant pay a huge price because im a college student trying to learn, but sometimes i cant work out my own errors, so I will compensate you for your time at a reasonable rate... PM me

Posted: Mon Oct 23, 2006 4:11 pm
by satheshf12000

Code: Select all

$info = mysql_query("SELECT * FROM `users` WHERE email_address = '{$email_address}' ");
$info2 = mysql_query("SELECT * FROM `basic` WHERE email_addy = '{$email_addy}' ");
Try writing your query without single quotes for the table name like this:

Code: Select all

$info = mysql_query("select * from users where email_address='$email_address'");
$info2 = mysql_query("select * from basic where email_addy = '$email_addy'");
copy the above and test it and then post the warnings/errors back here if u still got stuck up..

Posted: Mon Oct 23, 2006 5:07 pm
by bokehman
There's nothing wrong with the queries!