Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Help with this php quesiton please
Old 05-20-2010, 11:17 AM Help with this php quesiton please
Novice Talker

Posts: 8
Trades: 0
Hi I'm new to php and I'm currently stuck on this question:

Create a PHP page that contains a form that contains an xhtml selection list containing all the customer names (last name is sufficient) as the option text and the customer ID as the value for the option. The selection list must be created by
running an SQL query to obtain the data from the database. The form should have a submit and a rest button. The form should use task8.php as the
action and the method should be get.

what I have so far is as below:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Prac 3 Task 1</title>
</head>

<?PHP
$conn2 = mysql_connect("localhost", "twastudent", "prac3");
mysql_select_db("warehouse", $conn2)
or die ('Database not found ' . mysql_error() );
$sql = mysql_query("SELECT lastName, customerID FROM customer, $conn2)
or die ('Problem with query' . mysql_error());
?>
       
<body>
  <h1>Prac 3 Task 10 </h1>
  <form id="task10" action="task8.php" method="get">

  </form>
</body>
</html>
where all the information about the name and ID is already stored in a database.

Anyone have any idea where to start or what kind of functions should I use?
Izzy123 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-20-2010, 11:41 AM Re: Help with this php quesiton please
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Use mysql_fetch_array in a while loop to generate the list:
PHP Code:
<select>
<?php while($row mysql_fetch_array($sqlMYSQL_NUM)) : ?>
     <option value="<?php echo $row[1]; ?>"><?php echo $row[0]; ?></option>
<?php endwhile; ?>
</select>
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by NullPointer; 05-20-2010 at 11:46 AM..
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 05-20-2010, 11:42 AM Re: Help with this php quesiton please
Phunk Rabbit's Avatar
Ultra Talker

Posts: 255
Name: John Nerush
Location: Milton Keynes, UK
Trades: 0
You would use a while loop to create the select rows, example:

PHP Code:
<select>
<?php
while($result mysql_fetch_array($sql)){
     echo 
'<option value="' $result['lastName'] . '">' $result['lastName'] . '</option>';
}
?>
</select>

Last edited by Phunk Rabbit; 05-20-2010 at 11:43 AM.. Reason: fail html
Phunk Rabbit is offline
Reply With Quote
View Public Profile Visit Phunk Rabbit's homepage!
 
Old 05-20-2010, 11:44 AM Re: Help with this php quesiton please
Phunk Rabbit's Avatar
Ultra Talker

Posts: 255
Name: John Nerush
Location: Milton Keynes, UK
Trades: 0
Seems i am too slow, NullPointer beat me to it ^^
Phunk Rabbit is offline
Reply With Quote
View Public Profile Visit Phunk Rabbit's homepage!
 
Old 05-20-2010, 09:09 PM Re: Help with this php quesiton please
Novice Talker

Posts: 8
Trades: 0
I got this so far
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>...</title>
</head>      
 
<body>
<?PHP
$conn2 = mysql_connect("localhost", "twastudent", "prac3");
mysql_select_db("warehouse", $conn2)
or die ('Database not found ' . mysql_error() );
$sql = mysql_query("SELECT* FROM customer, $conn2)
or die ('Problem with query' . mysql_error());
?>

<select>
<?php while($row = mysql_fetch_array($sql)) { ?>
<option value="<?php echo $row['customerID'] ?>"><?php echo $row['lastName'] ?></option>
<?php } endwhile; ?>
</select>

  <form id="task10" action="task8.php" method="get">
<p><input type="submit" value="submit"> <input type="reset"  value="reset"/></p>
</body>
</html>
but when I try to run it, it state Parse error: syntax error, unexpected '?'on line 21

Anyone know what I did wrong?
Izzy123 is offline
Reply With Quote
View Public Profile
 
Old 05-20-2010, 09:19 PM Re: Help with this php quesiton please
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
2 things wrong:

1. You forgot 2 semicolons on this line (I added them):
PHP Code:
<option value="<?php echo $row['customerID']; ?>"><?php echo $row['lastName']; ?></option>
Either use the while-endwhile syntax or the brackets, not both:
PHP Code:
<?php } endwhile; ?>
In this case just remove the endwhile. Ex:

PHP Code:
while($foo) :
     
//code here
endwhile;

while(
$foo)
{
     
//code here

__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by NullPointer; 05-20-2010 at 09:21 PM..
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 05-20-2010, 10:14 PM Re: Help with this php quesiton please
Novice Talker

Posts: 8
Trades: 0
Thanks for the reply. I've corrected those errors, but the output still showing the same thing : Parse error: syntax error, unexpected '?' on line 21

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>...</title>
</head>      
 
<body>
<?PHP
$conn2 = mysql_connect("localhost", "twastudent", "prac3");
mysql_select_db("warehouse", $conn2)
or die ('Database not found ' . mysql_error() );
$sql = mysql_query("SELECT* FROM customer, $conn2)
or die ('Problem with query' . mysql_error());
?>

<select>
<?php while($row = mysql_fetch_array($sql)) { ?>
<option value="<?php echo $row['customerID']; ?>"><?php echo $row['lastName']; ?></option>
<?php } ?>
</select>

  <form id="task10" action="task8.php" method="get">
</form>
</body>
</html>
the error is still located at
Code:
<option value="<?php echo $row['customerID']; ?>"><?php echo $row['lastName']; ?></option>
Izzy123 is offline
Reply With Quote
View Public Profile
 
Old 05-20-2010, 11:30 PM Re: Help with this php quesiton please
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
You forgot a quote (") on this line:
PHP Code:
$sql mysql_query("SELECT* FROM customer, $conn2
Using an editor with syntax highlighting should reveal these types of mistakes.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 05-20-2010, 11:49 PM Re: Help with this php quesiton please
Novice Talker

Posts: 8
Trades: 0
Thanks so much for your help! it works now!
Izzy123 is offline
Reply With Quote
View Public Profile
 
Old 05-21-2010, 03:02 AM Re: Help with this php quesiton please
Junior Talker

Posts: 1
Trades: 0
In the get method the data made available to the action page ( where data is received ) by the URL so data can be seen in the address bar. Not advisable if you are sending login info like password etc. In the post method the data will be available as data blocks and not as query string in case of get method.
__________________
julia
juliasida is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Help with this php quesiton please
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.41517 seconds with 12 queries