Note that there are some explanatory texts on larger screens.

plurals
  1. POediting mysql table with html form
    primarykey
    data
    text
    <p>My aim is to have a simple, form based CMS so the client can log in and edit the MySQL table data via an html form. The login is working, but the edit page isn't returning the values from the MySQL table, nor am I getting any errors.</p> <p>I'm still amateur, and I first started the following code for a class project, but now plan to implement it for a live site. From what I understand I shouldn't have to declare the next/previous/etc. variables at the top, which I tried unsuccessfully to do so anyway. Does anything stand out to any of you?:</p> <pre><code>&lt;?php echo "&lt;h2&gt;Edit Special Offer&lt;/h2&gt;&lt;hr&gt;"; if (isset($_COOKIE["username"])) { echo "Welcome " . $_COOKIE["username"] . "!&lt;br /&gt;"; include "login.php"; } else echo "You need to log in to access this page.&lt;br /&gt;"; if(isset($previous)) { $query = "SELECT id, specialtitle, specialinfo FROM special WHERE id &lt; $id ORDER BY id DESC"; $result = mysql_query($query); check_mysql(); $row = mysql_fetch_row($result); check_mysql(); if ($row[0] &gt; 0) { $id = $row[0]; $specialtitle = $row[1]; $specialinfo = $row[2]; } } elseif (isset($next)) { $query = "SELECT id, specialtitle, specialinfo FROM special WHERE id &gt; $id ORDER BY id ASC"; $result = mysql_query($query); check_mysql(); $row = mysql_fetch_row($result); check_mysql(); if ($row[0] &gt; 0) { $id = $row[0]; $specialtitle = $row[1]; $specialinfo = $row[2]; } } elseif (isset($add)) { $query = "INSERT INTO special (specialtitle, specialinfo) VALUES ('$specialtitle', '$specialinfo')"; $result = mysql_query($query); check_mysql(); $id = mysql_insert_id(); $message = "Special Offer Added"; } elseif (isset($update)) { $query = "UPDATE special SET specialtitle='$specialtitle', specialinfo='$specialinfo' WHERE id = $id"; $result = mysql_query($query); check_mysql(); $id = mysql_insert_id(); $message = "Monthly Special Updated"; } elseif (isset($delete)) { $query = "DELETE FROM special WHERE id = $id"; $result = mysql_query($query); check_mysql(); $specialtitle = ""; $specialinfo = ""; $message = "Special Offer Deleted"; } $specialtitle = trim($specialtitle); $specialinfo = trim($specialinfo); ?&gt; &lt;form method="post" action="editspecial.php"&gt; &lt;p&gt;&lt;b&gt;Special Offer&lt;/b&gt; &lt;br&gt;&lt;input type="text" name="specialtitle" &lt;?php echo "VALUE=\"$specialtitle\"" ?&gt;&gt; &lt;/p&gt; &lt;p&gt;&lt;b&gt;Special Info/Description&lt;/b&gt; &lt;br&gt;&lt;textarea name="specialinfo" rows="8" cols="70" &gt; &lt;?php echo $specialinfo ?&gt; &lt;/textarea&gt; &lt;/p&gt; &lt;br&gt; &lt;input type="submit" name="previous" value="previous"&gt; &lt;input type="submit" name="next" value="next"&gt; &lt;br&gt;&lt;br&gt; &lt;input type="submit" name="add" value="Add"&gt; &lt;input type="submit" name="update" value="Update"&gt; &lt;input type="submit" name="delete" value="Delete"&gt; &lt;input type="hidden" name="id" &lt;?php echo "VALUE=\"$id\"" ?&gt;&gt; &lt;/form&gt; &lt;?php if (isset($message)) { echo "&lt;br&gt;$message"; } ?&gt; </code></pre> <p>Login.php:</p> <pre><code>&lt;?php function check_mysql() { if(mysql_errno()&gt;0) { die ("&lt;br&gt;" . mysql_errno().": ".mysql_error()."&lt;br&gt;"); } } $dbh=mysql_connect ("xxxxxxxxxxxxxxxxx","xxxxxxxx","xxxxxxxx"); if (!$dbh) { die ("Failed to open the Database"); } mysql_select_db("xxxxxx"); check_mysql(); if(!isset($id)) { $id=0; } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload