Need help editing MySql rows


I am using the following script to add entries to a table ( the output is a html table that contains products name, description and price ) however I can only add scripts…but i also have to edit them and i don’t know how to proceed.

The script that ads the products to the table is listed below… any help would be greatly appreciated!


class simpleCMS {

  var $host;
  var $username;
  var $password;
  var $table;

  public function display_public() {
    $q = "SELECT * FROM produse ORDER BY created DESC LIMIT 3";
    $r = mysql_query($q);

    if ( $r !== false && mysql_num_rows($r) > 0 ) {
      while ( $a = mysql_fetch_assoc($r) ) {
        $numeprodus = stripslashes($a['numeprodus']);
        $pretprodus = stripslashes($a['pretprodus']);
        $descriereprodus = stripslashes($a['descriereprodus']);

        $entry_display .= <<<ENTRY_DISPLAY

    <table cellpadding="0" cellspacing="0" width="100%" style="border:1px solid:#000000;" border="1">
    <td> $numeprodus</td><td> $descriereprodus</td> <td>$pretprodus</td>

    } else {
      $entry_display = <<<ENTRY_DISPLAY

    <h2> Momentan nu exista nici un produs adaugat!</h2>

    $entry_display .= <<<ADMIN_OPTION

   <br> <p class="admin_link">
      <a href="{$_SERVER['PHP_SELF']}?admin=1">Add New</a>


    return $entry_display;

  public function display_admin() {
    return <<<FORMULAR_ADMIN

    <form action="{$_SERVER['PHP_SELF']}" method="post">
      <label for="numeprodus">numeprodus:</label><br />
      <input name="numeprodus" id="numeprodus" type="text" maxlength="150" />
      <div class="clear"></div>
       <label for="pretprodus">Pret Produs:</label><br />
      <input name="pretprodus" id="pretprodus" type="text" maxlength="150" />
      <div class="clear"></div>
      <label for="descriereprodus">Body Text:</label><br />
      <textarea name="descriereprodus" id="descriereprodus"></textarea>
      <div class="clear"></div>
      <input type="submit" value="Adauga!" />
    <br />
    <a href="display.php">Back to Home</a>


  public function write($p) {
      if ( $_POST['pretprodus'] )
      $pretprodus = mysql_real_escape_string($_POST['pretprodus']);
    if ( $_POST['numeprodus'] )
      $numeprodus = mysql_real_escape_string($_POST['numeprodus']);
    if ( $_POST['descriereprodus'])
      $descriereprodus = mysql_real_escape_string($_POST['descriereprodus']);
    if ( $numeprodus && $descriereprodus ) {
      $created = time();
      $sql = "INSERT INTO produse VALUES('$numeprodus','$descriereprodus','$pretprodus','$created')";
      return mysql_query($sql);
    } else {
      return false;

  public function connect() {
    mysql_connect($this->host,$this->username,$this->password) or die("Could not connect. " . mysql_error());
    mysql_select_db($this->table) or die("Could not select database. " . mysql_error());

    return $this->creazaDB();

  private function creazaDB() {
    $sql = <<<MySQL_QUERY
numeprodus        VARCHAR(150),
descriereprodus    TEXT,
pretprodus VARCHAR(150),
created        VARCHAR(100)

    return mysql_query($sql);



This is the query that ‘INSERTS’ your item:

$sql = "INSERT INTO produse VALUES('$numeprodus','$descriereprodus','$pretprodus','$created')"

You need to use the UPDATE function to edit rows.
Update Rows

Did you copy this from somewhere rather then write it, as the way it’s structured actually intimidated me. :stuck_out_tongue:


Thanks for your help!

Yes I have found it somewhere, made only a few modifications to it .

Will give it a try today!
Thanks again!

You can also try the REPLACE statement or even the insert… update on duplicate… syntax: