Jump to content

Need to tweak the code! Please help now! php mysql, thanks in advance


Recommended Posts

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)

?>

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.

 

 

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) ?>

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());

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) ?>  

<?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>

<?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()...

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?

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 !!";
}



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.

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);
?>

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.

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 ?

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.

 

 

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);
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.