/    Sign up×
Community /Pin to ProfileBookmark

MySQL Error messages

Howdy

Trying to make a drop down menu that interacts with my database and some fields on the page.

Trying to figure out these two errors

Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /home/scott/public_html/drop_down.php on line 3

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/scott/public_html/drop_down.php on line 3

[code=php]
<?php
$username = “xx”;
$password = “xx”;
$hostname = “xx”;
$dbh = mysql_connect($hostname, $username, $password) or die(“Unable to connect to MySQL”);
$selected = mysql_select_db(“xx”,$dbh) or die(“Could not select database”);
$query_seminars = (‘SELECT * FROM `Contacts`’);
$seminars = mysql_query($query_seminars) or die(mysql_error());
$row_seminars = mysql_fetch_assoc($seminars);
$totalRows_seminars = mysql_num_rows($seminars);

$colname_chosen_seminar = “-1”;
if (isset($_POST[‘Attend’])) {
$colname_chosen_seminar = (get_magic_quotes_gpc()) ? $_POST[‘Attend’] : addslashes($_POST[‘Attend’]);
}
mysql_select_db($database_CHF_PHP, $CHF_PHP);
$query_chosen_seminar = sprintf(“SELECT * FROM Permission_To_Camp WHERE id = %s”, $colname_chosen_seminar);
$chosen_seminar = mysql_query($query_chosen_seminar, $CHF_PHP) or die(mysql_error());
$row_chosen_seminar = mysql_fetch_assoc($chosen_seminar);
$totalRows_chosen_seminar = mysql_num_rows($chosen_seminar);
?>
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” “http://www.w3.org/TR/html4/loose.dtd”>
<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″>
<title>Untitled Document</title>
<script type=”text/javascript”>
function chkFrm(el){
if(el.selectedIndex == 0){
alert(“Please choose an option”);
return false
}
else{
el.form.submit();
}
}
</script>
</head>

<body>
<form name=”form1″ method=”post” action=””>
<p>
<select name=”Attend” onchange=”chkFrm(this)”>
<option value=”Choose” <?php if (!(strcmp(“Choose”, $_POST[‘Attend’]))) {echo “SELECTED”;} ?>>Choose Seminar</option>
<?php
do {
?>
<option value=”<?php echo $row_seminars[‘ID’]?>”<?php if (!(strcmp($row_seminars[‘ID’], $_POST[‘Attend’]))) {echo “SELECTED”;} ?>><?php echo $row_seminars[‘Attend’]?></option>
<?php
} while ($row_seminars = mysql_fetch_assoc($seminars));
$rows = mysql_num_rows($seminars);
if($rows > 0) {
mysql_data_seek($seminars, 0);
$row_seminars = mysql_fetch_assoc($seminars);
}
?>
</select>
</p>
<p>Location
<input name=”textfield” type=”text” value=”<?php echo $row_chosen_seminar[‘Location’]; ?>”>
<br>
From
<input name=”textfield” type=”text” value=”<?php echo $row_chosen_seminar[‘Fromto’]; ?>”>
<br>
Leader
<input name=”textfield” type=”text” value=”<?php echo $row_chosen_seminar[‘Leadership’]; ?>”>
</p>
</form>
</body>
</html>
[/code]

to post a comment
PHP

17 Comments(s)

Copy linkTweet thisAlerts:
@Mester_PedizFeb 15.2006 — dunno if it's the error but in: $query_seminars = ('SELECT * FROM Contacts');

you need to define what database you want to get the field data from

(i'll assume that 'Contacts' is a filed in you database)

something like: $query_seminars = ('SELECT 'Contacts' FROM 'your_database_name' WHERE 1');

(if the database name is Contacts it should be)

$query_seminars = ('SELECT * FROM 'Contacts' WHERE 1');
Copy linkTweet thisAlerts:
@scottyrobauthorFeb 15.2006 — Yay that worked, there both gone now.. lol but i now get


Parse error: parse error in /home/scott/public_html/drop_down.php on line 1
Copy linkTweet thisAlerts:
@Mester_PedizFeb 15.2006 — Hehe hmmm.

try to comment out "$selected = mysql_select_db("xx",$dbh) or die("Could not select database");"

I usually dont need that when i call the database name in the query
Copy linkTweet thisAlerts:
@scottyrobauthorFeb 15.2006 — :s what do you mean by that lol
Copy linkTweet thisAlerts:
@Mester_PedizFeb 15.2006 — just add // to comment the line out

//$selected = mysql_select_db("xx",$dbh) or die("Could not select database");
Copy linkTweet thisAlerts:
@scottyrobauthorFeb 15.2006 — parse error on line 2 now... lol
Copy linkTweet thisAlerts:
@NogDogFeb 15.2006 — Try this to maximize your chance of getting some useful debug info:
[code=php]
<?php
$username = "xx";
$password = "xx";
$hostname = "xx";

$dbh = @mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL");
$selected = @mysql_select_db("xx", $dbh) or die("Could not select database: " . mysql_error());
$query_seminars = ('SELECT * FROM Contacts');
$seminars = @mysql_query($query_seminars) or die("Query failed: $query_seminars - " . mysql_error());
[/code]
Copy linkTweet thisAlerts:
@NogDogFeb 15.2006 — If mysql_select_db does not work, you've got a problem which won't be avoided by just commenting it out.
Copy linkTweet thisAlerts:
@scottyrobauthorFeb 15.2006 — Ok well ive added the code you gave me, i changed it to suit me and found that i had made a spelling mistake in my table name. Fixed that but again i get this

http://scott.loddonexplorers.co.uk/drop_down.php

Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /home/scott/public_html/drop_down.php on line 3

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/scott/public_html/drop_down.php on line 3
Copy linkTweet thisAlerts:
@Mester_PedizFeb 15.2006 — heh heh oki then it wasen't there ?

ok then i dunno what it is.....
Copy linkTweet thisAlerts:
@NogDogFeb 15.2006 — Can you show us the current version of the source code?
Copy linkTweet thisAlerts:
@scottyrobauthorFeb 15.2006 — The table name is "Permission_To_Camp" just so you know!

[code=php]
<?php
$username = "xx";
$password = "xx";
$hostname = "xx";

$dbh = @mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL");
$selected = @mysql_select_db("xx", $dbh) or die("Could not select database: " . mysql_error());
$query_seminars = ('SELECT * FROM Permission_To_Camp');
$seminars = @mysql_query($query_seminars) or die("Query failed: $query_seminars - " . mysql_error());
$row_seminars = mysql_fetch_assoc($seminars);
$totalRows_seminars = mysql_num_rows($seminars);

$colname_chosen_seminar = "-1";
if (isset($_POST['Attend'])) {
$colname_chosen_seminar = (get_magic_quotes_gpc()) ? $_POST['Attend'] : addslashes($_POST['Attend']);
}
mysql_select_db($database_CHF_PHP, $CHF_PHP);
$query_chosen_seminar = sprintf("SELECT * FROM Permission_To_Camp WHERE id = %s", $colname_chosen_seminar);
$chosen_seminar = mysql_query($query_chosen_seminar, $CHF_PHP) or die(mysql_error());
$row_chosen_seminar = mysql_fetch_assoc($chosen_seminar);
$totalRows_chosen_seminar = mysql_num_rows($chosen_seminar);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script type="text/javascript">
function chkFrm(el){
if(el.selectedIndex == 0){
alert("Please choose an option");
return false
}
else{
el.form.submit();
}
}
</script>
</head>

<body>
<form name="form1" method="post" action="">
<p>
<select name="Attend" onchange="chkFrm(this)">
<option value="Choose" <?php if (!(strcmp("Choose", $_POST['Attend']))) {echo "SELECTED";} ?>>Choose Seminar</option>
<?php
do {

?>
<option value="<?php echo $row_seminars['ID']?>"<?php if (!(strcmp($row_seminars['ID'], $_POST['Attend']))) {echo "SELECTED";} ?>><?php echo $row_seminars['Attend']?></option>
<?php
} while ($row_seminars = mysql_fetch_assoc($seminars));
$rows = mysql_num_rows($seminars);
if($rows > 0) {
mysql_data_seek($seminars, 0);
$row_seminars = mysql_fetch_assoc($seminars);
}
?>
</select>
</p>
<p>Location

<input name="textfield" type="text" value="<?php echo $row_chosen_seminar['Location']; ?>">
<br>
From

<input name="textfield" type="text" value="<?php echo $row_chosen_seminar['Fromto']; ?>">
<br>
Leader
<input name="textfield" type="text" value="<?php echo $row_chosen_seminar['Leadership']; ?>">
</p>
</form>
</body>
</html>
[/code]
Copy linkTweet thisAlerts:
@NogDogFeb 15.2006 — The 2nd query section is using a link id of $CHF_PHP, but your link id is stored earlier in $dbh, so either change it to $dbh, or since you only have one mysql connection, just get rid of that optional argument.
Copy linkTweet thisAlerts:
@scottyrobauthorFeb 15.2006 — Thats great thanks very much for your help. Works now! I was editing someone elses script so that is proably why it caused so many problems!

Fet
Copy linkTweet thisAlerts:
@Mester_PedizFeb 15.2006 — Hmm i dunno if it's fixed now, but i just tried the page, and it comes up fine for me, with

a dropdown and 3 input boxes and no errors (this is in FireFox)
Copy linkTweet thisAlerts:
@scottyrobauthorFeb 15.2006 — Ok now that ive got this partialy working.. ive got 4 echo functions on pcform.php

I.E <?php echo $_POST['attend'];?>

How to i make it so that when i chose that data from the drop-down box it shows it in the fields, but then when i click a submit button it shoves the data from those fields into the next document?

Fet
Copy linkTweet thisAlerts:
@scottyrobauthorFeb 15.2006 — Anyone?
×

Success!

Help @scottyrob spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...