Page 1 of 1

showing values from the database

Posted: Mon Nov 27, 2006 3:30 pm
by franknu
I have a error in my updating form I want to show the data that is on the database so the user can see what is already there, i am just having a problem on my select statement


here is my error code:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' `Slogan=''`, `Business_Address`='', `Tel`='', `



here is my code

Code: Select all

?php
$host     = "localhost";
$username = "localhost";
$password = "abc123";
$database = "contacts";
 

$db = mysql_connect($host, $username, $password) or die(mysql_error()); 
mysql_select_db($database) or die(mysql_error()); 

$BusinessName = (isset($_POST['BusinessName']) ? $_POST['BusinessName'] : ''); 
$Slogan = (isset($_POST['Slogan']) ? $_POST['Slogan']:'');
$Business_Address = (isset($_POST['Business_Address']) ? $_POST['Business_Address']:'');
$Tel = (isset($_POST['Tel']) ? $_POST['Tel']:'');
$Website = (isset($_POST['Website']) ? $_POST['Website']:'');
$Email = (isset($_POST['Email']) ? $_POST['Email']:'');
$Member_Status = (isset($_POST['Member_Status']) ? $_POST['Member_Status']:'');
$Fax =(isset($_POST['Fax']) ? $_POST['Fax']:'');
$type = (isset($_POST['type']) ? $_POST['type']:'');
$make = (isset($_POST['make']) ? $_POST['make']:'');
$Categories = (isset($_POST['Categories']) ? $_POST['Categories']:'');
$Keyword = (isset($_POST['Keyword']) ? $_POST['Keyword']:'');
$Picture1 =  (isset($_POST['Picture1']) ? $_POST['Picture1']:'');
$Headline =  (isset($_POST['Headline']) ? $_POST['Headline']:'');
$Slogan2 = (isset($_POST['Slogan2']) ? $_POST['Slogan2']:'');
$Description1 = (isset($_POST['Description1']) ? $_POST['Description1']:'');
$Description2 = (isset($_POST['Description2']) ? $_POST['Description2']:'');
$Description3= (isset($_POST['Description3']) ? $_POST['Description3']:'');
$Contact2 = (isset($_POST['Contact2']) ? $_POST['Contact2']:'');
$Picture2 =  (isset($_POST['Picture2']) ? $_POST['Picture2']:'');
$Picture3 = (isset($_POST['Picture3']) ? $_POST['Picture3']:'');
$Picture4 =  (isset($_POST['Picture4']) ? $_POST['Picture4']:'');
$User_Name = (isset($_POST['User_Name']) ? $_POST['User_Name']:'');
$Password = (isset($_POST['Password']) ? $_POST['Password']: '');


$query = "SELECT * FROM business_info WHERE `BusinessName`= '$BusinessName', `Slogan='$Slogan'`,
               `Business_Address`='$Business_Address', `Tel`='$Tel', `Website`='$Website', 
               `Email`='$Email', `Member_Status`='$Member_Status', `Fax`='$Fax', `type`='$type',
               `make`='$make', `Categories`='$Categories', `Keyword`='$Keyword', `Picture1`='$Picture1', 
               `Headline`='$Headline', `Slogan2`='{$Slogan2}', `Description1`='$Description1',
               `Description2`='$Description2', `Description3`= '$Description3', `Contact2`='$Contact2',
               `Picture2`='$Picture2', `Picture3`='$Picture3', 
               `Password`='$Password', `User_Name`='$User_Name'";

$result = mysql_query($query) or die (mysql_error());

 if(isset($_POST['update'])) 
 {



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


$result = mysql_query($query) or die (mysql_error()); 
}

  ?> 
  
  
<table width="83%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td bordercolor="#FFFFFF" bgcolor="#FFFFFF"><div align="left"><br>
        <table width="96%" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
          <tr> 
            
            <td width="91%">
			<?
		
			include("../includefiles/logo.php"); 
			?>
			</td>
          </tr>
        </table>
      </div></td>
  </tr>
  <tr>
    <td><div align="center"></div></td>
  </tr>
  <tr>
    <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
         
		  <td width="94%">
		 
		 <table width="100%" border="0" cellpadding="0" cellspacing="0" background="../images/top_center_back2.jpg" bgcolor="#FFFFFF">
 <tr> 
  <td>				
