Note that there are some explanatory texts on larger screens.

plurals
  1. POMySQL PHP insert and update
    primarykey
    data
    text
    <p>I am a little lost being new to databases. I am trying to create a page/form that, from a link only the admin can see, pulls in that $id's information from the database, displays it so that each field can be updated and saves it back to the database. I also added a form at the bottom of the page to input a new field into the database. For simplicity sake I put them on one page but I can separate them out if needed. My code does not work yet and any help would be greatly appreciated.</p> <pre><code>echo "&lt;a href=\"test.html?p=ID{$row["id"]}\"&gt;Edit&lt;/a&gt;&lt;br&gt;"; </code></pre> <p>spits out a link to test.html?p=ID(#) The link part is working perfectly.</p> <p>Admin page</p> <pre><code>&lt;div&gt;&lt;h1 class="pageTitle"&gt;Episode List UPDATE&lt;/h1&gt;&lt;/div&gt; &lt;?php // Connect to the database require 'include/episodelist.db.php'; // Ask the database for the information from the season table BUT how to only get info for the ID? $query="SELECT * FROM `season` WHERE `id` = $id"; $result = mysql_query("SELECT * FROM season"); $num=mysql_numrows($result); mysql_close(); ?&gt; &lt;form action="include/epslist.update.php" method="POST"&gt; &lt;table&gt; &lt;tr&gt; &lt;td&gt;Season Number: &lt;/td&gt;&lt;td&gt;&lt;input type="text" name="season_sum" size="50" value="&lt;? echo "$season_num";?&gt;"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Episode Number: &lt;/td&gt;&lt;td&gt;&lt;input type="text" name="eps_num" size="50" value="&lt;? echo "$eps_num";?&gt;"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Temp Episode Number: &lt;/td&gt;&lt;td&gt;&lt;input type="text" name="temp_eps_num" size="50" value="&lt;? echo "$temp_eps_num";?&gt;"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Title: &lt;/td&gt;&lt;td&gt;&lt;input type="text" name="title" size="50" value="&lt;? echo "$title";?&gt;"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Description: &lt;/td&gt;&lt;td&gt;&lt;textarea type="text" name="descrip" cols="50" rows="7" value="&lt;? echo "$descrip";?&gt;"&gt;&lt;/textarea&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td colspan="2"&gt; &lt;input type="Submit" value="Update"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt;&lt;/form&gt; &lt;div class="Down10px"&gt;&lt;/div&gt; &lt;div&gt;&lt;h1 class="pageTitle"&gt;Episode List NEW&lt;/h1&gt;&lt;/div&gt; &lt;form action="include/epslist.new.php" method="POST"&gt; &lt;table&gt; &lt;tr&gt; &lt;td&gt;Season Number: &lt;/td&gt;&lt;td&gt;&lt;input type="text" name="season_sum" size="50" value="&lt;? echo "$season_num";?&gt;"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Episode Number: &lt;/td&gt;&lt;td&gt;&lt;input type="text" name="eps_num" size="50" value="&lt;? echo "$eps_num";?&gt;"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Temp Episode Number: &lt;/td&gt;&lt;td&gt;&lt;input type="text" name="temp_eps_num" size="50"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Title: &lt;/td&gt;&lt;td&gt;&lt;input type="text" name="title" size="50"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Description: &lt;/td&gt;&lt;td&gt;&lt;textarea type="text" name="descrip" cols="50" rows="7"&gt;&lt;/textarea&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td colspan="2"&gt; &lt;input type="Submit" value="New Item"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt;&lt;/form&gt; </code></pre> <p>epslist.update.php</p> <pre><code>&lt;?php require "episodelist.db.php"; //Test for user inout if (!empty($_GET[season_sum])&amp;&amp; !empty($_GET[eps_num])&amp;&amp; !empty($_GET[temp_eps_num])&amp;&amp; !empty($_GET[title])&amp;&amp; !empty($_GET[descrip])) { // Im at a lost how to pull in the data just for test.html&amp;=edit(#), check if a user changed it, then if so update that value in the database // Trying to redirect the user back to the list once the update is finished header("Location:"); ?&gt; </code></pre> <p>epslist.new.php <strong>UPDATED</strong></p> <pre><code>&lt;?php require "episodelist.db.php"; //Test for user inout if (!empty($_POST[season_sum])&amp;&amp; !empty($_POST[eps_num])&amp;&amp; !empty($_POST[temp_eps_num])&amp;&amp; !empty($_POST[title])&amp;&amp; !empty($_POST[descrip])) { $season_sum = mysqlclean($_POST,"season_sum",$link); $eps_num = mysqlclean($_POST,"eps_num",$link); $temp_eps_num = mysqlclean($_POST,"temp_eps_num",$link); $title = mysqlclean($_POST,"title",$link); //This is a text area cols 50 rows 7 $descrip = mysqlclean($_POST,"descrip",$link); $ID = mysqlclean($_POST,"id",$link); } if ( ! empty($_POST['ID'])) $id = (int)$_POST['ID']; else $id = 'NULL'; //Insert new entry $query = "INSERT INTO `season` (`ID`, `season_num`, `temp_eps_num`, `esp_num`, `title`, `descrip`) VALUES ({$id}, '{$season_sum}', '{$eps_num}', '{$temp_eps_num}', '{$title}', '{$descrip}')"; // Trying to rederect the user back to the list once the update is successfully finished header("Location: episodelist_superadmin.html"); ?&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