Jump to content

Error: Database not selected


ActaNonVerba1

Recommended Posts

Hey guys

 

I keep getting the error "Database not selected" with this script

<?php
session_start();
if ($_SESSION['adminlogin'] == 1){
	//Run
}
else {
header('Location: Log-In.php');
exit;
}
?>
<!DOCTYPE HTML>
<html lang="en-GB">
<head>
            <meta charset="utf-8">
            <!--Search Engine Meta Tags--> 
            <meta name="author" content="Worldwide Lighthouses">
            <meta name="keywords" content="Lighthouses,Lightships,Trinity House,Fog Signals,Fog Horns,Fresnel">
            <meta name="description" content="Worldwide Lighthouses is the number 1 source of information, pictures and videos on the Subject of Lighthouses and Lightships">
            <!--Stylesheets/Javascript-->
            <link rel="stylesheet" href="../../Page-Layout.css" media="screen and (min-width: 481px)">
            <link rel="stylesheet" href="../../Mobile-Page-Layout.css" media="only screen and (max-width:480px)">
            <!--Mobile Browser Support-->
            <meta name="viewport" content="width=320; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
            <!--IE Support-->
            <!--[if lt IE 9]><script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> <link rel="stylesheet" href="../Page-Layout.css"><![endif]-->
<meta name="application-name" content="Worldwide Lighthouses"> 
	<meta name="msapplication-starturl" content="http://worldwidelighthouses.com/"> 
        	<meta name="msapplication-tooltip" content="Worldwide Lighthouses: Your number one source of Lighthouse Information, Videos and Pictures"> 
        	<meta name="msapplication-task" content="name=Lighthouses;action-uri=http://worldwidelighthouses.com/Lighthouses.php;icon-uri=http://worldwidelighthouses.com/IE9/Lighthouses.ico"> 
        	<meta name="msapplication-task" content="name=Lightships;action-uri=http://worldwidelighthouses.com/Lightships.php;icon-uri=http://worldwidelighthouses.com/IE9/Lightships.ico"> 
	<meta name="msapplication-task" content="name=Fog Signals;action-uri=http://worldwidelighthouses.com/Fog-Signals.php;icon-uri=http://worldwidelighthouses.com/IE9/Fog-Signals.ico"> 
       		<meta name="msapplication-task" content="name=Glossary;action-uri=http://worldwidelighthouses.com/Glossary.php;icon-uri=http://worldwidelighthouses.com/IE9/Glossary.ico">
            	<title>Mailing List Administration | Worldwide Lighthouses</title> 
            </head>
<body>
  <header>
	<h1 id="WWLH">Worldwide Lighthouses</h1>
	<form method="get" action="http://www.worldwidelighthouses.com/Search/search.php" id="Search-Box">
		<input type="search" placeholder="Search Worldwide Lighthouses" name="query" id="query" size="30" value="" autocomplete="off">	
		<input type="submit" value="Search">
           		<input type="hidden" name="search" value="1"> 
  		</form>
</header> 	<nav>
  		<ul id="Nav">
		<li class="MenuButton" id="Index"><a href="../Index.php"><p class="Nav">Home</p></a></li>
       		<li class="MenuButton" id="Lighthouses"><a href="../Lighthouses.php"><p class="Nav">Lighthouses</p></a></li>
       		<li class="MenuButton" id="Lightships"><a href="../Lightships.php"><p class="Nav">Lightships</p></a></li>
       		<li class="MenuButton" id="FogSignals"><a href="../Fog-Signals.php"><p class="Nav">Fog Signals</p></a></li>
            <li class="MenuButton" id="Daymarks"><a href="../Daymarks.php"><p class="Nav">Daymarks</p></a></li>
            <li class="MenuButton" id="Buoys"><a href="../Buoys.php"><p class="Nav">Buoys</p></a></li>
       		<li id="MenuButtonLast"><a href="../Glossary.php"><p class="Nav">Glossary</p></a></li>
	</ul>
</nav>
        <?php
	if ($_SESSION['adminlogin']==1) {
		echo '<div id="logout">
			  <div style="float:left; width:30%; text-align:left;!important">
			  <a href="Log-In-Accept-Deny.php">Back to Admin Home</a>
			  </div>
			  <div style="float:right; width:70%;">
			  <a href="Logout.php">Log Out of Admin</a>
			  <p style="font-size:10px;">Always Sign Out when Finished!</p>
			  </div></div>';}
?> 
<article>
    <h1 class="Title">Update Contact Record</h1>
  <div class="Textbox"> 
<?
$id=$_GET['id'];
$username="worldw44_php";
$password="c@rtmeldrive41";
$database="worldw44_newsemail";
mysql_connect(localhost,$username,$password); 
$query="SELECT * FROM contacts WHERE id='$id'";
$result=mysql_query($query) or die( 'Error: ' . mysql_error() );
$num = mysql_num_rows($result); 
$i=0;
while ($i < $num) { 
$name=mysql_result($result,$i,"name");
$email=mysql_result($result,$i,"email");
?>
<form action="updated.php" method="post">
<input type="hidden" name="ud_id" value="<? echo $id; ?>">
Name: <input type="text" name="ud_first" value="<? echo $name; ?>"><br>
E-mail: <input type="text" name="ud_email" value="<? echo $email; ?>"><br>
<input type="Submit" value="Update">
</form>
<?
++$i;
}

mysql_close();
?>
      <?php
      if ($_SESSION['adminlogin'] == 1){
	echo "Logged in on server side.";
}?>
    </div>
</article>
    <footer>
    <ul>
	<li><a href="http://www.worldwidelighthouses.com/About.php">About</a></li>
        <li><a href="http://www.worldwidelighthouses.com/Contact-us.php">Contact</a></li>
        <li><a href="http://www.worldwidelighthouses.com/Use-Our-Media.php">Use our media</a></li>
        <li><a href="http://www.worldwidelighthouses.com/Search/search.php">Search</a></li>
        <li><a href="http://www.worldwidelighthouses.com/Social-Networking.php">Social</a></li>
        <li><a href="#Top">Back to top</a></li>
    </ul>
    <br>
    <br>
    	&#169; Worldwide Lighthouses <?php echo date("Y"); ?>
</footer>
</body>

 

I have no idea why?

 

Any help? AS far as my understanding i have selected it as "Contactinfo"?

 

Thanks

Danny

 

Link to comment
Share on other sites

Hey guys

 

I keep getting the error "Database not selected" with this script

<?php
session_start();
if ($_SESSION['adminlogin'] == 1){
	//Run
}
else {
header('Location: Log-In.php');
exit;
}
?>
<!DOCTYPE HTML>
<html lang="en-GB">
<head>
            <meta charset="utf-8">
            <!--Search Engine Meta Tags--> 
            <meta name="author" content="Worldwide Lighthouses">
            <meta name="keywords" content="Lighthouses,Lightships,Trinity House,Fog Signals,Fog Horns,Fresnel">
            <meta name="description" content="Worldwide Lighthouses is the number 1 source of information, pictures and videos on the Subject of Lighthouses and Lightships">
            <!--Stylesheets/Javascript-->
            <link rel="stylesheet" href="../../Page-Layout.css" media="screen and (min-width: 481px)">
            <link rel="stylesheet" href="../../Mobile-Page-Layout.css" media="only screen and (max-width:480px)">
            <!--Mobile Browser Support-->
            <meta name="viewport" content="width=320; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
            <!--IE Support-->
            <!--[if lt IE 9]><script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> <link rel="stylesheet" href="../Page-Layout.css"><![endif]-->
<meta name="application-name" content="Worldwide Lighthouses"> 
	<meta name="msapplication-starturl" content="http://worldwidelighthouses.com/"> 
        	<meta name="msapplication-tooltip" content="Worldwide Lighthouses: Your number one source of Lighthouse Information, Videos and Pictures"> 
        	<meta name="msapplication-task" content="name=Lighthouses;action-uri=http://worldwidelighthouses.com/Lighthouses.php;icon-uri=http://worldwidelighthouses.com/IE9/Lighthouses.ico"> 
        	<meta name="msapplication-task" content="name=Lightships;action-uri=http://worldwidelighthouses.com/Lightships.php;icon-uri=http://worldwidelighthouses.com/IE9/Lightships.ico"> 
	<meta name="msapplication-task" content="name=Fog Signals;action-uri=http://worldwidelighthouses.com/Fog-Signals.php;icon-uri=http://worldwidelighthouses.com/IE9/Fog-Signals.ico"> 
       		<meta name="msapplication-task" content="name=Glossary;action-uri=http://worldwidelighthouses.com/Glossary.php;icon-uri=http://worldwidelighthouses.com/IE9/Glossary.ico">
            	<title>Mailing List Administration | Worldwide Lighthouses</title> 
            </head>
<body>
  <header>
	<h1 id="WWLH">Worldwide Lighthouses</h1>
	<form method="get" action="http://www.worldwidelighthouses.com/Search/search.php" id="Search-Box">
		<input type="search" placeholder="Search Worldwide Lighthouses" name="query" id="query" size="30" value="" autocomplete="off">	
		<input type="submit" value="Search">
           		<input type="hidden" name="search" value="1"> 
  		</form>
</header> 	<nav>
  		<ul id="Nav">
		<li class="MenuButton" id="Index"><a href="../Index.php"><p class="Nav">Home</p></a></li>
       		<li class="MenuButton" id="Lighthouses"><a href="../Lighthouses.php"><p class="Nav">Lighthouses</p></a></li>
       		<li class="MenuButton" id="Lightships"><a href="../Lightships.php"><p class="Nav">Lightships</p></a></li>
       		<li class="MenuButton" id="FogSignals"><a href="../Fog-Signals.php"><p class="Nav">Fog Signals</p></a></li>
            <li class="MenuButton" id="Daymarks"><a href="../Daymarks.php"><p class="Nav">Daymarks</p></a></li>
            <li class="MenuButton" id="Buoys"><a href="../Buoys.php"><p class="Nav">Buoys</p></a></li>
       		<li id="MenuButtonLast"><a href="../Glossary.php"><p class="Nav">Glossary</p></a></li>
	</ul>
</nav>
        <?php
	if ($_SESSION['adminlogin']==1) {
		echo '<div id="logout">
			  <div style="float:left; width:30%; text-align:left;!important">
			  <a href="Log-In-Accept-Deny.php">Back to Admin Home</a>
			  </div>
			  <div style="float:right; width:70%;">
			  <a href="Logout.php">Log Out of Admin</a>
			  <p style="font-size:10px;">Always Sign Out when Finished!</p>
			  </div></div>';}
?> 
<article>
    <h1 class="Title">Update Contact Record</h1>
  <div class="Textbox"> 
<?
$id=$_GET['id'];
$username="worldw44_php";
$password="c@rtmeldrive41";
$database="worldw44_newsemail";
mysql_connect(localhost,$username,$password); 
$query="SELECT * FROM contacts WHERE id='$id'";
$result=mysql_query($query) or die( 'Error: ' . mysql_error() );
$num = mysql_num_rows($result); 
$i=0;
while ($i < $num) { 
$name=mysql_result($result,$i,"name");
$email=mysql_result($result,$i,"email");
?>
<form action="updated.php" method="post">
<input type="hidden" name="ud_id" value="<? echo $id; ?>">
Name: <input type="text" name="ud_first" value="<? echo $name; ?>"><br>
E-mail: <input type="text" name="ud_email" value="<? echo $email; ?>"><br>
<input type="Submit" value="Update">
</form>
<?
++$i;
}

mysql_close();
?>
      <?php
      if ($_SESSION['adminlogin'] == 1){
	echo "Logged in on server side.";
}?>
    </div>
</article>
    <footer>
    <ul>
	<li><a href="http://www.worldwidelighthouses.com/About.php">About</a></li>
        <li><a href="http://www.worldwidelighthouses.com/Contact-us.php">Contact</a></li>
        <li><a href="http://www.worldwidelighthouses.com/Use-Our-Media.php">Use our media</a></li>
        <li><a href="http://www.worldwidelighthouses.com/Search/search.php">Search</a></li>
        <li><a href="http://www.worldwidelighthouses.com/Social-Networking.php">Social</a></li>
        <li><a href="#Top">Back to top</a></li>
    </ul>
    <br>
    <br>
    	&#169; Worldwide Lighthouses <?php echo date("Y"); ?>
</footer>
</body>

 

I have no idea why?

 

Any help? AS far as my understanding i have selected it as "Contactinfo"?

 

Thanks

Danny

Where do you see that code at all?

 

You have to establish the connection to the database server, then select the database you'll be working on. So after your mysql_connect, (where localhost should be in quotes!), throw in:

 

mysql_select_db("databasename", "connectionvar");

 

Connectionvar isn't required, it's just the link identifier of your mysql_connect.

Link to comment
Share on other sites

Also, as a side note looking at your $id bit there, if I were your end user...I would have an easy time going to your URL like so:

 

http://yoursite.com/yourpage?id=1'; DROP TABLE contacts; --

 

And there goes your contacts table, vanish. To be honest for something like that, something as simple as changing $id=$_GET['id'] to:

$id = (int)$_GET['id'];

 

Should suffice, since it would make my sql query turn into "0".

 

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.