<table width="100%" height="125" border="0" cellpadding="1" cellspacing="1">
	 <form  name="form"  method="Post" action="" >
  <tr> 
    <td background="../images/fondo2.jpg" bgcolor="#999966"><div align="center"><strong>Business Info</strong></div></td>
  </tr>
  <tr> 
    <td><table width="100%" border="0" cellspacing="1" cellpadding="1">
        <tr> 
          <td width="17%">Business Name</td>
          <td width="22%"><input type="text" name="BusinessName" value="<?  echo"$BusinessName"; ?>"> </td>
         
        </tr>
        <tr> 
          <td>Slogan</td>
          <td><input type="text" name="Slogan" value="<?php echo $Slogan ?>"></td>
          <td>Website</td>
          <td><input type="text" name="Website " value="<?php echo $Website ?>"></td>
        </tr>
        <tr> 
          <td>Tel</td>
          <td><input type="text" name="Tel" value="<?php echo $Tel?>"></td>
          <td>Key Words</td>
          <td><input type="text" name="Keyword  value="<?php echo $Keyword ?>"> </td>
        </tr>
        <tr> 
          <td>Fax</td>
          <td><input type="text" name="Fax" value="<?php echo $Fax ?>"> </td>
          <td>Address</td>
          <td><input type="text" name="Business_Address" value="<?php echo $Business_Address ?> "> </td>
        </tr>
      </table></td>
  </tr>
  <tr> 
    <td>
	
	<table width="101%" height="35" border="0" cellpadding="0" cellspacing="0">
        <tr> 
          <td width="13%">State</td>
          <td width="7%"> <select name="make" style="width:160px;"></td>
          
          <td width="16%">City</td>
          <td width="8%"><select name="type" style="width:160px;">
                  </select>
				  
				  </td>
          <td width="9%">Category</td>
          <td width="16%"> <TEXTAREA rows=3  name="Categories" value="<?php echo $Categories?>"> </TEXTAREA> </td>
         
        </tr>
      </table><br>
	  <table width="100%" border="0" cellspacing="1" cellpadding="1">
        <tr> 
          <td background="../images/fondo2.jpg" bgcolor="#CCCCCC"><div align="center"><strong><font color="#000000">Business 
                          Webpage</font></strong></div></td>
        </tr>
        <tr> 
          <td>Headline</td>
        </tr>
        <tr> 
          <td><input type="text" name="Headline" value="<?php echo $Headline?>"> </td>
        </tr>
        <tr> 
          <td>Slogan </td>
        </tr>
        <tr> 
          <td><input type="text" name="Slogan2" value="<?php echo $Slogan2?>" ></td>
        </tr>
        <tr> 
                      <td>Description1 </td>
        </tr>
        <tr> 
          <td><TEXTAREA ROWS=5 COLS=65 NAME="Description1" value="<?php echo $Description1 ?>" > </TEXTAREA></td>
        </tr>
        <tr> 
          <td>Description2</td>
        </tr>
        <tr> 
          <td><TEXTAREA ROWS=5 COLS=65 NAME="Description2" value="<?php echo $Description2 ?>"></TEXTAREA></td>
        </tr>
        <tr> 
          <td>Description3</td>
        </tr>
        <tr> 
          <td><TEXTAREA ROWS=5 COLS=65 NAME="Description3" value="<?php echo $Description3 ?> "></TEXTAREA></td>
        </tr>
        <tr> 
          <td>Contact Name
            <TEXTAREA ROWS=1 COLS=25 NAME="Contact2" value="<?php echo $Contact2 ?>"> </TEXTAREA></td>
        </tr>
        <tr> 
          <td>
		 
		 
           Picture1 
		   <input name="Picture1" type="file" value="<?php echo $Picture1?>">
		
		  		   
		   </td>
        </tr>
        <tr> 
          <td>Picture 2
		  <input name="Picture2" type="file" value="<?php echo $Picture2 ?>">
	   </td>
        </tr>
        <tr> 
          <td>Picture 3 <input name="Picture3" type="file" value="<?php echo $Picture3?>"></td>
        </tr>
		<tr> 
          <td>
		  Audio
		   <input name="Audio" type="file" value="<?php echo $Audio?>"> </td>
        </tr>
		<tr> 
          <td> 
		  Video
		  <input name="video" type="file" value="<?php echo $video?>"></td>
        </tr>
        <tr>
          <td><table width="100%" border="1" cellspacing="1" cellpadding="1">
              <tr>
                <td>User Name</td>
                <td><input type="text" name="User_Name"value="<?php echo $User_Name?>"></td>
                <td>Password</td>
                <td><input type="text" name="Password" value="<?php echo $Password?>"></td>
              </tr>
            </table></td>
        </tr>
      </table> </td>
  </tr>
  <tr> 
    <td background="../images/fondo2.jpg"> <div align="right">
    <input type="submit"  value="Update my database" name="update" />
        <input type="reset" value="Reset fields" />
      </div><td>
  </form>

