Jump to content

Help me!! :/


mizz key_me

Recommended Posts

hye everyone..im a newbie here.. ;)

actually, i hav a project based on php and db..

i hav 2 submit it in 3 weeks time...

the prob is..the more i've done the coding..the more i get soo confused.. ???

 

lets just be clear..im doing a project based on a school system..

the main thing is about the registration 4 new students..

 

example like i want 2 make the list 4 the staff 2 view bout the new students based on their gender...

so i make this drop down menu consists of male and female..(of coz!!  ;D)

and the list will only view based on the gender that they choose...

 

how do i code it so that my page will only appear the student list based on their gender..

 

plizz...i really need to understand it.. thanx alott..

Link to comment
Share on other sites

hye everyone..im a newbie here.. ;)

actually, i hav a project based on php and db..

i hav 2 submit it in 3 weeks time...

the prob is..the more i've done the coding..the more i get soo confused.. ???

 

lets just be clear..im doing a project based on a school system..

the main thing is about the registration 4 new students..

 

example like i want 2 make the list 4 the staff 2 view bout the new students based on their gender...

so i make this drop down menu consists of male and female..(of coz!! ;D)

and the list will only view based on the gender that they choose...

 

how do i code it so that my page will only appear the student list based on their gender..

 

plizz...i really need to understand it.. thanx alott..

 

hey baby il help u, u see u need to do alot so do it bit by bit and tell us where u get stuck,

 

1. make the drop down menu (male female) and a submit button, the page must submit to itself so in teh form action writ ethe name of teh php file u are in

 

2. the page will submit to itself so it needs to know what has been submited at teh top of teh page when it sarts to load again so ask if u need to do this

 

3. when it knows that teh page has submited to itself it needs to then get a list of the males or females based on the input feild that has been posted $_post['gender'] and print it out

 

 

 

sooooo just for you babs heres the code

 

<?php
include 'db_connect.php';
if($_post['gender']) {
	$result = mysql_query("SELECT student_name, student_gender, student_regno FROM student WHERE student_gender = '".$_POST['gender']."' ");

	while($row = mysql_fetch_array($result)){
		echo $row['student_name'];
		echo $row['student_gender'];
		echo $row['student_regno'];
	{

}

?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<select name="gender">
   	<option value="male">male</option>
       <option value="female">female</option>
   </select>
   <br>
   <br>
   <input type="submit" value="submit" name="submit">
</form>

 

 

look in teh databse and see what teh values for gender are and modify

 

<option value="male">male</option>

<option value="female">female</option>

 

it shoudl be ok anyways

 

which uni do u go to ?

Link to comment
Share on other sites

Here's some smaple code that should get you started.

 

<?php

# Check to see if the user has submitted the form
if ( isset($_POST['gender']) ) {

# Define gender as male/female depending on selection
$gender = ( $_POST['gender'] == '1' ? 'female' : 'male' );

# Build your query
$query = "SELECT `name` FROM `students` WHERE `gender` = '$gender'";
# Execute
$result = mysql_query( $query );
# Echo results
while( $data = mysql_fetch_assoc($result) )
	echo $data['name'] . "<br />\n";
}

?>

<br /><br />
<h3>What gender would you like to view?</h3>
<form action="" method="post">
  <input type="radio" name="gender" value="0" /> Male
  <br />
  <input type="radio" name="gender" value="1" /> Female
  <br /><br />
  <input type="submit" name="submit" />
</form>

Link to comment
Share on other sites

thanx alot discomatt and nadeemshafi9  :)

 

i've tried both codes but still cant preview it..

 

@nadeemshafi9: can u please tell me how to do it from the first step?? im really stuck.. :-\

                      besides, im studying in UiTM in Malaysia.. :) and you??

 

@discomatt: i've tried your codes. The table turns out perfectly but the data was not there...

 

Thanx again..

 

Link to comment
Share on other sites

Mine won't 'just work'... you have to fill in your own database values. I'm not here to code for you, I'm here to help you.

 

And just for the record, nadeemshafi9's code is wide open for injection. You're better off using 2 non-descriptive values ( I used 1 and 0 ) and replace with expect values manually. This will prevent any user input from being in the query.

 

