Jump to content

updating mysql table


austin.mad

Recommended Posts

[b][color=red]i could add a new record with the submit part but the update part is not working.
i dont get an error message..i need an urgent help..[/color][/b]


**************************************

<HTML>
<?php
include "config.php";


$con =@mysql_connect($server,$user,$pass);//connecting to server

if(!$con) { die("No connection to Database server");}

mysql_select_db($db,$con);//select database





if(isset($submit))
{

$article_name= $_REQUEST['name'] ;
$article_price = $_REQUEST['preis'];
$article_brandid = $_REQUEST['brand-name'];
$article_text = $_REQUEST['message'];


$sql ="INSERT INTO shop_article  (article_id, article_brandid, article_name, article_price,article_text, article_image)
VALUES ('', '$article_brandid', '$article_name', '$article_price', '$article_text','')";


$result = mysql_query($sql);

  if(!$result)
{
  echo 'There was a problem inserting your data into the databse please try again later';
}else {

echo " 1 record added" ;   
echo "<br><a href=\"myviewdb.php\">Alle Produkte</a>";
}

}


else if(isset($update))
{
$article_id= $_REQUEST['article_id'] ;


$article_name= $_REQUEST['name'] ;
$article_price = $_REQUEST['preis'];
$article_brandid =$_REQUEST['brand-name'];
$article_text = $_REQUEST['message'];


$sql="UPDATE shop_article SET article_name=''$article_name', article_price='$article_price', article_brandid='$article_brandid',
          article_text='$article_text', WHERE article_id='$article_id' ";


$result = mysql_query($sql);

echo "Thank you! Information updated.\n";

echo "<br><a href=\"myviewdb.php\">Alle Produkte</a>";

 


}
else if(isset($article_id))
{
$sql ="SELECT A.*,B.brand_name  from shop_article AS A,shop_brand AS B WHERE A.article_brandid=B.brand_id and article_id='$article_id'";

$result =mysql_query($sql);

$myrow = mysql_fetch_array($result);
?>
<form method="post" action="myaddedit.php">
<input type="hidden" name="article_id" value="<?php echo $myrow["$article_id"]; ?>"/>
 
  <div align="center">
    <table border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td align="right"><div class="txt" id="div2"><b> Name&nbsp;&nbsp;:</b></div></td>
        <td>&nbsp;</td>
        <td><input name="name" type="text" style="width: 150px" value="<?php echo $myrow["article_name"];?>" /></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td align="right"><div class="txt" id="div2"><b>Preis &nbsp;:</b></div></td>
        <td>&nbsp;</td>
        <td><input name="preis" type="text" style="width: 150px" value="<?php echo $myrow["article_price"];?>"  /></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td align="right"><div class="txt" id="div2"><b>Hersteller&nbsp;&nbsp;: </b></div></td>
        <td>&nbsp;</td>
        <td><select name="brand-name" style="width: 150px;">
              <option selected value=""><?php echo $myrow["brand_name"];?></option>
  <option  value="1">Franzis</option>
  <option  value="2">PowerQuest</option>
  <option value="3">Macromedia</option>
  <option value="4">McAfee</option>
  <option  value="5">Suse</option> 
</select><br>
</td>
      </tr>
       
      <tr>
        <td>&nbsp;</td>
      </tr>
   
      <tr>
        <td width="110" align="right" valign="top"><div class="txt" id="div2"><b>Beschreibung &nbsp;&nbsp;:</b></div></td>
        <td>&nbsp;</td>
        <td><textarea name="message" rows="5"  style="width: 150px; overflow: auto"><?php echo $myrow["article_text"];?></textarea></td>
      </tr>
    </table>
    <p>
      <input  type="Submit" name="update" value="Update Artikel" />

</p>
    <p>&nbsp;</p>
  </div>
</form>




<?php
}
else
{
?>
<form method="post" action="myaddedit.php">
 
 
  <div align="center">
    <table border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td align="right"><div class="txt" id="div2"><b> Name&nbsp;&nbsp;:</b></div></td>
        <td>&nbsp;</td>
        <td><input name="name" type="text" style="width: 150px" /></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td align="right"><div class="txt" id="div2"><b>Preis &nbsp;:</b></div></td>
        <td>&nbsp;</td>
        <td><input name="preis" type="text" style="width: 150px" /></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td align="right"><div class="txt" id="div2"><b>Hersteller&nbsp;&nbsp;: </b></div></td>
        <td>&nbsp;</td>
        <td><select name="brand-name" style="width: 150px;">
              <option selected value="No Value">---------</option>
  <option  value="1">Franzis</option>
  <option  value="2">PowerQuest</option>
  <option value="3">Macromedia</option>
  <option value="4">McAfee</option>
  <option  value="5">Suse</option> 
</select><br>
</td>
      </tr>
       
      <tr>
        <td>&nbsp;</td>
      </tr>
   
      <tr>
        <td width="110" align="right" valign="top"><div class="txt" id="div2"><b>Beschreibung &nbsp;&nbsp;:</b></div></td>
        <td>&nbsp;</td>
        <td><textarea name="message" rows="5"  style="width: 150px; overflow: auto"></textarea></td>
      </tr>
    </table>
    <p>
      <input  type="Submit" name="submit" value="Add" />

</p>
    <p>&nbsp;</p>
  </div>
</form>



<?php
}
?>
</HTML>
Link to comment
https://forums.phpfreaks.com/topic/32614-updating-mysql-table/
Share on other sites

copy and paste this exactly:
[code]
$sql= "UPDATE shop_article SET article_name='$article_name',article_price='$article_price',article_brandid='$article_brandid',article_text='$article_text' WHERE article_id='$article_id'";
$result = mysql_query($sql) or die(mysql_error());
[/code]
Link to comment
https://forums.phpfreaks.com/topic/32614-updating-mysql-table/#findComment-151713
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.