</table>

</td>
          <td width="6%" valign="top" bgcolor="#FFFFFF">&nbsp;</td>
        </tr>
      </table>	 
	   </td>
</table>
  </tr>

</body>

</html>

Posted: Mon Nov 27, 2006 3:34 pm
by Burrito

Code: Select all

$query = "...`Slogan='$Slogan'`";
should be

Code: Select all

$query = "...`Slogan`='$Slogan'";

Posted: Mon Nov 27, 2006 3:45 pm
by franknu
i did that and i kept getting the same error

Posted: Mon Nov 27, 2006 3:47 pm
by Burrito
echo your query and make sure it's what you think it is.

in fact, post it here and let us have a look at it.

Posted: Mon Nov 27, 2006 3:54 pm
by franknu
here is my query

Code: Select all

$query = "SELECT * FROM business_info WHERE `BusinessName`= '$BusinessName',`Slogan`='$Slogan';
               `Business_Address`='$Business_Address',`Tel`='$Tel',`Website`='$Website', 
               `Email`='$Email', `Member_Status`='$Member_Status', `Fax`='$Fax', `type`='$type',
               `make`='$make', `Categories`='$Categories', `Keyword`='$Keyword', `Picture1`='$Picture1', 
               `Headline`='$Headline', `Slogan2`='{$Slogan2}', `Description1`='$Description1',
               `Description2`='$Description2', `Description3`= '$Description3', `Contact2`='$Contact2',
               `Picture2`='$Picture2', `Picture3`='$Picture3', 
               `Password`='$Password', `User_Name`='$User_Name'";

$result = mysql_query($query) or die (mysql_error());

Posted: Mon Nov 27, 2006 3:57 pm
by Burrito
I can see your query, but I asked you to echo it out so it's easier for us to read the real thing.

I can tell you right off, that your syntax isn't correct.

1) you have a semi-colon after your $Slogan var.
2) you need ANDs between your WHERE conditions, not commas.

Posted: Mon Nov 27, 2006 4:00 pm
by franknu
i have to query

but the update works fine becuase i worked with it before i just want to display the data so the user can see what he/she is changing

i did echo query and kept doing the same

Code: Select all

$query = "SELECT * FROM business_info WHERE `BusinessName`= '$BusinessName',`Slogan`='$Slogan'
               `Business_Address`='$Business_Address',`Tel`='$Tel',`Website`='$Website', 
               `Email`='$Email', `Member_Status`='$Member_Status', `Fax`='$Fax', `type`='$type',
               `make`='$make', `Categories`='$Categories', `Keyword`='$Keyword', `Picture1`='$Picture1', 
               `Headline`='$Headline', `Slogan2`='{$Slogan2}', `Description1`='$Description1',
               `Description2`='$Description2', `Description3`= '$Description3', `Contact2`='$Contact2',
               `Picture2`='$Picture2', `Picture3`='$Picture3', 
               `Password`='$Password', `User_Name`='$User_Name'";

$result = mysql_query($query) or die (mysql_error());

