telsiin Posted June 26, 2008 Share Posted June 26, 2008 Hello everyone I need a little help with submitting a form with multiple buttons I have two button named Submit1 and Submit2 What I am trying to do is first check if a record exist if it does exist use information in that record else it does NOT exist give me some random numbers if($Submit1){ the user does not like those random number give me a new set of random numbers} if ($Submit2) {the user likes those number save them in the database} <?php require_once('../../Connections/LordofAnsalon.php'); session_start(); $cname =$_SESSION[uid]; mysql_select_db($database_LordofAnsalon, $LordofAnsalon); $query_Recordset1 = "SELECT * FROM createchr2 WHERE createchr2.CharID='$_SESSION[charID]'"; $Recordset1 = mysql_query($query_Recordset1, $LordofAnsalon) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysql_num_rows($Recordset1); if ($row_Recordset1['str']>=1){ $str = $row_Recordset1['str']; $dex = $row_Recordset1['dex']; $con = $row_Recordset1['con']; $int = $row_Recordset1['intell']; $wis = $row_Recordset1['wis']; $cha = $row_Recordset1['cha']; } else { $cname = $cname; $str = rand(1+9,20-2); $dex = rand(1+9,20-2); $con = rand(1+9,20-2); $int = rand(1+9,20-2); $wis = rand(1+9,20-2); $cha = rand(1+9,20-2); } if ($Submit2) {//Begin $Submit2 function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue; switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $insertSQL = sprintf("INSERT INTO createchr2 (str, dex, con, intell, wis, cha, CharID) VALUES (%s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['str'], "int"), GetSQLValueString($_POST['dex'], "int"), GetSQLValueString($_POST['con'], "int"), GetSQLValueString($_POST['intell'], "int"), GetSQLValueString($_POST['wis'], "int"), GetSQLValueString($_POST['cha'], "int"), GetSQLValueString($_POST['CharID'], "int")); mysql_select_db($database_LordofAnsalon, $LordofAnsalon); $Result1 = mysql_query($insertSQL, $LordofAnsalon) or die(mysql_error()); $insertGoTo = "Classstats.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } @header(sprintf("Location: %s", $insertGoTo)); } }//End $Submit2 include_once 'gatekeeper.php'; include_once 'Cctoolbar.php'; ?> <html> <head> <title>Lords of Ansalon</title> <style type="text/css"> <!-- .style1 {font-family: "Tempus Sans ITC"} --> </style> </head> <body bgcolor="#FFFFFF" background="images/back2.jpg"> <form action="<?php echo $editFormAction; ?>" method="POST" name="form1" class="style1" > <table width="289" border="0" cellpadding="0" cellspacing="0" class="style1"> <tr> <th scope="row"><div align="left">Character Name </div></th> <td><input name="cname" type="text" class="style1 " value="<?php echo $cname?>" readonly="0"> </label> </td> </tr> <tr> <th width="123" scope="row"><div align="left" class="style1"> <p>Strength</p> </div></th> <td width="150"> <input name="str" type="text" class="style1" value="<?php echo $str?>" readonly="0"></td> </tr> <tr> <th scope="row"><div align="left" class="style1"> <p>Dexterity</p> </div></th> <td><input name="dex" type="text" class="style1" value="<?php echo $dex?>" readonly="0"></td> </tr> <tr> <th scope="row"><div align="left" class="style1"> <p>Constitution</p> </div></th> <td><input name="con" type="text" class="style1" value="<?php echo $con?>" readonly="0"></td> </tr> <tr> <th scope="row"><div align="left" class="style1"> <p>Intelligence</p> </div></th> <td><input name="intell" type="text" class="style1" value="<?php echo $int?>" readonly="0"></td> </tr> <tr> <th scope="row"><div align="left" class="style1"> <p>Wisdom</p> </div></th> <td><input name="wis" type="text" class="style1" value="<?php echo $wis?>" readonly="0"></td> </tr> <tr> <th scope="row"><div align="left" class="style1"> <p class="style1">Charisma</p> </div></th> <td><input name="cha" type="text" class="style1" value="<?php echo $cha?>" readonly="0"> <input name="charID" type="hidden" class="style1" value="<?php echo $_SESSION[charID]?>" readonly="0"></td> </tr> <tr ><td></td><td> <input type="text" class="style1" name="CharID" value="<?php echo $_SESSION[charID]?>"></td></tr> </table> <input type="submit" name="Submit1" value="Re~roll" id="Submit1" > <input type="submit" name="Submit2" value="Accept Stat" id="Submit2"> </p> <input type="hidden" name="MM_insert" value="form1"> </form> </body> </html> <?php mysql_free_result($Recordset1); ?> Changed quote tags to code tags ~ CV Quote Link to comment https://forums.phpfreaks.com/topic/112060-solved-form-with-multiple-submit-buttons/ Share on other sites More sharing options...
.josh Posted June 26, 2008 Share Posted June 26, 2008 sounds like a plan, so hop to it! or...did you have a problem you forgot to mention? Quote Link to comment https://forums.phpfreaks.com/topic/112060-solved-form-with-multiple-submit-buttons/#findComment-575230 Share on other sites More sharing options...
telsiin Posted June 26, 2008 Author Share Posted June 26, 2008 well it does not submit the form when I press the submit2 button instead it just give the random number over and over again Quote Link to comment https://forums.phpfreaks.com/topic/112060-solved-form-with-multiple-submit-buttons/#findComment-575241 Share on other sites More sharing options...
.josh Posted June 26, 2008 Share Posted June 26, 2008 if ($Submit2) should be if ($_POST['submit2']) Quote Link to comment https://forums.phpfreaks.com/topic/112060-solved-form-with-multiple-submit-buttons/#findComment-575245 Share on other sites More sharing options...
telsiin Posted June 26, 2008 Author Share Posted June 26, 2008 thank you very much it worked Antonio Quote Link to comment https://forums.phpfreaks.com/topic/112060-solved-form-with-multiple-submit-buttons/#findComment-575288 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.