Forum Moderators: coopster

Message Too Old, No Replies

Exporting Data from MySQL

Am I missing something on my script?

         

joe1182

10:45 pm on Dec 14, 2004 (gmt 0)

10+ Year Member



Below is the script I am using for an HTML form. The form only has a dropdown that gives the user the option of job s to select from. Once they select the job and click on the submit button I want it to display every item in the jobs respected row. I know this can be done but, not sure what I am missing. Can anyone tell me what I need to do to fix this?

<?php
$sql1 = mysql_connect ("localhost", "username", "password") or die ('I cannot connect to the database because: ' . mysql_error());
$dbh = mysql_select_db ("database");
$job = $_POST['job'];
$result = mysql_query('SELECT FROM jobs WHERE Job=$job');
$results = mysql_fetch_array ($result);
print $results;
?>

Salsa

11:36 pm on Dec 14, 2004 (gmt 0)

10+ Year Member



You haven't specified anything to SELECT. Have you thought of calling mysql_error() if!$result, like you did with mysql_connect()?

joe1182

1:15 am on Dec 15, 2004 (gmt 0)

10+ Year Member



the mysql_error says mysql_fetch_array is not valid

dreamcatcher

1:41 am on Dec 15, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You also need your $job variable between apostrophes:

$result = mysql_query("SELECT something FROM jobs WHERE Job='$job'");

Also, to show the data using mysql_fetch_array, you`ll need to use numerical or name indices, not just $result.

ie:

$result[0] or $result['name']

Hope that helps.

joe1182

11:12 am on Dec 15, 2004 (gmt 0)

10+ Year Member



Below is the code I am using. It says unexpected T-String on line 6. I am not quite sure where to put the mysql_num. Any help on this?

<?php
$sql1 = mysql_connect ("localhost", "username", "password") or die ('I cannot connect to the database because: ' . mysql_error());
$dbh = mysql_select_db ("database");
$job = $_POST['job'];
$result = mysql_query("SELECT * FROM jobs WHERE Job='$job'") or mysql_error();
$results = mysql_fetch_array mysql_num ($result[0], $result[1]);
print $results;
?>

joe1182

11:34 am on Dec 15, 2004 (gmt 0)

10+ Year Member



I re wrote the script and got it to work now. Thanks for all of the help.