KC8Alen Posted April 14, 2010 Share Posted April 14, 2010 Hi, I have a problem with a PHP webpage i made, the problem is It doesnt show the data from the user, I've looked at it for one and a half days already but I can't seem to find the problem, it doesn't echo or print the value it gets from the database. The data it retrieves actually should be printed out on the page, but currently i'm trying to have it print in textbox value, it doesn't really matter whether its printed/echoed in textbox or not. Here is the code: <?PHP session_start(); mysql_connect("localhost", "username") or die(mysql_error()); mysql_select_db("Survey") or die(mysql_error()); //checks cookies to make sure they are logged in if(isset($_COOKIE['ID_my_site'])) { $username = $_COOKIE['ID_my_site']; $pass = $_COOKIE['Key_my_site']; $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { if ($pass != $info['password']) { header("Location: login.php"); } } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> </head> <body> <?PHP mysql_connect("localhost", "username") or die(mysql_error()); mysql_select_db("Survey") or die(mysql_error()); if(isset($_COOKIE['ID_my_site'])) { $username = $_COOKIE['ID_my_site']; $pass = $_COOKIE['Key_my_site']; $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { if ($pass != $info['password']) { header("Location: login.php"); } } } $result=mysql_query($check); $num=mysql_numrows($result); $i=0; while ($i < $num) { $username=mysql_result($result,$i,"username"); $bnaam=mysql_result($result,$i,"Bedrijfsnaam"); $kvk=mysql_result($result,$i,"Kvknr"); $tel=mysql_result($result,$i,"Telefoonnummer"); $email=mysql_result($result,$i,"Emailadres"); $contpers=mysql_result($result,$i,"Contactpersoon"); $adres=mysql_result($result,$i,"Adres"); $jaar=mysql_result($result,$i,"Jaar_van_oprichting"); $pcode=mysql_result($result,$i,"Postcode"); $plaats=mysql_result($result,$i,"Plaats"); $i++; } ?> <?PHP print $jaar;?> <!-- I've just added this random to check if it shows up... --> <table border="0"> <tr><td>Gebruikersnaam:</td><td> <input type="text" name="username" maxlength="60"> </table> <table><tr><td>_____________________________________________________</td></tr><td></td><tr><td></td></tr></table> <table> <tr><td> Bedrijfsnaam: </td> <td> <input type="text" readonly="readonly" name="bnaam" size="26" id="bnaam" value="<?PHP echo $bnaam;?>"/></td></tr> <tr><td> Contactpersoon:</td> <td><input type="text" name="contpers" size="26" id="contpers" value="<?PHP echo $contpers; ?>"/></td></tr> <tr><td> Adres: </td> <td><input type="text" name="adres" size="26" id="adres" maxlength="29" value="<? echo $adres;?>"/></td></tr> <tr><td> Postcode en plaats: </td> <td><input type="text" name="pcode" size="7" id="pcode" maxlength="7"/><input type="text" name="plaats" size="17" maxlength="26" id="plaats"/></td></tr> <tr><td> Kvk nr: </td> <td> <input type="text" name="kvk" size="18" id="kvk" maxlength="10"></td></tr> <tr><td> Telefoonnummer: </td> <td> <input type="text" name="tel" size="18" id="tel" maxlength="18"/></td></tr> <tr><td> E-mailadres: </td> <td> <input type="text" name="email" size="26" id="email" maxlength="28"/></td></tr> <tr><td> Jaar van oprichting:</td> <td><select name="jaar"> <option>Jaar</option> <option value=2010>2010</option> <option value=2009>2009</option> <option value=2008>2008</option> <option value=2007>2007</option> <option value=2006>2006</option> <option value=2005>2005</option> <option value=2004>2004</option> <option value=2003>2003</option> <option value=2002>2002</option> <option value=2001>2001</option> <option value=2000>2000</option> <option value=1999>1999</option> <option value=1998>1998</option> <option value=1997>1997</option> <option value=1996>1996</option> <option value=1995>1995</option> <option value=1994>1994</option> <option value=1993>1993</option> <option value=1992>1992</option> <option value=1991>1991</option> <option value=1990>1990</option> <option value=1989>1989</option> <option value=1988>1988</option> <option value=1987>1987</option> <option value=1986>1986</option> <option value=1985>1985</option> <option value=1984>1984</option> <option value=1983>1983</option> <option value=1982>1982</option> <option value=1981>1981</option> <option value=1980>1980</option> <option value=1979>1979</option> <option value=1978>1978</option> <option value=1977>1977</option> <option value=1976>1976</option> <option value=1975>1975</option> <option value=1974>1974</option> <option value=1973>1973</option> <option value=1972>1972</option> <option value=1971>1971</option> <option value=1970>1970</option> <option value=1969>1969</option> <option value=1968>1968</option> <option value=1967>1967</option> <option value=1966>1966</option> <option value=1965>1965</option> <option value=1964>1964</option> <option value=1963>1963</option> <option value=1962>1962</option> <option value=1961>1961</option> <option value=1960>1960</option> </select></td></tr> </table> </body> </html> Hope someone can help me out, thanks a lot. Quote Link to comment Share on other sites More sharing options...
Wolphie Posted April 14, 2010 Share Posted April 14, 2010 The line $num=mysql_numrows($result); should be $num = mysql_num_rows($result); This code $result=mysql_query($check); $num=mysql_numrows($result); $i=0; while ($i < $num) { $username=mysql_result($result,$i,"username"); $bnaam=mysql_result($result,$i,"Bedrijfsnaam"); $kvk=mysql_result($result,$i,"Kvknr"); $tel=mysql_result($result,$i,"Telefoonnummer"); $email=mysql_result($result,$i,"Emailadres"); $contpers=mysql_result($result,$i,"Contactpersoon"); $adres=mysql_result($result,$i,"Adres"); $jaar=mysql_result($result,$i,"Jaar_van_oprichting"); $pcode=mysql_result($result,$i,"Postcode"); $plaats=mysql_result($result,$i,"Plaats"); $i++; } should also be within the if(isset($_COOKIE['ID_my_site'])) statement, otherwise $check may not be declared and you will get a T_UNDEFINED_VARIABLE error. Quote Link to comment Share on other sites More sharing options...
Wolphie Posted April 14, 2010 Share Posted April 14, 2010 I also failed to mention that you don't need to open a new MySQL connection twice in the same script unless you use the function mysql_close() on a MySQL handler. I also noticed you haven't included a password in the mysql_connect() function, unless you just left this out to post your code here? Quote Link to comment Share on other sites More sharing options...
KC8Alen Posted April 14, 2010 Author Share Posted April 14, 2010 thnx for your reply, but i've delete that part and replaced something else with it, so i didnt declare every column, and looks like its working But thank you for pointing me that out =D Quote Link to comment Share on other sites More sharing options...
KC8Alen Posted April 14, 2010 Author Share Posted April 14, 2010 yups i deleted that part already about the 2 opening mysql, because i went freak so i tried to set 2 mysql opening and hope it worked... lol for the password, i dont have a password for the mysql yet, and when i put password I get error, but im still running it local only, thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.