atrocious Posted February 26, 2009 Share Posted February 26, 2009 Hi everyone, I am new to php and my sql. I want to do something for my website with php and mysql. here is what I want to do. a) The user fills the forum (application) with all his details etc and when he/she click the submit button all the information gets stored in the database. b) there is an admin page where admin can login can have universal or a unique password to check the recent application , Additionally he/she can will add necessary comments and which would be saved to the particular application. c) now the user who applied can come back to a separate page and check his application status by his name. d) if the admin approves the application he should be able to delete and modify and or edit the application. I am able to make all the html pages my issue is with php code and mysql integration..can i please give me an example if available or a code for php and mysql integration..it will be very helpful. ----------------------------------------------------------------------------------------------- Here is what i've done so far. as you have already seen my application forum above if not here it is again www.atrocious.comuf.com/apply.html I used the below php code to connect and then insert the data into the database. Also note that i made a new database called "databasename" by mysql and i went into phpmyadmin and created a new table called "application" and i made 12 fields there to insert all these information. Now i uploaded these files to my server, went into the application page filled the forum up. When i hit the submit button i get an error saying, "Error: Unknown column 'Rank' in 'field list' Any solutions to this? note that in my forums the text box field have the same name as in the post filed below.... <?php $con = mysql_connect ( "myhost" , "databasename" , "pass" ) or die("Error connecting: <br><br>".mysql_error()); mysql_select_db( "databasename" ) or die("Error getting db: <br><br>".mysql_error()); $sql="INSERT INTO application (IGN, Rank, Age, Kdr, Whyjoin, Preclan, Hack, Email, Mapmode, Reco, Refer, Agree) VALUES ('$_POST[id]','$_POST[Rank]','$_POST[Age]','$_POST[Kdr]','$_POST[Whyjoin]','$_POST[Preclan]','$_POST[Hack]','$_POST','$_POST[Mapmode]','$_POST[Reco]','$_POST[Refer]','$_POST[Agree]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo " Thank you."; mysql_close($con) ?> Quote Link to comment https://forums.phpfreaks.com/topic/147080-need-to-tweak-the-code-please-help-now-php-mysql-thanks-in-advance/ Share on other sites More sharing options...
revraz Posted February 26, 2009 Share Posted February 26, 2009 Your error means what it says, there is no Rank column in your Database. Post your DB structure. Quote Link to comment https://forums.phpfreaks.com/topic/147080-need-to-tweak-the-code-please-help-now-php-mysql-thanks-in-advance/#findComment-772135 Share on other sites More sharing options...
samshel Posted February 26, 2009 Share Posted February 26, 2009 1) does your table have field called Rank ? [check case too, i m not sure if it causes problems] 2) use back ticks to mark fields in query, to avoid problems with key words. $sql="INSERT INTO application (`IGN`, `Rank`, `Age`, `Kdr`, `Whyjoin`, `Preclan`, `Hack`, `Email`, `Mapmode`, `Reco`, `Refer`, `Agree`) VALUES ('$_POST[id]','$_POST[Rank]','$_POST[Age]','$_POST[Kdr]','$_POST[Whyjoin]','$_POST[Preclan]','$_POST[Hack]','$_POST[Email]','$_POST[Mapmode]','$_POST[Reco]','$_POST[Refer]','$_POST[Agree]')"; TIP: avoid using upper case letters in table and field names, always using lower case letters helps in avoiding mismatch problems. Quote Link to comment https://forums.phpfreaks.com/topic/147080-need-to-tweak-the-code-please-help-now-php-mysql-thanks-in-advance/#findComment-772138 Share on other sites More sharing options...
atrocious Posted February 26, 2009 Author Share Posted February 26, 2009 That error was correct. I did not have that in my table and i've fixed that but i get an error again... Is there something wrong with my code? I get a huge error this time. ".mysql_error()); mysql_select_db( "databasename" ) or die("Error getting db: ".mysql_error()); $sql="INSERT INTO application (IGN, Rank, Age, Kdr, Whyjoin, Preclan, Hack, Email, Mapmode, Reco, Refer, Agree) VALUES ('$_POST[id]','$_POST[Rank]','$_POST[Age]','$_POST[Kdr]','$_POST[Whyjoin]','$_POST[Preclan]','$_POST[Hack]','$_POST','$_POST[Mapmode]','$_POST[Reco]','$_POST[Refer]','$_POST[Agree]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo " Thank you."; mysql_close($con) ?> Quote Link to comment https://forums.phpfreaks.com/topic/147080-need-to-tweak-the-code-please-help-now-php-mysql-thanks-in-advance/#findComment-772147 Share on other sites More sharing options...
revraz Posted February 26, 2009 Share Posted February 26, 2009 Remove those BRs from your Error code so we can see where it's failing. Quote Link to comment https://forums.phpfreaks.com/topic/147080-need-to-tweak-the-code-please-help-now-php-mysql-thanks-in-advance/#findComment-772155 Share on other sites More sharing options...
atrocious Posted February 26, 2009 Author Share Posted February 26, 2009 BRs? Sorry i'm new to all this... Quote Link to comment https://forums.phpfreaks.com/topic/147080-need-to-tweak-the-code-please-help-now-php-mysql-thanks-in-advance/#findComment-772158 Share on other sites More sharing options...
revraz Posted February 26, 2009 Share Posted February 26, 2009 The Line Breaks $con = mysql_connect ( "myhost" , "databasename" , "pass" ) or die("Error connecting:".mysql_error()); mysql_select_db( "databasename" ) or die("Error getting db:".mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/147080-need-to-tweak-the-code-please-help-now-php-mysql-thanks-in-advance/#findComment-772162 Share on other sites More sharing options...
samshel Posted February 26, 2009 Share Posted February 26, 2009 always put ur code in between [ code ] [ / code ] tags. remove space in the tags..it makes the code readable. Quote Link to comment https://forums.phpfreaks.com/topic/147080-need-to-tweak-the-code-please-help-now-php-mysql-thanks-in-advance/#findComment-772163 Share on other sites More sharing options...
atrocious Posted February 26, 2009 Author Share Posted February 26, 2009 oh ok thanks. ".mysql_error()); mysql_select_db( "databasename" ) or die("Error getting db: ".mysql_error()); $sql="INSERT INTO application (IGN, Rank, Age, Kdr, Whyjoin, Preclan, Hack, Email, Mapmode, Reco, Refer, Agree) VALUES ('$_POST[id]','$_POST[Rank]','$_POST[Age]','$_POST[Kdr]','$_POST[Whyjoin]','$_POST[Preclan]','$_POST[Hack]','$_POST[Email]','$_POST[Mapmode]','$_POST[Reco]','$_POST[Refer]','$_POST[Agree]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo " Thank you."; mysql_close($con) ?> Quote Link to comment https://forums.phpfreaks.com/topic/147080-need-to-tweak-the-code-please-help-now-php-mysql-thanks-in-advance/#findComment-772166 Share on other sites More sharing options...
samshel Posted February 26, 2009 Share Posted February 26, 2009 what is the error? Quote Link to comment https://forums.phpfreaks.com/topic/147080-need-to-tweak-the-code-please-help-now-php-mysql-thanks-in-advance/#findComment-772170 Share on other sites More sharing options...
atrocious Posted February 26, 2009 Author Share Posted February 26, 2009 When i hit the submit button I get that whole thing as an error. Quote Link to comment https://forums.phpfreaks.com/topic/147080-need-to-tweak-the-code-please-help-now-php-mysql-thanks-in-advance/#findComment-772179 Share on other sites More sharing options...
samshel Posted February 26, 2009 Share Posted February 26, 2009 post ur whole code, u might be missing a semicolon or closing bracket somewhere. it generally never shows PHP code in the error. Quote Link to comment https://forums.phpfreaks.com/topic/147080-need-to-tweak-the-code-please-help-now-php-mysql-thanks-in-advance/#findComment-772185 Share on other sites More sharing options...
atrocious Posted February 26, 2009 Author Share Posted February 26, 2009 <?php $con = mysql_connect ( "myhost" , "databasename" , "pass" ) or die("Error connecting: <br><br>".mysql_error()); mysql_select_db( "databasename" ) or die("Error getting db: <br><br>".mysql_error()); $sql="INSERT INTO application (IGN, Rank, Age, Kdr, Whyjoin, Preclan, Hack, Email, Mapmode, Reco, Refer, Agree) VALUES ('$_POST[id]','$_POST[Rank]','$_POST[Age]','$_POST[Kdr]','$_POST[Whyjoin]','$_POST[Preclan]','$_POST[Hack]','$_POST[Email]','$_POST[Mapmode]','$_POST[Reco]','$_POST[Refer]','$_POST[Agree]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo " Thank you."; mysql_close($con) ?> this is all i have for the php file below is the forum section. <form id="application" name="app" method="post" action="application.php"> <div align="left"> <p>Q1. Enter your In Game Name <input name="id" type="text" id="id" maxlength="25" /> </p> <p>Q2. What is your Rank? <input name="Rank" type="text" id="Rank" /> </p> <p>Q3. What is your age? <input name="Age" type="text" width= 26 id="Age" /> </p> <p>Q4. What is your Kill/Death ratio? <input name="Kdr" type="text" width = 30 id="Kdr" /> </p> <p>Q5. Why would you like to join our clan?</p> <p align="center"> <textarea name="Whyjoin" rows=4 cols=48 id="Whyjoin"></textarea> </p> <p>Q6. Can you please list your previous clan and the reason why you left them?</p> <p align="center"> <textarea name="Preclan" cols=48id="preclan" rows=4 id="Preclan"></textarea> </p> <p align="left">Q7 Do you have any previous history of hacking? Be honest!</p> <p align="center"> <input name="Hack" type="text" id="Hack" /> </p> <p align="left">Q8. What is your Email Address? </p> <p align="center"> <input name="Email" type="text" id="Email" /> </p> <p align="left">Q9. What are your faviorate map and mode? </p> <p align="center"> <textarea name="Mapmode" cols=48id="fav" rows=4 id="Mapmode"></textarea> </p> <p>Q10. Did any of our clan members recomended you? If yes provie their IGN below.</p> <p align="center"> <input name="Reco" type="text" id="Reco" /> </p> <p>Q11. Finally, Where did you hear about us?</p> <p align="center"> <input name="Refer" type="text" id="Refer" /> </p> <p> <input name="Agree" type="checkbox" id="Agree" value="checkbox" /> By checking this button I agree that I have read the rules of the clan and will abide by the all the time.</p> <p align="center"> <input name="SubmitForum" type="submit" id="SubmitForum" value="Submit" /> <input name="reset" type="reset" id="reset" value="Reset" /> </p> </div> </form> Quote Link to comment https://forums.phpfreaks.com/topic/147080-need-to-tweak-the-code-please-help-now-php-mysql-thanks-in-advance/#findComment-772188 Share on other sites More sharing options...
samshel Posted February 26, 2009 Share Posted February 26, 2009 <?php $con = mysql_connect ( "myhost" , "databasename" , "pass" ) or die(mysql_error()); mysql_select_db( "databasename" ) or die(mysql_error()); not sure but u can try this...the code is breaking just before mysql_error()... Quote Link to comment https://forums.phpfreaks.com/topic/147080-need-to-tweak-the-code-please-help-now-php-mysql-thanks-in-advance/#findComment-772191 Share on other sites More sharing options...
atrocious Posted February 26, 2009 Author Share Posted February 26, 2009 You are awesome!!!! That definitely worked and i got the echo message printed out. When i looked up in phpmyadmin it says 1 query made today. But i dont see the text that i inserted in the forums? Any idea what might be going wrong? Quote Link to comment https://forums.phpfreaks.com/topic/147080-need-to-tweak-the-code-please-help-now-php-mysql-thanks-in-advance/#findComment-772192 Share on other sites More sharing options...
samshel Posted February 26, 2009 Share Posted February 26, 2009 echo out ur query... $sql="INSERT INTO application (IGN, Rank, Age, Kdr, Whyjoin, Preclan, Hack, Email, Mapmode, Reco, Refer, Agree) VALUES ('$_POST[id]','$_POST[Rank]','$_POST[Age]','$_POST[Kdr]','$_POST[Whyjoin]','$_POST[Preclan]','$_POST[Hack]','$_POST[Email]','$_POST[Mapmode]','$_POST[Reco]','$_POST[Refer]','$_POST[Agree]')"; echo $sql; $res = mysql_query($sql,$con) or die(mysql_error()); if(mysql_insert_id($res)) { echo "Thank You !!"; } else { echo "Insertion Failed !!"; } Quote Link to comment https://forums.phpfreaks.com/topic/147080-need-to-tweak-the-code-please-help-now-php-mysql-thanks-in-advance/#findComment-772194 Share on other sites More sharing options...
atrocious Posted February 27, 2009 Author Share Posted February 27, 2009 Ok great! Now i can see that in the table..... Phew took 5 hours thanks for saving the day. There is the check box at the bottom of my forums now how do i know if they checked or unchecked the box from the phpmyadmin. I think i list that its as BOOL in phpmyadmin. The value I get is 0 in that box. Now can you please give me a heads up on getting started on step (b) and © please. Quote Link to comment https://forums.phpfreaks.com/topic/147080-need-to-tweak-the-code-please-help-now-php-mysql-thanks-in-advance/#findComment-772198 Share on other sites More sharing options...
samshel Posted February 27, 2009 Share Posted February 27, 2009 yes u can store it as bool and add the value of checkbox and field name in the same insert query. Quote Link to comment https://forums.phpfreaks.com/topic/147080-need-to-tweak-the-code-please-help-now-php-mysql-thanks-in-advance/#findComment-772199 Share on other sites More sharing options...
atrocious Posted February 27, 2009 Author Share Posted February 27, 2009 Ok so i am working on part © now once after the user submits the application he/she comes back to check his/her status. The key here is ign or (in game name) I wrote a code but it will display everything that's stored in that table. Here is the code. <?php $con = mysql_connect("host" , "database" , "pw"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("databasename", $con); $result = mysql_query("SELECT * FROM application"); echo "<table border='1'> <tr> <th>In Game Name</th> <th>Comments:</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['ign'] . "</td>"; echo "<td>" . $row['comment'] . "</td>"; echo "</tr>"; } echo "</table>"; mysql_close($con); ?> Quote Link to comment https://forums.phpfreaks.com/topic/147080-need-to-tweak-the-code-please-help-now-php-mysql-thanks-in-advance/#findComment-772218 Share on other sites More sharing options...
samshel Posted February 27, 2009 Share Posted February 27, 2009 u need to filter on the username or a key like IGN..but next question would be how do we know which person is seeing the page.. you can put a login functionality in ur system and map the users with the IGN. u should get plenty of help on login in this forum. Quote Link to comment https://forums.phpfreaks.com/topic/147080-need-to-tweak-the-code-please-help-now-php-mysql-thanks-in-advance/#findComment-772221 Share on other sites More sharing options...
atrocious Posted February 27, 2009 Author Share Posted February 27, 2009 it really does not matter who is looking at the page in this context. Since it is the user but in admin page i will have the login functionality. but for this one all it does is displays everthing stored in that table. i only want their IGN and a comment field being displayed... can anyone modify the code ? Quote Link to comment https://forums.phpfreaks.com/topic/147080-need-to-tweak-the-code-please-help-now-php-mysql-thanks-in-advance/#findComment-772227 Share on other sites More sharing options...
samshel Posted February 27, 2009 Share Posted February 27, 2009 it should display only IGN and comment as per ur code.. check in phpmyadmin if the values are stored correctly, may be all data is in one field Quote Link to comment https://forums.phpfreaks.com/topic/147080-need-to-tweak-the-code-please-help-now-php-mysql-thanks-in-advance/#findComment-772232 Share on other sites More sharing options...
atrocious Posted February 27, 2009 Author Share Posted February 27, 2009 I think I need an if statement there looking for the IGN that the person is entering but i dont know how do i write that.... Quote Link to comment https://forums.phpfreaks.com/topic/147080-need-to-tweak-the-code-please-help-now-php-mysql-thanks-in-advance/#findComment-772272 Share on other sites More sharing options...
atrocious Posted February 27, 2009 Author Share Posted February 27, 2009 I need help guys, How do I exactly find what I am looking for in the checking status code. It displays the whole table. What I want is to make a query for the particular key entered by the user if that exists return the value if it does not then give an error saying it don't exist. Quote Link to comment https://forums.phpfreaks.com/topic/147080-need-to-tweak-the-code-please-help-now-php-mysql-thanks-in-advance/#findComment-772738 Share on other sites More sharing options...
samshel Posted February 27, 2009 Share Posted February 27, 2009 prepare a form first...just like u did for inserting asking only for IGN number with field name as ign..submit the form to your page above..and add the following code: <?php $con = mysql_connect("host" , "database" , "pw"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("databasename", $con); $ign = mysql_real_escape_string($_POST['ign']); $result = mysql_query("SELECT * FROM application WHERE `IGN` = '".$ign."'"); echo "<table border='1'> <tr> <th>In Game Name</th> <th>Comments:</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['ign'] . "</td>"; echo "<td>" . $row['comment'] . "</td>"; echo "</tr>"; } echo "</table>"; mysql_close($con); ?> Quote Link to comment https://forums.phpfreaks.com/topic/147080-need-to-tweak-the-code-please-help-now-php-mysql-thanks-in-advance/#findComment-772742 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.