Also, thanks for replying in a slightly more formal manner ;) I will help you further if you show your modified version of the example I provided.

Link to comment
Share on other sites

@discomatt: i've already put the data in db...but i dont know why it does not appear in the table..

                  actually, for the registration report, i wanted to make 2 pages.

 

                  First page: Select Gender ( I've made a drop down menu for gender )

                  Second page: The data of the new students will appear based on the gender that the staff choose.

 

 

Link to comment
Share on other sites

okay2..my mistake.. ;D

 

here's the code for the first page

<form name="y1_gender" action="y1_report3.php" method="post">
<select name="gender">
    	<option value="Male">Male</option>
        <option value="Female">Female</option>
    </select>
    <br>
    <br>
    <input type="submit" value="submit" name="submit">
</form>

 

and here's for the second page

<?php 

include 'db_connect.php';
		if($_post['gender']) {
	$result = mysql_query("SELECT student_name, student_gender, student_regno FROM student WHERE student_gender = $y1_gender ");

	while($row = mysql_fetch_array($result)){
		echo $row['student_name'];
		echo $row['student_gender'];
		echo $row['student_regno'];
	{

}

?>

  
  <tr>
    <td><?php echo "".$row['student_name'];?></td>
    <td><?php echo "".$row['student_gender'];?></td>
    <td><?php echo "".$row['student_regno'];?></td>
    <td><div align="center"><a href="s_detail.php?student_name=<?php echo $row['student_name']; ?>" class="style2">Detail</a></div></td>
    <td><div align="center"><a href="s_edit.php?student_name=<?php echo $row['student_name']; ?>" class="style2">Edit</a></div></td>
    <td><div align="center"><a href="s_delete.php?student_name=<?php echo $row['student_name']; ?>" class="style2">Delete</a></div></td>
  </tr>

Link to comment
Share on other sites

it would appear that you're using nadeemshafi9's code... typos and all ;)

it would appear that you're using nadeemshafi9's code... typos and all ;)

 

i'm sorry, here's the your code that i use

<?php
if ( isset($_POST['student_gender']) ) {


$gender = ( $_POST['student_gender'] == '1' ? 'female' : 'male' );

$query = "SELECT `student_name, student_gender, student_regno FROM students WHERE gender = $gender";

$result = mysql_query( $query );

while( $data = mysql_fetch_assoc($result) )
	echo $data['name'] . "<br />\n";
}

?>

 
 <tr>
   <td><?php echo "".$row['student_name'];?></td>
   <td><?php echo "".$row['student_gender'];?></td>
   <td><?php echo "".$row['student_regno'];?></td>
   <td><div align="center"><a href="s_detail.php?student_name=<?php echo $row['student_name']; ?>" class="style2">Detail</a></div></td>
   <td><div align="center"><a href="s_edit.php?student_name=<?php echo $row['student_name']; ?>" class="style2">Edit</a></div></td>
   <td><div align="center"><a href="s_delete.php?student_name=<?php echo $row['student_name']; ?>" class="style2">Delete</a></div></td>
 </tr>


</table>

Link to comment
Share on other sites

Okay, first off... all string in MySQL must be enclosed in quotes

 

$query = "SELECT student_name, student_gender, student_regno FROM students WHERE gender = '$gender' ";

 

Second, look into WHILE

http://php.net/manual/en/control-structures.while.php

 

And learn how the WHILE loop works... then look into mysql_fetch_assoc()

http://php.net/manual/en/function.mysql-fetch-assoc.php

 

And learn how that function works. There's an example similar to what you want in that page. Read it up, give it another shot and let me know how you're doing.

Link to comment
Share on other sites

Mine won't 'just work'... you have to fill in your own database values. I'm not here to code for you, I'm here to help you.

 

And just for the record, nadeemshafi9's code is wide open for injection. You're better off using 2 non-descriptive values ( I used 1 and 0 ) and replace with expect values manually. This will prevent any user input from being in the query.

 

Also, thanks for replying in a slightly more formal manner ;) I will help you further if you show your modified version of the example I provided.

 

i dont think it matters if its unsafe code lol

Link to comment
Share on other sites

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.