selecting from database

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
franknu
Forum Contributor
Posts: 146
Joined: Sun May 28, 2006 9:29 am

selecting from database

Post by franknu »

ok, i am having couple of issues from a self form that needs to select databata from the database and update that date

my issue is that it is not updating or getting the data from the database..

here is my code

Code: Select all

if ($num_rows!=1)

{
print "<p><b>username and/or password not found. Try
again?</b></p>";
}
else

{
echo " Welcome";

echo '


<table border="0">
 <tr>

   <td valign="top">
   <table border="0">
        <tr>

        <td bgcolor="cococo">
<a href="index.php">

Home

<font color="cococo">ddddddddddddddddddddd</font>

</a>
		</td>

        </tr>
        <tr>
          <td>


		welcome $BusinessName,  
<font color="ffffff">dddddddddddddddddddfffffffffffffffffffdd</font> 
		  </td>
           </tr>
          </table>
        <table background="../images/fondo2.jpg"  border="1" valign="top">
          <tr> 
          <td valign="top">
		  <table border="1" background="../images/fondo2.jpg" valign="top">

<tr> 
            <td>
		  <a href= "http://entrepreneur.com">Pictures Uploads/change</a>
		  </td>
          </tr>

          <tr>
            <td>
		  <a href= "http://entrepreneur.com">Advertise your website</a>
		  </td>
          </tr>
          <tr> 
           <td>
		  </td>
          </tr>
          <tr> 
           <td>
<a href="http://69.89.27.201:2082/horde/index.php/">Email</a>
		 </td>
           </tr>
              <tr> 
                <td>
								</td>
              </tr>
              <tr>
                <td>
		<a href="http://www.nasdaq.com">Stock Market</a>
				</td>

              </tr>
            </table>
			</td>
          <td  valign="top"> 

            <center><table border="1">
			  <tr>
               <td>




<a href=\"update.php?update=true\">update</a>







			</td>
                <td>
	<a href=\"keyword.php?keyword=true\">Add Key words</a>
				</td>
                <td>
				<a href="http://www.ccbill.com">CCBILL</a>
				</td>
              </tr>

            </table> 




</center> ';

?>



<?PHP	
	 
$sql = "SELECT * FROM business_info WHERE BusinessName = '$BusinessName' AND User_Name = '$User_Name'";
$result = mysql_query($query) or die ("Problem with the query: <pre>$sql</pre><br>" . mysql_error());
$res2 = mysql_fetch_assoc($result); 

$BusinessName

?>


 if(isset($_POST["submit"]))
 
{

<?PHP

$query="UPDATE  business_info  SET BusinessName= '$BusinessName', `Slogan`='$Slogan',
               Business_Address = '$Business_Address', Tel='$Tel', Website= '$Website',
               Email = '$Email', Fax= '$Fax', `type`='$type',
               make = '$make', Categories = '$Categories', Keyword = '$Keyword',  Picture1 = '$Picture1',
               Headline = '$Headline', Slogan2 = '$Slogan2', Description1 = '$Description1',
               Description2 = '$Description2', Description3 =  '$Description3',
               Picture2 = '$Picture2', Picture3 = '$Picture3',
`Password`= '$Password' WHERE User_Name = '$User_Name'";


$result = mysql_query($query) or die ("Problem with the query: <pre>$query</pre><br>" . mysql_error());


?>


}


<?

echo'

<table bgcolor="ffffff">
  <tr>
    <td>
        <table>
          <tr>

                     </tr>
        </table>
      </td>
  </tr>
  <tr>
    <td></td>
  </tr>
  <tr>
    <td>
    <table> 
        <tr>

		  <td>

		<table bgcolor="ffffff ">
 <tr>
  <td>
<table>
?>


<?


<form action="<?php echo $_SERVER["PHP_SELF"] method="Post" >"  

 ?>






<tr>
    <td>
    Busiess Info
   </td>
  </tr>
  <tr>
    <td>
    <table>
        <tr>
          <td>
          Business Name
          </td>
          <td>






<input type="text" name="BusinessName"  Value="$BusinessName">

          </td>

        </tr>
        <tr>
          <td>
          Slogan
          </td>

          <td>

          <input type="text" NAME="Slogan" value="$Slogan">

          </td>
          <td>
          Website
          </td>

          <td> <input type="text" name="Website" value="$Website">
          </td>
       </tr>

        <tr>

          <td>
          Tel
          </td>

          <td>
          <input type="text" name="Tel" value="$Tel">
         </td>

          <td>
          Key Words
          </td>
          <td>
        <input type="text" name="Keyword" value="$Keyword">

       
       </td>

       </tr>
        <tr>
          <td>
          Fax
         </td>

          <td>
          <input type="text" name="Fax" value="$fax">
          </td> 

          <td>
         Address
         
          </td>
          <td> <input type="text" name="Business_Address" value="$Business_Address">
           </td>

       </tr>

      </table>
      </td>

  </tr>
  <tr>
    <td>

	<table>
        <tr>
         <td>
          </td>
          <td>
          </td>

          <td>
         
          </td>

          <td> 

				  </td>
          <td>

 </tr>
  <tr>
    <td>
    <input type="submit"  value="Update my database" name="submit" />
        <input type="reset" value="Reset fields" />
      <td> 
  </form>

>
  </tr>
</table> ';

}