echo "$query";

 if(isset($_POST['update'])) 
 {



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


$result = mysql_query($query) or die (mysql_error()); 
}

  ?>

Posted: Mon Nov 27, 2006 4:04 pm
by Burrito

Code: Select all

$query = "SELECT * FROM business_info WHERE `BusinessName`= '$BusinessName' AND `Slogan`='$Slogan' AND
               `Business_Address`='$Business_Address' AND ...";
echo $query;
$result = mysql_query($query) or die (mysql_error());
my gut tells me that this isn't what you want though. I mean in terms of adding all of those conditions to match in your WHERE clause....

Posted: Mon Nov 27, 2006 4:07 pm
by franknu
ok, i did that and i got on the page

Code: Select all

SELECT * FROM business_info WHERE `BusinessName`= '' AND`Slogan`='' AND `Business_Address`='' AND`Tel`='' AND `Website`='' AND `Email`='' AND `Member_Status`=''AND `Fax`='' AND `type`='' AND `make`='' AND `Categories`='' AND `Keyword`='' AND `Picture1`='' AND `Headline`='' AND `Slogan2`='' AND `Description1`='' AND `Description2`='' AND `Description3`= '' AND `Contact2`='' AND `Picture2`='' AND `Picture3`='' AND `Password`='' AND `User_Name`='' 

and the form but with not data

all i want is to display the data. so the user can updated

i think that it is the only way i can dispaly the data that is on the database

Posted: Mon Nov 27, 2006 4:14 pm
by Burrito
I changed the highlighting to sql on your post.

assuming that this is indeed the query you want to run, you need to add some spaces between the conditions and the ANDs in a few places.

Posted: Mon Nov 27, 2006 4:19 pm
by franknu
so it should be `Slogan`="" AND `Business_Address`=""

instead of

`Slogan`='$Slogan' AND `Business_Address`= '$Business_Address'

Posted: Mon Nov 27, 2006 4:41 pm
by Burrito
no, it should be:
`Slogan` = '$Slogan' AND `Business_Address` = '$Business_Address'
instead of
`Slogan` = '$Slogan'AND `Business_Address` = '$Business_Address'

obviously, that's just an example, but removing the spaces is what you need to do.

Posted: Mon Nov 27, 2006 4:49 pm
by franknu
well, i am not displaying anything in my text fields any reason why

here is my query

Code: Select all

$query = "SELECT * FROM business_info WHERE `BusinessName`= '$BusinessName' AND `Slogan`='$Slogan' AND
               `Business_Address`='$Business_Address' AND `Tel`='$Tel' AND `Website`='$Website' AND 
               `Email`='$Email' AND `Member_Status`='$Member_Status' AND `Fax`='$Fax' AND `type`='$type' AND
               `make`='$make' AND `Categories`='$Categories' AND `Keyword`='$Keyword' AND `Picture1`='$Picture1' AND 
               `Headline`='$Headline' AND `Slogan2`='{$Slogan2}' AND `Description1`='$Description1' AND
               `Description2`='$Description2' AND `Description3`= '$Description3' AND `Contact2`='$Contact2' AND
               `Picture2`='$Picture2' AND `Picture3`='$Picture3' AND
               `Password`='$Password' AND `User_Name`='$User_Name'";

$result = mysql_query($query) or die (mysql_error());

Posted: Mon Nov 27, 2006 4:59 pm
by Burrito
couple things:

1) as I alluded to before, your query is limiting your results A LOT by all of the conditions in the WHERE clause.
2) You have some basic errors in your HTML output (missing quotes etc) which should be made obvious by the syntax highlighting above
3) for textareas, you don't use the 'value' attribute, you put the value between the opening and closing tag

your fields only should be prepopulated if you submit the form with info in them....this is according the code you have written here anyway.

Posted: Mon Nov 27, 2006 5:18 pm
by RobertGonzalez
Do your rows have an id associated with them (you know, a primary key type field) where you can select on that. All of those WHERE clause criteria seem overkill for a simple select query. If there is one unique attribute for the user, select WHERE that_attribute_field = that_attribute, if you know what I mean.