Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Form Script

3,611 views

Published on

Published in: Technology, Sports
  • Be the first to comment

  • Be the first to like this

Form Script

  1. 1. View Edit Delete<br />
  2. 2. View Data<br />&lt;?php<br />require_once (&apos;../../mysql/mysql_connect.php&apos;); <br /> $query = &quot;SELECT * FROM Tablename &quot;;<br />$result = mysql_query ($query);<br />$row = mysql_fetch_array ($result, MYSQL_ASSOC);<br />echo &apos;&lt;table cellspacing=&quot;2&quot; cellpadding=&quot;2&quot;&gt;&apos;;<br />echo &apos;&lt;table border=&quot;0&quot; cellspacing=&quot;3&quot; cellpadding=&quot;3&quot; align=&quot;center&quot;&gt;<br />&lt;tr&gt;<br />&lt;td align=&quot;left&quot; width=&quot;&quot;&gt;&lt;b&gt;Name&lt;/b&gt;&lt;/td&gt;<br />&lt;/tr&gt;&apos;;<br />// Display all the URLs.<br />$result = mysql_query ($query);<br />$total = mysql_num_rows ($result);<br />while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) <br />{<br /> // Display each record.<br />echo &quot;&lt;tr&gt;&lt;/tr&gt;&quot;;<br />echo &quot;&lt;td align=left&gt;&lt;a href=&quot;cooperator.php?coop=&quot;.$row[&apos;id&apos;].&quot;&quot;&gt;{$row[&apos;name&apos;]}&lt;/font&gt;&lt;/td&gt;&lt;/td&gt;&quot;;<br />echo &quot;&lt;td align=left&gt;&lt;a href=&quot;edit-coop.php?coop_id=&quot;.$row[&apos;id&apos;].&quot;&quot;&gt;Edit&lt;/font&gt;&lt;/td&gt;&quot;;<br />} // End of while loop.<br />echo &quot;&lt;tr&gt;&lt;/tr&gt;&quot;;<br />echo &quot;&lt;td align=&quot;left&quot;&gt;&lt;b&gt;$total&lt;/b&gt;&lt;/font&gt;&lt;/td&gt; &quot;;<br />echo &apos;&lt;/table&gt;&apos;; // Close the table.*/<br />mysql_close(); // Close the database connection.<br />?&gt;<br />
  3. 3. View Single Data<br />&lt;?php<br />require_once (&apos;../../mysql/mysql_connect.php&apos;); <br />if (is_numeric ($_GET[&apos;coop&apos;])) { // Make sure there&apos;s a print ID.<br />$query = &quot;SELECT * <br /> FROM Table_name&quot;;<br /> $result = mysql_query ($query);<br /> $row = mysql_fetch_array ($result, MYSQL_ASSOC);<br />mysql_close(); // Close the database connection.<br />} else { // Redirect<br /> //header (&quot;Location: http://&quot; . $_SERVER[&apos;HTTP_HOST&apos;] . dirname($_SERVER[&apos;PHP_SELF&apos;]) . &quot;/index.php&quot;);<br /> exit(&quot;No Cooperator Id is Present&quot;);<br />}<br /> echo &quot;&lt;TABLE&gt; &quot;;<br /> echo &quot;&lt;TR &gt;&lt;TD&gt;{$row[&apos;last_name&apos;]}&lt;/td&gt;&quot;;<br /> echo &quot;&lt;/TABLE&gt;&quot;;<br />?&gt;<br />
  4. 4. Edit<br />&lt;?php<br />require_once (&apos;../../mysql/mysql_connect.php&apos;); <br /> $coop_id = $_GET[&apos;coop_id&apos;];<br /> if(isset($_POST[&apos;submit&apos;]))<br /> {<br />first_name= $_POST[&apos;first_name&apos;];<br /> $result = mysql_query(&quot;UPDATE table SET first_name=&apos;$first_name&apos;&quot;,$connect);<br /> echo &quot;The Cooperator has been UPDATED Successfully!&quot;;<br /> }<br />elseif($id)<br />{<br />$result = mysql_query(&quot;SELECT * FROM table WHERE coop_id=&apos;$id&apos; &quot;,$connect);<br /> while($myrow = mysql_fetch_assoc($result))<br /> {<br />$first_name = $_POST[&quot;first_name&quot;];<br />?&gt;<br />
  5. 5. Edit Cont.<br />&lt;h3 align=&quot;center&quot;&gt;Edit &lt;? echo $myrow[&apos;first_name&apos;]?&gt; &lt;? echo $myrow[&apos;last_name&apos;]?&gt; Information&lt;/h3&gt;<br />&lt;form method=&quot;post&quot; action=&quot;&lt;?php echo $PHP_SELF ?&gt;&quot;&gt;<br />&lt;input type=&quot;hidden&quot; name=&quot;coop_id&quot; value=&quot;&lt;? echo $myrow[&apos;coop_id&apos;]?&gt;&quot;&gt;<br />&lt;table width=&quot;760&quot; border=&quot;0&quot; align=&quot;center&quot;&gt;<br /> &lt;tr&gt;<br /> &lt;td&gt;First Name&lt;/td&gt;<br /> &lt;td&gt;&lt;input name=&quot;first_name&quot; size=&quot;40&quot; maxlength=&quot;255&quot; value=&quot;&lt;? echo $myrow[&apos;first_name&apos;]?&gt;&quot; /&gt;&lt;/td&gt;<br /> &lt;/tr&gt;<br /> &lt;tr&gt;<br /> &lt;td&gt;&nbsp;&lt;/td&gt;<br /> &lt;td&gt;&lt;input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Update Information&quot; /&gt;&lt;/td&gt;<br /> &lt;/tr&gt;<br />&lt;/table&gt;<br />&lt;/form&gt;<br />&lt;?<br /> }//end of while loop<br /> }//end else<br />?&gt;<br />
  6. 6. Delete<br />&lt;?php<br />require_once (&apos;../../mysql/mysql_connect.php&apos;); <br /> $id = $_GET[‘name_id&apos;];<br /> $result = mysql_query(&quot;DELETE FROM table WHERE name_id=$id&quot;);<br /> echo &apos;Record has been deleted&apos;;<br />?&gt;<br />

×