?>

here is my display
if(isset($_POST["submit"])) { }


?> " ?>

and only the variables on the value space
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

Code: Select all

print_r($_POST); // to see which varialbes have been posted yes or no.

Code: Select all

$sql = "SELECT * FROM business_info WHERE BusinessName = '$BusinessName' AND User_Name = '$User_Name'"; 
$result = mysql_query($query) or die ("Problem with the query: <pre>$sql</pre><br>" . mysql_error()); 
$res2 = mysql_fetch_assoc($result); 
// What are you trying to do here ?
print_r($res)
$BusinessName  // ???
Now i must say that the page as posted above is kinda messy!

Try reorganising that page a bit, do things step by step, for what i can see above is that everyting is mixed.

Basic Example

Code: Select all

if (isset($_POST['submit']) && $loggedin==true) {
   #update query 
   # display thank you or whatever
   exit;
}

if ($loggedin == true) { // you could use $_SESSION
     # query select from database where username=whatever or userID=000
     # show the form
} else {
     # show login form
}
Last edited by ol4pr0 on Fri Mar 30, 2007 4:04 pm, edited 1 time in total.
franknu
Forum Contributor
Posts: 146
Joined: Sun May 28, 2006 9:29 am

Post by franknu »

ok that is a <form action="<?php echo $_SERVER["PHP_SELF"] method="Post" >"

the user type in the user name and password it goes to a member page where the user can make changes to a page

Code: Select all

here it should select the info from the database

$sql = "SELECT * FROM business_info WHERE BusinessName = '$BusinessName' AND User_Name = '$User_Name'"; 
$result = mysql_query($query) or die ("Problem with the query: <pre>$sql</pre><br>" . mysql_error()); 
$res2 = mysql_fetch_assoc($result); 


so it should selct from the database business info where business name match and the username
// down here show the name of the business
$BusinessName
print_r($_POST) was not working for me...
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

franknu wrote: // down here show the name of the business
$BusinessName
Read some more about retrieving data from youre database, search this forum you will find alot of examples
print_r($_POST) was not working for me...
That doesnt surprise me, look at youre code.

Code: Select all

<? // php tags
<form action="<?php echo $_SERVER["PHP_SELF"] method="Post" >" #<-- NO ERROR ? php tags inside php tags ?
 ?>

Code: Select all

// example... 
while ($frow = mysql_fetch_assoc($res)) {
    echo $frow["businessname"];
    echo $frow["nombre_completo"];
    echo $frow["status_usuario"];
}
More info either search this FORUM or take a look at http://www.php.net/mysql_fetch_assoc
franknu
Forum Contributor
Posts: 146
Joined: Sun May 28, 2006 9:29 am

Post by franknu »

i think that i have not problem selecting from database

actually this was working but i had echo in every single line

i decided to changed it and that is when the problem started

all i need it was a little light

maybe i was doing something that i couldn't see
Post Reply