skiingguru1611 Posted October 24, 2008 Share Posted October 24, 2008 I have a website for a sports team tournament and I want individual players to be able to enter their personal information for college coaches to see. However I don't want them entering all their friends info to, so I am trying to take the page I currently have for UPDATING the info and making it into a a page for INSERT and UPDATE. The actually SQL to dump the info into the database I can do so unless it is relelvent I am not going to post it. My problem is that, if they have info added in the database I want those values to show up in the fields, which I have set up and working. However, if they don't have info in the DB then a blank screen shows up and they can't see the form. What do I have to do to the code so if they have info it shows up in the fields but if they don't have info then blank fields show up? Here is the code. <?php $db_name="****"; $connection=mysql_connect("localhost","****","****") or die("I Couldn't connect"); $db=mysql_select_db($db_name,$connection) or die("I Couldn't select your database"); $table="player"; // Table name $sql="select user, first, last, birth, address, city, state, zip, email, grade, team, coach, height, weight, gpa, sat, phone, other from $table WHERE user='$user'"; $result=mysql_query($sql,$connection) or die(mysql_error()); while($row=mysql_fetch_array($result)) { ?> <form method="post" action="../player/insertupdate.php"> <input type="hidden" name="user" value="<?php echo $user; ?>"> <p>First Name <input type="text" name="first" maxlength="20" value="<?php echo $row['first']; ?>"> Last Name <input type="text" name="last" maxlength="20" value="<?php echo $row['last']; ?>"> </p> <p>Birth Date <input type="text" name="birth" maxlength="20" value="<?php echo $row['birth']; ?>"> Address <input type="text" name="address" maxlength="50" value="<?php echo $row['address']; ?>"> </p> <p> City <input type="text" name="city" maxlength="20" value="<?php echo $row['city']; ?>"> State <select name="state" value="<?php echo $row['state']; ?>"> # <option value="">None</option> # <option value="AL">Alabama</option> # <option value="AK">Alaska</option> # <option value="AZ">Arizona</option> # <option value="AR">Arkansas</option> # <option value="CA">California</option> # <option value="CO">Colorado</option> # <option value="CT">Connecticut</option> # <option value="DC">District of Columbia</option> # <option value="DE">Delaware</option> # <option value="FL">Florida</option> # <option value="GA">Georgia</option> # <option value="HI">Hawaii</option> # <option value="ID">Idaho</option> # <option value="IL">Illinois</option> # <option value="IN">Indiana</option> # <option value="IA">Iowa</option> # <option value="KS">Kansas</option> # <option value="KY">Kentucky</option> # <option value="LA">Louisiana</option> # <option value="ME">Maine</option> # <option value="MD">Maryland</option> # <option value="MA">Massachusetts</option> # <option value="MI">Michigan</option> # <option value="MN">Minnesota</option> # <option value="MS">Mississippi</option> # <option value="MO">Missouri</option> # <option value="MT">Montana</option> # <option value="NE">Nebraska</option> # <option value="NV">Nevada</option> # <option value="NH">New Hampshire</option> # <option value="NJ">New Jersey</option> # <option value="NM">New Mexico</option> # <option value="NY">New York</option> # <option value="NC">North Carolina</option> # <option value="ND">North Dakota</option> # <option value="OH">Ohio</option> # <option value="OK">Oklahoma</option> # <option value="OR">Oregon</option> # <option value="PA">Pennsylvania</option> # <option value="PR">Puerto Rico</option> # <option value="RI">Rhode Island</option> # <option value="SC">South Carolina</option> # <option value="SD">South Dakota</option> # <option value="TN">Tennessee</option> # <option value="TX">Texas</option> # <option value="UT">Utah</option> # <option value="VT">Vermont</option> # <option value="VA">Virginia</option> # <option value="WA">Washington</option> # <option value="WV">West Virginia</option> # <option value="WI">Wisconsin</option> # <option value="WY">Wyoming</option> # </select> Zipcode <input type="text" name="zip" maxlength="5" value="<?php echo $row['zip']; ?>"> </p> <p>Phone ex.(555) 555-5555 <input type="text" name="phone" maxlength="20" value="<?php echo $row['phone']; ?>"> Email <input type="text" name="email" maxlength="50" value="<?php echo $row['email']; ?>"> </p> <p>Grade <input type="text" name="grade" maxlength="10" value="<?php echo $row['grade']; ?>"> School <input type="text" name="team" maxlength="20" value="<?php echo $row['team']; ?>"> </p> <p>Coach <input type="text" name="coach" maxlength="20" value="<?php echo $row['coach']; ?>"> Height <input type="text" name="height" maxlength="10" value="<?php echo $row['height']; ?>"> Weight <input type="text" name="weight" maxlength="10" value="<?php echo $row['weight']; ?>"> </p> <p>Grade Point Average (GPA) <input type="text" name="gpa" maxlength="10" value="<?php echo $row['gpa']; ?>"> SAT Score <input type="text" name="sat" maxlength="5" value="<?php echo $row['sat']; ?>"> </p> <p> Notable Academic and Athletic Achievments: (2500 Character Maximum) </p> <textarea name="other" rows="10" cols="50"><?php echo $row['other']; ?> </textarea> <p><input type="submit" value="Submit"></p> <?php } ?> </form> Quote Link to comment https://forums.phpfreaks.com/topic/129997-help-with-phpmysql-code-needs-to-be-done-soon/ Share on other sites More sharing options...
Lee-Bartlett Posted October 24, 2008 Share Posted October 24, 2008 Im not a good php person just learning and wouldnt know how to code this but couldnt you do somthing like, if $varible is inputed echo $varible else echo, no data inputted. Could be wrong but thats what i think, if i read your problem right Quote Link to comment https://forums.phpfreaks.com/topic/129997-help-with-phpmysql-code-needs-to-be-done-soon/#findComment-673926 Share on other sites More sharing options...
n3ightjay Posted October 24, 2008 Share Posted October 24, 2008 you have to take a field that is manditory ... like their name (if your not entering that) and check to make sure its not null then proceed for my example im assuming they have to enter their own first name: this would go directly after you start your while loop if($row['first'] != ""){ ?> ** Your Form with info in it ** <? }else{ ?> ** Your blank form ** <? } ?> Quote Link to comment https://forums.phpfreaks.com/topic/129997-help-with-phpmysql-code-needs-to-be-done-soon/#findComment-673938 Share on other sites More sharing options...
skiingguru1611 Posted October 24, 2008 Author Share Posted October 24, 2008 I am getting a "Parse error: syntax error, unexpected T_ELSE" message. By the way "user" is mandatory not "first." I am almost positive I have all the brackets closed. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/129997-help-with-phpmysql-code-needs-to-be-done-soon/#findComment-673947 Share on other sites More sharing options...
skiingguru1611 Posted October 24, 2008 Author Share Posted October 24, 2008 Anyone else have any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/129997-help-with-phpmysql-code-needs-to-be-done-soon/#findComment-674012 Share on other sites More sharing options...
DarkWater Posted October 24, 2008 Share Posted October 24, 2008 We'd need to see your code to fix any parse errors. Quote Link to comment https://forums.phpfreaks.com/topic/129997-help-with-phpmysql-code-needs-to-be-done-soon/#findComment-674013 Share on other sites More sharing options...
skiingguru1611 Posted October 24, 2008 Author Share Posted October 24, 2008 Here it is with n3ightjay's suggestion. <?php $db_name="***"; $connection=mysql_connect("localhost","***","***") or die("I Couldn't connect"); $db=mysql_select_db($db_name,$connection) or die("I Couldn't select your database"); $table="player"; // Table name $sql="select user, first, last, birth, address, city, state, zip, email, grade, team, coach, height, weight, gpa, sat, phone, other from $table WHERE user='$user'"; $result=mysql_query($sql,$connection) or die(mysql_error()); while($row=mysql_fetch_array($result)) { if($row['user'] != ""){ ?> <form method="post" action="../player/insertupdate.php"> <input type="hidden" name="user" value="<?php echo $user; ?>"> <p>First Name <input type="text" name="first" maxlength="20" value="<?php echo $row['first']; ?>"> Last Name <input type="text" name="last" maxlength="20" value="<?php echo $row['last']; ?>"> </p> <p>Birth Date <input type="text" name="birth" maxlength="20" value="<?php echo $row['birth']; ?>"> Address <input type="text" name="address" maxlength="50" value="<?php echo $row['address']; ?>"> </p> <p> City <input type="text" name="city" maxlength="20" value="<?php echo $row['city']; ?>"> State <select name="state" value="<?php echo $row['state']; ?>"> # <option value="">None</option> # <option value="AL">Alabama</option> # <option value="AK">Alaska</option> # <option value="AZ">Arizona</option> # <option value="AR">Arkansas</option> # <option value="CA">California</option> # <option value="CO">Colorado</option> # <option value="CT">Connecticut</option> # <option value="DC">District of Columbia</option> # <option value="DE">Delaware</option> # <option value="FL">Florida</option> # <option value="GA">Georgia</option> # <option value="HI">Hawaii</option> # <option value="ID">Idaho</option> # <option value="IL">Illinois</option> # <option value="IN">Indiana</option> # <option value="IA">Iowa</option> # <option value="KS">Kansas</option> # <option value="KY">Kentucky</option> # <option value="LA">Louisiana</option> # <option value="ME">Maine</option> # <option value="MD">Maryland</option> # <option value="MA">Massachusetts</option> # <option value="MI">Michigan</option> # <option value="MN">Minnesota</option> # <option value="MS">Mississippi</option> # <option value="MO">Missouri</option> # <option value="MT">Montana</option> # <option value="NE">Nebraska</option> # <option value="NV">Nevada</option> # <option value="NH">New Hampshire</option> # <option value="NJ">New Jersey</option> # <option value="NM">New Mexico</option> # <option value="NY">New York</option> # <option value="NC">North Carolina</option> # <option value="ND">North Dakota</option> # <option value="OH">Ohio</option> # <option value="OK">Oklahoma</option> # <option value="OR">Oregon</option> # <option value="PA">Pennsylvania</option> # <option value="PR">Puerto Rico</option> # <option value="RI">Rhode Island</option> # <option value="SC">South Carolina</option> # <option value="SD">South Dakota</option> # <option value="TN">Tennessee</option> # <option value="TX">Texas</option> # <option value="UT">Utah</option> # <option value="VT">Vermont</option> # <option value="VA">Virginia</option> # <option value="WA">Washington</option> # <option value="WV">West Virginia</option> # <option value="WI">Wisconsin</option> # <option value="WY">Wyoming</option> # </select> Zipcode <input type="text" name="zip" maxlength="5" value="<?php echo $row['zip']; ?>"> </p> <p>Phone ex.(555) 555-5555 <input type="text" name="phone" maxlength="20" value="<?php echo $row['phone']; ?>"> Email <input type="text" name="email" maxlength="50" value="<?php echo $row['email']; ?>"> </p> <p>Grade <input type="text" name="grade" maxlength="10" value="<?php echo $row['grade']; ?>"> School <input type="text" name="team" maxlength="20" value="<?php echo $row['team']; ?>"> </p> <p>Coach <input type="text" name="coach" maxlength="20" value="<?php echo $row['coach']; ?>"> Height <input type="text" name="height" maxlength="10" value="<?php echo $row['height']; ?>"> Weight <input type="text" name="weight" maxlength="10" value="<?php echo $row['weight']; ?>"> </p> <p>Grade Point Average (GPA) <input type="text" name="gpa" maxlength="10" value="<?php echo $row['gpa']; ?>"> SAT Score <input type="text" name="sat" maxlength="5" value="<?php echo $row['sat']; ?>"> </p> <p> Notable Academic and Athletic Achievments: (2500 Character Maximum) </p> <textarea name="other" rows="10" cols="50"><?php echo $row['other']; ?> </textarea> <p><input type="submit" value="Submit"></p> <?php } ?> </form> <?php }else{ ?> <form method="post" action="../player/insertplayer.php"> <p>First Name <input type="text" name="first" maxlength="20"> Last Name <input type="text" name="last" maxlength="20"> </p> <p>Birth Date <input type="text" name="birth" maxlength="20"> Address <input type="text" name="address" maxlength="50"> </p> <p> City <input type="text" name="city" maxlength="20"> State <select name="state"> # <option value="">None</option> # <option value="AL">Alabama</option> # <option value="AK">Alaska</option> # <option value="AZ">Arizona</option> # <option value="AR">Arkansas</option> # <option value="CA">California</option> # <option value="CO">Colorado</option> # <option value="CT">Connecticut</option> # <option value="DC">District of Columbia</option> # <option value="DE">Delaware</option> # <option value="FL">Florida</option> # <option value="GA">Georgia</option> # <option value="HI">Hawaii</option> # <option value="ID">Idaho</option> # <option value="IL">Illinois</option> # <option value="IN">Indiana</option> # <option value="IA">Iowa</option> # <option value="KS">Kansas</option> # <option value="KY">Kentucky</option> # <option value="LA">Louisiana</option> # <option value="ME">Maine</option> # <option value="MD">Maryland</option> # <option value="MA">Massachusetts</option> # <option value="MI">Michigan</option> # <option value="MN">Minnesota</option> # <option value="MS">Mississippi</option> # <option value="MO">Missouri</option> # <option value="MT">Montana</option> # <option value="NE">Nebraska</option> # <option value="NV">Nevada</option> # <option value="NH">New Hampshire</option> # <option value="NJ">New Jersey</option> # <option value="NM">New Mexico</option> # <option value="NY">New York</option> # <option value="NC">North Carolina</option> # <option value="ND">North Dakota</option> # <option value="OH">Ohio</option> # <option value="OK">Oklahoma</option> # <option value="OR">Oregon</option> # <option value="PA">Pennsylvania</option> # <option value="PR">Puerto Rico</option> # <option value="RI">Rhode Island</option> # <option value="SC">South Carolina</option> # <option value="SD">South Dakota</option> # <option value="TN">Tennessee</option> # <option value="TX">Texas</option> # <option value="UT">Utah</option> # <option value="VT">Vermont</option> # <option value="VA">Virginia</option> # <option value="WA">Washington</option> # <option value="WV">West Virginia</option> # <option value="WI">Wisconsin</option> # <option value="WY">Wyoming</option> # </select> Zipcode <input type="text" name="zip" maxlength="5" > </p> <p>Phone ex.(555) 555-5555 <input type="text" name="phone" maxlength="20"> Email <input type="text" name="email" maxlength="50"> </p> <p>Grade <input type="text" name="grade" maxlength="10"> <?php $host="localhost"; // Host name $username="***"; // Mysql username $password="***"; // Mysql password $db_name="***"; // Database name $tbl_name="teams"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // Retrieve data from database $sql="SELECT team FROM $tbl_name ORDER BY team"; $result=mysql_query($sql); ?> School <select name = "team"> <?php // Start looping rows in mysql database. while($rows=mysql_fetch_array($result)){ ?> <option value = <?php echo $rows['team']; ?>><?php echo $rows['team']; ?></option> <?php // close while loop } // close connection mysql_close(); ?> </select> </p> <p>Coach <input type="text" name="coach" maxlength="20"> Height <input type="text" name="height" maxlength="10"> Weight <input type="text" name="weight" maxlength="10"> </p> <p>Grade Point Average (GPA) <input type="text" name="gpa" maxlength="10"> SAT Score <input type="text" name="sat" maxlength="5"> </p> <p> Notable Academic and Athletic Achievments: (2500 Character Maximum) </p> <textarea name="other" rows="10" cols="50"> </textarea> <p><input type="submit" value="Submit"></p> </form> <?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/129997-help-with-phpmysql-code-needs-to-be-done-soon/#findComment-674016 Share on other sites More sharing options...
DarkWater Posted October 24, 2008 Share Posted October 24, 2008 You threw in an extra <?php } ?>. Quote Link to comment https://forums.phpfreaks.com/topic/129997-help-with-phpmysql-code-needs-to-be-done-soon/#findComment-674017 Share on other sites More sharing options...
skiingguru1611 Posted October 24, 2008 Author Share Posted October 24, 2008 Where? Quote Link to comment https://forums.phpfreaks.com/topic/129997-help-with-phpmysql-code-needs-to-be-done-soon/#findComment-674019 Share on other sites More sharing options...
DarkWater Posted October 24, 2008 Share Posted October 24, 2008 Notable Academic and Athletic Achievments: (2500 Character Maximum) </p> <textarea name="other" rows="10" cols="50"><?php echo $row['other']; ?> </textarea> <p><input type="submit" value="Submit"></p> <?php } ?> </form> <?php }else{ ?> Right after that </p>. See it? Quote Link to comment https://forums.phpfreaks.com/topic/129997-help-with-phpmysql-code-needs-to-be-done-soon/#findComment-674021 Share on other sites More sharing options...
skiingguru1611 Posted October 24, 2008 Author Share Posted October 24, 2008 Well i need 2 there. One to close the "while" and one to close the "if". I tried it anyways and got this error "Parse error: syntax error, unexpected $end" Quote Link to comment https://forums.phpfreaks.com/topic/129997-help-with-phpmysql-code-needs-to-be-done-soon/#findComment-674025 Share on other sites More sharing options...
DarkWater Posted October 24, 2008 Share Posted October 24, 2008 The one that closes the while should go after the else { }, not the if { }. Quote Link to comment https://forums.phpfreaks.com/topic/129997-help-with-phpmysql-code-needs-to-be-done-soon/#findComment-674027 Share on other sites More sharing options...
skiingguru1611 Posted October 24, 2008 Author Share Posted October 24, 2008 That just gives me the blank screen I talked about in the OP. I have a seperate "while" statement that runs in the "else" statement so that gets funky. I tested the code below with the username already in the DB. It showed both sets of forms. So i am confused. Notable Academic and Athletic Achievments: (2500 Character Maximum) </p> <textarea name="other" rows="10" cols="50"><?php echo $row['other']; ?> </textarea> <p><input type="submit" value="Submit"></p> </form> <?php }else{ } ?> Quote Link to comment https://forums.phpfreaks.com/topic/129997-help-with-phpmysql-code-needs-to-be-done-soon/#findComment-674034 Share on other sites More sharing options...
skiingguru1611 Posted October 25, 2008 Author Share Posted October 25, 2008 Can someone help me here? Quote Link to comment https://forums.phpfreaks.com/topic/129997-help-with-phpmysql-code-needs-to-be-done-soon/#findComment-674179 Share on other sites More sharing options...
skiingguru1611 Posted October 25, 2008 Author Share Posted October 25, 2008 Seriously, no one can help? I need this running by tomorrow. Quote Link to comment https://forums.phpfreaks.com/topic/129997-help-with-phpmysql-code-needs-to-be-done-soon/#findComment-674493 Share on other sites More sharing options...
kenshintomoe225 Posted October 25, 2008 Share Posted October 25, 2008 if a variable is set to null, that is not the same thing (to my knowledge of php, and most OO languages) as null. "" represents an empty string, not null. When you query the DB for data, if there is no data, usually it'll return NULL, not the empty string. So if($row['other']) != "") will evaluate to true if nothing is returned, since NULL is returned. Use if(!isset($row['other'])) in your if statement to see if a value was returned or not. This will evaluate to true if $row['other'] is in fact not set, or NULL. Quote Link to comment https://forums.phpfreaks.com/topic/129997-help-with-phpmysql-code-needs-to-be-done-soon/#findComment-674556 Share on other sites More sharing options...
skiingguru1611 Posted October 25, 2008 Author Share Posted October 25, 2008 Kenshintomoe225, I feel this could help. I used the following code, but when there is no entry in the DB the page showed up blank. When it was in the in the DB it showed up with the fields values set to the corresponding values in the DB. Could you check out the code and help me out please? <?php $db_name="***"; $connection=mysql_connect("localhost","***","****") or die("I Couldn't connect"); $db=mysql_select_db($db_name,$connection) or die("I Couldn't select your database"); $table="player"; // Table name $sql="select user, first, last, birth, address, city, state, zip, email, grade, team, coach, height, weight, gpa, sat, phone, other from $table WHERE user='$user'"; $result=mysql_query($sql,$connection) or die(mysql_error()); if(!isset($row['user'])){ while($row=mysql_fetch_array($result)) { ?> <form method="post" action="../player/insertupdate.php"> <input type="hidden" name="user" value="<?php echo $user; ?>"> <p>First Name <input type="text" name="first" maxlength="20" value="<?php echo $row['first']; ?>"> Last Name <input type="text" name="last" maxlength="20" value="<?php echo $row['last']; ?>"> </p> <p>Birth Date <input type="text" name="birth" maxlength="20" value="<?php echo $row['birth']; ?>"> Address <input type="text" name="address" maxlength="50" value="<?php echo $row['address']; ?>"> </p> <p> City <input type="text" name="city" maxlength="20" value="<?php echo $row['city']; ?>"> State <select name="state" value="<?php echo $row['state']; ?>"> # <option value="">None</option> # <option value="AL">Alabama</option> # <option value="AK">Alaska</option> # <option value="AZ">Arizona</option> # <option value="AR">Arkansas</option> # <option value="CA">California</option> # <option value="CO">Colorado</option> # <option value="CT">Connecticut</option> # <option value="DC">District of Columbia</option> # <option value="DE">Delaware</option> # <option value="FL">Florida</option> # <option value="GA">Georgia</option> # <option value="HI">Hawaii</option> # <option value="ID">Idaho</option> # <option value="IL">Illinois</option> # <option value="IN">Indiana</option> # <option value="IA">Iowa</option> # <option value="KS">Kansas</option> # <option value="KY">Kentucky</option> # <option value="LA">Louisiana</option> # <option value="ME">Maine</option> # <option value="MD">Maryland</option> # <option value="MA">Massachusetts</option> # <option value="MI">Michigan</option> # <option value="MN">Minnesota</option> # <option value="MS">Mississippi</option> # <option value="MO">Missouri</option> # <option value="MT">Montana</option> # <option value="NE">Nebraska</option> # <option value="NV">Nevada</option> # <option value="NH">New Hampshire</option> # <option value="NJ">New Jersey</option> # <option value="NM">New Mexico</option> # <option value="NY">New York</option> # <option value="NC">North Carolina</option> # <option value="ND">North Dakota</option> # <option value="OH">Ohio</option> # <option value="OK">Oklahoma</option> # <option value="OR">Oregon</option> # <option value="PA">Pennsylvania</option> # <option value="PR">Puerto Rico</option> # <option value="RI">Rhode Island</option> # <option value="SC">South Carolina</option> # <option value="SD">South Dakota</option> # <option value="TN">Tennessee</option> # <option value="TX">Texas</option> # <option value="UT">Utah</option> # <option value="VT">Vermont</option> # <option value="VA">Virginia</option> # <option value="WA">Washington</option> # <option value="WV">West Virginia</option> # <option value="WI">Wisconsin</option> # <option value="WY">Wyoming</option> # </select> Zipcode <input type="text" name="zip" maxlength="5" value="<?php echo $row['zip']; ?>"> </p> <p>Phone ex.(555) 555-5555 <input type="text" name="phone" maxlength="20" value="<?php echo $row['phone']; ?>"> Email <input type="text" name="email" maxlength="50" value="<?php echo $row['email']; ?>"> </p> <p>Grade <input type="text" name="grade" maxlength="10" value="<?php echo $row['grade']; ?>"> School <input type="text" name="team" maxlength="20" value="<?php echo $row['team']; ?>"> </p> <p>Coach <input type="text" name="coach" maxlength="20" value="<?php echo $row['coach']; ?>"> Height <input type="text" name="height" maxlength="10" value="<?php echo $row['height']; ?>"> Weight <input type="text" name="weight" maxlength="10" value="<?php echo $row['weight']; ?>"> </p> <p>Grade Point Average (GPA) <input type="text" name="gpa" maxlength="10" value="<?php echo $row['gpa']; ?>"> SAT Score <input type="text" name="sat" maxlength="5" value="<?php echo $row['sat']; ?>"> </p> <p> Notable Academic and Athletic Achievments: (2500 Character Maximum) </p> <textarea name="other" rows="10" cols="50"><?php echo $row['other']; ?> </textarea> <p><input type="submit" value="Submit"></p> </form> <?php } }else{ ?> <form method="post" action="../player/insertplayer.php"> <p>First Name <input type="text" name="first" maxlength="20"> Last Name <input type="text" name="last" maxlength="20"> </p> <p>Birth Date <input type="text" name="birth" maxlength="20"> Address <input type="text" name="address" maxlength="50"> </p> <p> City <input type="text" name="city" maxlength="20"> State <select name="state"> # <option value="">None</option> # <option value="AL">Alabama</option> # <option value="AK">Alaska</option> # <option value="AZ">Arizona</option> # <option value="AR">Arkansas</option> # <option value="CA">California</option> # <option value="CO">Colorado</option> # <option value="CT">Connecticut</option> # <option value="DC">District of Columbia</option> # <option value="DE">Delaware</option> # <option value="FL">Florida</option> # <option value="GA">Georgia</option> # <option value="HI">Hawaii</option> # <option value="ID">Idaho</option> # <option value="IL">Illinois</option> # <option value="IN">Indiana</option> # <option value="IA">Iowa</option> # <option value="KS">Kansas</option> # <option value="KY">Kentucky</option> # <option value="LA">Louisiana</option> # <option value="ME">Maine</option> # <option value="MD">Maryland</option> # <option value="MA">Massachusetts</option> # <option value="MI">Michigan</option> # <option value="MN">Minnesota</option> # <option value="MS">Mississippi</option> # <option value="MO">Missouri</option> # <option value="MT">Montana</option> # <option value="NE">Nebraska</option> # <option value="NV">Nevada</option> # <option value="NH">New Hampshire</option> # <option value="NJ">New Jersey</option> # <option value="NM">New Mexico</option> # <option value="NY">New York</option> # <option value="NC">North Carolina</option> # <option value="ND">North Dakota</option> # <option value="OH">Ohio</option> # <option value="OK">Oklahoma</option> # <option value="OR">Oregon</option> # <option value="PA">Pennsylvania</option> # <option value="PR">Puerto Rico</option> # <option value="RI">Rhode Island</option> # <option value="SC">South Carolina</option> # <option value="SD">South Dakota</option> # <option value="TN">Tennessee</option> # <option value="TX">Texas</option> # <option value="UT">Utah</option> # <option value="VT">Vermont</option> # <option value="VA">Virginia</option> # <option value="WA">Washington</option> # <option value="WV">West Virginia</option> # <option value="WI">Wisconsin</option> # <option value="WY">Wyoming</option> # </select> Zipcode <input type="text" name="zip" maxlength="5" > </p> <p>Phone ex.(555) 555-5555 <input type="text" name="phone" maxlength="20"> Email <input type="text" name="email" maxlength="50"> </p> <p>Grade <input type="text" name="grade" maxlength="10"> <?php $host="localhost"; // Host name $username="****"; // Mysql username $password="***"; // Mysql password $db_name="****"; // Database name $tbl_name="teams"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // Retrieve data from database $sql="SELECT team FROM $tbl_name ORDER BY team"; $result=mysql_query($sql); ?> School <select name = "team"> <?php // Start looping rows in mysql database. while($rows=mysql_fetch_array($result)){ ?> <option value = <?php echo $rows['team']; ?>><?php echo $rows['team']; ?></option> <?php // close while loop } // close connection mysql_close(); ?> </select> </p> <p>Coach <input type="text" name="coach" maxlength="20"> Height <input type="text" name="height" maxlength="10"> Weight <input type="text" name="weight" maxlength="10"> </p> <p>Grade Point Average (GPA) <input type="text" name="gpa" maxlength="10"> SAT Score <input type="text" name="sat" maxlength="5"> </p> <p> Notable Academic and Athletic Achievments: (2500 Character Maximum) </p> <textarea name="other" rows="10" cols="50"> </textarea> <p><input type="submit" value="Submit"></p> </form> <?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/129997-help-with-phpmysql-code-needs-to-be-done-soon/#findComment-674623 Share on other sites More sharing options...
kenshintomoe225 Posted October 25, 2008 Share Posted October 25, 2008 What do the error logs of your webserver say? Look for the most recent entry. Quote Link to comment https://forums.phpfreaks.com/topic/129997-help-with-phpmysql-code-needs-to-be-done-soon/#findComment-674628 Share on other sites More sharing options...
skiingguru1611 Posted October 25, 2008 Author Share Posted October 25, 2008 The only thing it says is that my favicon.ico file does not exist. Which I'm not worried about right now. I looked in the Apache Error Logs. Is that what you meant? Quote Link to comment https://forums.phpfreaks.com/topic/129997-help-with-phpmysql-code-needs-to-be-done-soon/#findComment-674634 Share on other sites More sharing options...
kenshintomoe225 Posted October 25, 2008 Share Posted October 25, 2008 !isset($row['user']) will evaluate to true, and execute the body code whenever $row['user'] is NOT set. If it is not set, and you then try to echo it out, you're gonna run into problems. Quote Link to comment https://forums.phpfreaks.com/topic/129997-help-with-phpmysql-code-needs-to-be-done-soon/#findComment-674672 Share on other sites More sharing options...
skiingguru1611 Posted October 25, 2008 Author Share Posted October 25, 2008 I switched which form went in the "else" and which went in the "if". However it still doesn't execute the "else" statement, whether or not there is something in the DB. Quote Link to comment https://forums.phpfreaks.com/topic/129997-help-with-phpmysql-code-needs-to-be-done-soon/#findComment-674678 Share on other sites More sharing options...
kenshintomoe225 Posted October 25, 2008 Share Posted October 25, 2008 did you move your while loop when you moved the forms? You said you moved the form from the if body to the else body, did you move that while loop along with it? Quote Link to comment https://forums.phpfreaks.com/topic/129997-help-with-phpmysql-code-needs-to-be-done-soon/#findComment-674699 Share on other sites More sharing options...
skiingguru1611 Posted October 25, 2008 Author Share Posted October 25, 2008 No, I didn't move it at first. I just moved it and now it just displays the "if" statement (the one that is supposed to show up if there is no entry in the DB) all the time. Quote Link to comment https://forums.phpfreaks.com/topic/129997-help-with-phpmysql-code-needs-to-be-done-soon/#findComment-674704 Share on other sites More sharing options...
kenshintomoe225 Posted October 25, 2008 Share Posted October 25, 2008 ok, thats a start. Now what I want you to do is copy and paste your sql query into the sql command line and run it, that way we can see what the query actually returns when run. Quote Link to comment https://forums.phpfreaks.com/topic/129997-help-with-phpmysql-code-needs-to-be-done-soon/#findComment-674706 Share on other sites More sharing options...
skiingguru1611 Posted October 25, 2008 Author Share Posted October 25, 2008 This sql query selects what I need when the code runs correctly. select user, first, last, birth, address, city, state, zip, email, grade, team, coach, height, weight, gpa, sat, phone, other from $table WHERE user='$user' Quote Link to comment https://forums.phpfreaks.com/topic/129997-help-with-phpmysql-code-needs-to-be-done-soon/#findComment-674708 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.