herhemi Posted February 21, 2007 Share Posted February 21, 2007 Hello, I am new to php and programming altogether, so this may be an easy one. I am trying to change the ADD, UPDATE and DELETE buttons to be radio buttons. Can someone help me out? <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html > <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Henry Books</title> </head> <body background="white" text="black"> <body bgcolor="#009933"> <img src="FrontPage.jpg"/> <div style="text-align: left; width: 797px;"><span style="font-weight: bold;"> <div style="text-align: Left;"> </span><big style="font-weight: bold;"><big> </big> <big style="color: rgb(255,0,255);"><big>Author Table</big></div> <form action="index2.php" method="post" enctype="application/x-www-form-urlencoded" name="controls" id="SelectTable" target="_self"> <br /> Please select one: <br /> <br> <h3 align="left"> <input type="AddAuthor" type="submit" id="Branch" value=" Add " onClick="submit();"> <input name="UpdateAuthor" type="submit" id="Publisher" value=" Update " onClick="submit();"> <input name="DeleteAuthor" type="submit" id="Author" value=" Delete " onClick="submit();"> </h3> </form> </td> <?PHP if (isset($_POST['Submit2'])) { echo('Operation cancelled.'); } if (! isset ($_POST['ListAuthor']) && ! isset ($_POST['AddAuthor']) && ! isset ($_POST['SubmitAuthor']) && ! isset ($_POST['UpdateAuthor']) && ! isset ($_POST['GoSubmit']) && ! isset ($_POST['EditAuthor']) && ! isset ($_POST['DeleteAuthor']) && ! isset ($_POST['DelSubmit']) && ! isset ($_POST['deltAuthor'])) if (isset( $_POST['ListAuthor']) ) { $dTable = 'Author'; echo("Listing info for table: ".$dTable.". "); listTable($dTable); } if (isset ($_POST['AddAuthor'])) { addAuthor(); } if (isset ($_POST['SubmitAuthor'])) { subAuthor($_POST['FirstName'], $_POST['LastName']); } if (isset ($_POST['UpdateAuthor'])) { updAuthor(); } if (isset ($_POST['GoSubmit']) && isset ($_POST['AuthorList'])) { editAuthor($_POST['AuthorList']); } if (isset ($_POST['EditAuthor']) ) { subUpdateAuthor($_POST['AuthorList'], $_POST['FirstName'], $_POST['LastName']); } if (isset ($_POST['DeleteAuthor'])) { delAuthor(); } if (isset ($_POST['DelSubmit']) && isset ($_POST['delList'])) { delShowAuthor($_POST['delList']); } if (isset ($_POST['deltAuthor']) ) { subDeleteAuthor($_POST['delList']); } ?> </p> <p> <?php function addAuthor() { global $host, $user, $psw, $db, $schema; require("globals.php"); echo('<form action="index.php" method="post" enctype="application/x-www-form-urlencoded" name="AddForm" target="_self"> <p align="center">Please add new Author:</p> <table width="250" border="0" cellspacing="0" cellpadding="0" align="center"> <tr> <td><div align="right">First Name: </div></td> <td><input name="FirstName" type="text" id="FirstName" size="15" maxlength="15" /></td> </tr> <tr> <td><div align="right">Last Name: </div></td> <td><input name="LastName" type="text" id="LastName" size="15" maxlength="15" /></td> </tr> </table> <p align="center"> <input type="submit" name="SubmitAuthor" value="Submit" onClick="submit()"/> <input type="submit" name="Submit2" value="Reset" action="index.php"/> </p> <p align="center"> Please click Submit to add or click Reset to clear. </p> <p align="center"> </p> </form> '); } ?> </p> <p> <?php function subAuthor($aFirst, $aLast) { global $host, $user, $psw, $db, $schema, $Authornums; require("globals.php"); $maxQuery = "Select max(authornum) as amax from henry.author"; $dbconn = pg_connect("host=$host user=$user dbname=$db password=$psw"); $result = pg_query($dbconn, $maxQuery) or die('Query failed: ' . pg_last_error()); $line = pg_fetch_array($result, null, PGSQL_ASSOC); $Authornums = $line['amax']; $Authornums = $Authornums + 1; $ANquery = "Select * from henry.author"; $dbconn = pg_connect("host=$host user=$user dbname=$db password=$psw"); $result = pg_query($dbconn, $ANquery) or die('Query failed: ' . pg_last_error()); if (isset ($_POST['SubmitAuthor'])) { if ($aFirst > "" && $aLast > "") { $query = "INSERT INTO henry.author VALUES (" .$Authornums. ", '" .$aLast. "', '" .$aFirst. "')"; $dbconn = pg_connect("host=$host user=$user dbname=$db password=$psw"); $result = pg_exec($dbconn, $query); echo("Your submission of author ".$aFirst." ".$aLast." was successful!"); } else { echo("Your submission failed, Please try again."); } } } ?> <p> <?php function updAuthor() { unset($authNum); unset($authFname); unset($authLname); unset($query); unset($result); global $host, $user, $psw, $db, $schema, $Authorlist; require("globals.php"); $dbconn = pg_connect("host=$host dbname=$db user=$user password=$psw") or die('Could not connect: ' . pg_last_error()); $query = "SELECT authornum, authorfirst, authorlast FROM ".$schema.".author ORDER BY authorlast, authorfirst"; $result = pg_query($query) or die('Query failed: ' . pg_last_error()); echo('<p align="center">Please Select an Author to update:</p>'); echo('</p> <form name="upAuthor" id="upAuthor" method="post" action="index.php" target="_self"> '); echo("<select name='AuthorList'>"); while ($line = pg_fetch_array($result, null, PGSQL_ASSOC)) { echo("\t<option value='".$line['authornum']."'>" .$line['authorfirst']." ".$line['authorlast']."\n"); } echo("</SELECT>"); echo('<input type="radio" name="GoSubmit" value="Submit" onClick="submit()"/>'); echo('</form>'); } ?> <p> <?php function editAuthor($Anum) { global $host, $user, $psw, $db, $schema; require("globals.php"); $ANquery = "SELECT * FROM henry.author WHERE authornum = ".$Anum; $dbconn = pg_connect("host=$host user=$user dbname=$db password=$psw"); $result = pg_query($dbconn, $ANquery) or die('Query failed: ' . pg_last_error()); $line = pg_fetch_array($result, null, PGSQL_ASSOC); echo('<form action="index.php" method="post" enctype="application/x-www-form-urlencoded" name="EditForm" target="_self"> <p align="center">Edit the Author information below:</p> <table width="250" border="0" cellspacing="0" cellpadding="0" align="center"> <tr> <td width="125"><div align="right">Author Number: </div></td> <td width="125">'.$Anum.' <input type="hidden" name="AuthorList" value="'.$Anum.'"> </td> </tr> <tr> <td><div align="right">First Name: </div></td> <td><input name="FirstName" type="text" id="FirstName" size="10" maxlength="10" value="'.trim($line['authorfirst']).'"/></td> </tr> <tr> <td><div align="right">Last Name: </div></td> <td><input name="LastName" type="text" id="LastName" size="10" maxlength="10" value="'.trim($line['authorlast']).'"/></td> </tr> </table> <p align="center"> <input type="radio" name="EditAuthor" value="Submit" onClick="submit()"/> <input type="radio" name="Submit2" value="Reset" action="index.php"/> </p> <p align="center">Please Click Submit to update or Reset to clear the form. </p> <p align="center"> </p> </form> '); } ?> <p> <?php function subUpdateAuthor($Anum, $aFirst, $aLast) { global $host, $user, $psw, $db, $schema; require("globals.php"); if (isset ($_POST['EditAuthor'])) { if ($aFirst > "" && $aLast > "") { $query = "UPDATE henry.author set authorfirst = '" .$aFirst. "', authorlast = '" .$aLast. "' where authornum = ".$Anum; $dbconn = pg_connect("host=$host user=$user dbname=$db password=$psw"); $result = pg_exec($dbconn, $query); echo("The change to author ".$aFirst." ".$aLast." was successful!"); } else { echo("The name was incomplete, Please try again."); } } } ?> <p> <?php function delAuthor() { unset($authNum); unset($authFname); unset($authLname); unset($query); unset($result); global $host, $user, $psw, $db, $schema, $Authorlist; require("globals.php"); $dbconn = pg_connect("host=$host dbname=$db user=$user password=$psw") or die('Could not connect: ' . pg_last_error()); $query = "SELECT authornum, authorfirst, authorlast FROM ".$schema.".author ORDER BY authorlast, authorfirst"; $result = pg_query($query) or die('Query failed: ' . pg_last_error()); echo('<p align="center">Please select an Author to delete:</p>'); echo('<p align="center"> <p> </p> <form name="delAuthor" id="delAuthor" method="post" action="index.php" target="_self"> '); echo("<select name='delList'>"); while ($line = pg_fetch_array($result, null, PGSQL_ASSOC)) { echo("\t<option value='".$line['authornum']."'>" .$line['authorfirst']." ".$line['authorlast']."\n"); } echo("</SELECT>"); echo('<input type="submit" name="DelSubmit" value="Submit" onClick="submit()"/>'); echo('</form>'); } ?> <p> <?php function delShowAuthor($Anum) { global $host, $user, $psw, $db, $schema; require("globals.php"); //file providing the credential to connect to the database $ANquery = "SELECT * FROM henry.author WHERE authornum = ".$Anum; $dbconn = pg_connect("host=$host user=$user dbname=$db password=$psw"); $result = pg_query($dbconn, $ANquery) or die('Query failed: ' . pg_last_error()); $line = pg_fetch_array($result, null, PGSQL_ASSOC); echo('<form action="index.php" method="post" enctype="application/x-www-form-urlencoded" name="ShowForm" target="_self"> <p align="center">You have selected the author below to be deleted:</p> <table width="250" border="0" cellspacing="0" cellpadding="0" align="center"> <tr> <td width="125"><div align="right">Author Number: </div></td> <td width="125">'.$Anum.'</div></td> <input type="hidden" name="delList" value="'.$Anum.'"> </td> </tr> <tr> <td><div align="right">First Name: </div></td> <td><input name="FirstName" type="hidden" id="FirstName" value="'.$line['authorfirst'].'">'); echo($line['authorfirst']); echo('</td> </tr> <tr> <td><div align="right">Last Name: </div></td> <td><input name="LastName" type="hidden" id="LastName" size="15" maxlength="15" value="'.$line['authorlast'].'">'); echo($line['authorlast']); echo('</td> </tr> </table> <p align="center"> <input type="submit" name="deltAuthor" value="Submit" onClick="submit()"/> <input type="submit" name="Submit2" value="Reset" action="index.php"/> </p> <p align="center">Click Submit to confirm or Click Reset to clear the form. </p> <p align="center"> </p> </form> '); } ?> </p> <p> <?php function subDeleteAuthor($Anum) { global $host, $user, $psw, $db, $schema; require("globals.php"); //file providing the credential to connect to the database if (isset ($_POST['deltAuthor'])) { $query = "DELETE FROM henry.author where authornum = ".$Anum; $dbconn = pg_connect("host=$host user=$user dbname=$db password=$psw"); $result = pg_exec($dbconn, $query); echo("Your deletion of author number ".$Anum." was successful!"); } else { echo("The Deletion failed, Please try again."); } } ?> </p> <p> </p> </p> </td> <td align="center" valign="top" class="box_right_line"> </td> </tr> </table></td> </tr> </table></td> </tr> </table></td> </tr> <tr> <td align="center" valign="top"><table width="669" border="0" cellspacing="0" cellpadding="0"> <tr> <td style="white-space:pre; font-size:11px; font-weight:normal; color:#FF00FF;" height="23" colspan="2" align="left" ><h3><a href="http://students.pointpark.edu/glthorn/glthorn.php">Home</a><h3></td> </tr> </tr> </table></td> </tr> </table></td> </tr> </table> </body> </html> Link to comment https://forums.phpfreaks.com/topic/39411-new-to-php/ Share on other sites More sharing options...
legohead6 Posted February 21, 2007 Share Posted February 21, 2007 thats a pretty hard code for a beginner, i would say to start simpler and find tutorials to get you going. Link to comment https://forums.phpfreaks.com/topic/39411-new-to-php/#findComment-190113 Share on other sites More sharing options...
Archadian Posted February 21, 2007 Share Posted February 21, 2007 That code is wayyyy too long, just post the section of the code you would like to change. Posting long code like that is against the posting rules anyways. Link to comment https://forums.phpfreaks.com/topic/39411-new-to-php/#findComment-190115 Share on other sites More sharing options...
herhemi Posted February 21, 2007 Author Share Posted February 21, 2007 Sorry, I was not aware of the rules. My teacher provided us with some code templates to use, we just need to make changes to it. I wanted to make the add, update and delete radio buttons. I think this is the code: <input type="AddAuthor" type="submit" id="Branch" value=" Add " onClick="submit();"> <input name="UpdateAuthor" type="submit" id="Publisher" value=" Update " onClick="submit();"> <input name="DeleteAuthor" type="submit" id="Author" value=" Delete " onClick="submit();"> Link to comment https://forums.phpfreaks.com/topic/39411-new-to-php/#findComment-190119 Share on other sites More sharing options...
Archadian Posted February 21, 2007 Share Posted February 21, 2007 here's an easy tutorial on radio buttons: http://www.echoecho.com/htmlforms10.htm Link to comment https://forums.phpfreaks.com/topic/39411-new-to-php/#findComment-190122 Share on other sites More sharing options...
tom100 Posted February 21, 2007 Share Posted February 21, 2007 1.) This is an html question. 2.) <input type="radio" type="submit" id="Branch" value=" Add " onClick="submit();"> <input name="UpdateAuthor" type="radio" id="Publisher" value=" Update " onClick="submit();"> <input name="DeleteAuthor" type="radio" id="Author" value=" Delete " onClick="submit();"> Link to comment https://forums.phpfreaks.com/topic/39411-new-to-php/#findComment-190123 Share on other sites More sharing options...
herhemi Posted February 21, 2007 Author Share Posted February 21, 2007 My document actually has both php and html in it, sorry about that. Thank you for your time and response. Link to comment https://forums.phpfreaks.com/topic/39411-new-to-php/#findComment-190133 Share on other sites More sharing options...
Archadian Posted February 21, 2007 Share Posted February 21, 2007 <input type="radio" type="submit" id="Branch" value=" Add " onClick="submit();"> <input name="UpdateAuthor" type="radio" id="Publisher" value=" Update " onClick="submit();"> <input name="DeleteAuthor" type="radio" id="Author" value=" Delete " onClick="submit();"> Do you need the onClick="submit(); if you are using radio buttons? It would be: <input type="radio" name="Branch" id="Branch" value="Branch"> <input name="UpdateAuthor" type="radio" id="Publisher" value="Publisher"> <input name="DeleteAuthor" type="radio" id="Author" value="Author"> <input type="submit" name="submit" value="Submit"> Link to comment https://forums.phpfreaks.com/topic/39411-new-to-php/#findComment-190142 Share on other sites More sharing options...
tom100 Posted February 21, 2007 Share Posted February 21, 2007 Theoretically you didn't need it on the submit buttons. If you want the radio buttons to submit the form when its clicked, you do need it. Link to comment https://forums.phpfreaks.com/topic/39411-new-to-php/#findComment-190144 Share on other sites More sharing options...
Archadian Posted February 21, 2007 Share Posted February 21, 2007 i just got owned XD ur right. Link to comment https://forums.phpfreaks.com/topic/39411-new-to-php/#findComment-190165 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.