kendallkamikaze Posted March 20, 2009 Share Posted March 20, 2009 Alright so I've put together this code on one page: <script type="text/javascript"> <!-- function confirmation() { var answer = confirm("Are you sure you want to euthanize this horse?") if (answer){ alert("This horse has been euthanized.") window.location = "horse_euth.php?id=<?PHP $_GET['id']; ?>"; } else{ alert("I'm sure the horse is happy that you didn't kill him/her!") } } //--> </script> <form> <input type="button" onclick="confirmation()" value="Euthanize"> </form> The above code is funtional but when it goes to the redirect link it doesnt post the id and I cant get part of the code to funtion: <?php include 'header.php'; ?> <?php $horseid=$_GET['id']; $sql = "SELECT id FROM horsedata WHERE Sire = ".$horseid." OR Dam = ".$horseid." and Owner='$id' and DOB > 24"; $result=mysql_query($sql); if(mysql_num_rows($sql) > 0){ $sql = "DELETE FROM horsedata WHERE id = '.$horseid.'"; $result=mysql_query($sql); echo "You have Euthanized this horse."; } else{ $query="UPDATE horsedata SET retired='yes' and dead='yes' WHERE id='$horseid' and Owner='$id' and DOB > 24"; $checkresult = mysql_query($query); if ($checkresult) echo "<BR><BR><font size='5pt' face='comic sans ms'><B>Your horse has been retired.</b></font>"; else echo "<BR><BR><font size='5pt' face='comic sans ms'><B>You do not own this horse/or the horse is not old enough to be retired.</b></font>";} ?> <?php include 'footer.php'; ?> this is what the page says: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/collegh9/public_html/one-stride/horse_euth.php on line 15 Your horse has been retired. Link to comment https://forums.phpfreaks.com/topic/150253-php-javascript-button-help/ Share on other sites More sharing options...
kendallkamikaze Posted March 20, 2009 Author Share Posted March 20, 2009 <?php print " <table border='1' bordercolor='#000000' cellpadding='2' cellspacing='1' height='95' width='505'> <tbody> <td class='top2' Colspan='2' width='120' height='20'>Grade</tr> <tr> <td class='horsetable' valign='middle'> <center><font face='verdana' size='8'> $Grading </td></tr></table>"; ?> </div> <style> -----! <div id="country5" class="tabcontent"> 5 </div> <div id="country6" class="tabcontent"> 6 </div> <div id="country7" class="tabcontent"> 7 </div> <div id="country8" class="tabcontent"> 8 </div> !----- </style> </div> <script type="text/javascript"> var countries=new ddtabcontent("countrytabs") countries.setpersist(true) countries.setselectedClassTarget("link") //"link" or "linkparent" countries.init() var countries=new ddtabcontent("countrytabs2") countries.setpersist(true) countries.setselectedClassTarget("link") //"link" or "linkparent" countries.init() </script> </td></tr></table> </div> </div> <div id="flowertabs" class="modernbricksmenu2"> <ul> <li><a href="#" rel="tcontent1">Basic Horse Info</a></li> <li><a href="#" rel="tcontent2">Other Horse Info</a></li> </ul> </div> <br style="clear: left" /> <script type="text/javascript"> var myflowers=new ddtabcontent("flowertabs") myflowers.setpersist(true) myflowers.setselectedClassTarget("link") //"link" or "linkparent" myflowers.init() </script> <?php } ?> <style type="text/css"> body, dd { font-family: verdana; font-size: 11px; text-align:center; } .menu1 { background-color: #646f71; color: #d0c9aa; font-family: geneva, times new roman; font-size: 12px; letter-spacing: 2px; text-align:center; } .menu1 a { background-color: #646f71; color: #d0c9aa; font-family: geneva, times new roman; font-size: 12px; letter-spacing: 2px; text-align:center; } .menu2 { background-color: #d0c9aa; color: #54505e; font-family: geneva, times new roman; font-size: 12px; letter-spacing: 2px; text-align:center; } .menu2 a{ background-color: #d0c9aa; color: #54505e; font-family: geneva, times new roman; font-size: 12px; letter-spacing: 2px; text-align:center; } .menu3 { background-color: #babea9; color: #5a5a64; font-family: geneva, times new roman; font-size: 12px; letter-spacing: 2px; text-align:center; } .menu3 a { background-color: #babea9; color: #5a5a64; font-family: geneva, times new roman; font-size: 12px; letter-spacing: 2px; text-align:center; } #display { border-width: 0px; border-style: none; font-family: geneva, times new roman; font-size: 12px; letter-spacing: 2px; text-align:center; } </style> <script src="http://jquery.com/src/jquery.js"></script> <script> //Toggle function for menu $(document).ready(function(){ //on click hide and display $("dd:not(:first)").hide(); $("dt a").click(function(){ //set the speed of the slide $("dd:visible").slideUp("slow"); $(this).parent().next().slideDown("slow"); return false; }); }); </script> <br><br> <table style="border-width: 1px; border-color:black;"><tr><td width="505px"> <dl> <dt class="menu1"><a href="/"><b>View Registrations</b></a></dt> <dd> <?php $horseid=$_GET['id']; $sql="SELECT * FROM registration WHERE horseid='$horseid'"; $result=mysql_query($sql); while($r=mysql_fetch_array($result)) { $assoname=$r["assoname"]; echo "<BR>$assoname"; } ?> <br> <br> </dd> <dt class="menu2"><a href="/" ><b>View Awards</a></b></dt> <dd> <?php echo " Awards Won by $Name: <br> $Awards "; ?><br><br> </dd> <dt class="menu3"> <a href="/"><b>View Show Records</a></b></dt> <dd><?php $horseid=$_GET['id']; $sql="SELECT * FROM horsedata WHERE id='$horseid'"; $result=mysql_query($sql); while($r=mysql_fetch_array($result)) { $Owner=$r["Owner"]; $Name=$r["Name"]; $horseid=$r["id"]; $Height=$r["Height"]; $Breed=$r["Breed"]; $Gender=$r["Gender"]; $Color=$r["Color"]; $Registrations=$r["Registrations"]; $Exp=$r["Exp"]; $Points=$r["Points"]; $Speed=$r["Speed"]; $Scope=$r["Scope"]; $Endurance=$r["Endurance"]; $Power=$r["Power"]; $Obedience=$r["Obedience"]; $Sociability=$r["Sociability"]; $Intelligence=$r["Intelligence"]; $Sire=$r["Sire"]; $Dam=$r["Dam"]; $Foals=$r["Foals"]; $Awards=$r["Awards"]; $Image=$r["Image"]; $Log=$r["Log"]; $DOB=$r["DOB"]; $pedigree=$r["pedigree"]; $legs=$r["legs"]; $temperament=$r["temperament"]; $back=$r["back"]; $neck=$r["neck"]; $head=$r["head"]; $Grading=$r["Grading"]; $Firsts=$r["Firsts"]; $Seconds=$r["Seconds"]; $Thirds=$r["Thirds"]; $Fourths=$r["Fourths"]; $Fifths=$r["Fifths"]; $Sixths=$r["Sixths"]; $Entries=$r["Entries"]; $rabies=$r["rabies"]; $influenza=$r["influenza"]; $strangles=$r["strangles"]; $westnile=$r["westnile"]; $herpes=$r["herpes"]; $tetanus=$r["tetanus"]; $coggins=$r["coggins"]; echo " <br> <b>Show Records for $Name:</b> <br> Firsts: $Firsts | Seconds: $Seconds | Thirds: $Thirds <br> Fourths: $Fourths | Fifths: $Fifths | Sixths: $Sixths <br> Total Entries: $Entries <br><br>"; } ?> <br> <b>Barn Show Results</b> <br><br> <div style="border: 0pt none ; height: 100px; overflow: auto;"> <?php $horseid=$_GET['id']; $sql="SELECT * FROM BarnResults WHERE horseid='$horseid'"; $result=mysql_query($sql); while($r=mysql_fetch_array($result)) { $horseid=$r["horseid"]; $Place=$r["Place"]; $ClassName=$r["ClassName"]; $barnid=$r["barnid"]; //display the row echo " $Place in $ClassName at $barnid <br> "; } ?> </div><br><br> </dd> <dt class="menu1"> <a href="/"><b>Health Certification</a></b></dt> <dd> <?php $horseid=$_GET['id']; $sql="SELECT * FROM horsedata WHERE id='$horseid'"; $result=mysql_query($sql); while($r=mysql_fetch_array($result)) { $Owner=$r["Owner"]; $Name=$r["Name"]; $horseid=$r["id"]; $Height=$r["Height"]; $Breed=$r["Breed"]; $Gender=$r["Gender"]; $Color=$r["Color"]; $Registrations=$r["Registrations"]; $Exp=$r["Exp"]; $Points=$r["Points"]; $Speed=$r["Speed"]; $Scope=$r["Scope"]; $Endurance=$r["Endurance"]; $Power=$r["Power"]; $Obedience=$r["Obedience"]; $Sociability=$r["Sociability"]; $Intelligence=$r["Intelligence"]; $Sire=$r["Sire"]; $Dam=$r["Dam"]; $Foals=$r["Foals"]; $Awards=$r["Awards"]; $Image=$r["Image"]; $Log=$r["Log"]; $DOB=$r["DOB"]; $pedigree=$r["pedigree"]; $legs=$r["legs"]; $temperament=$r["temperament"]; $back=$r["back"]; $neck=$r["neck"]; $head=$r["head"]; $Grading=$r["Grading"]; $Firsts=$r["Firsts"]; $Seconds=$r["Seconds"]; $Thirds=$r["Thirds"]; $Fourths=$r["Fourths"]; $Fifths=$r["Fifths"]; $Sixths=$r["Sixths"]; $Entries=$r["Entries"]; $rabies=$r["rabies"]; $influenza=$r["influenza"]; $strangles=$r["strangles"]; $westnile=$r["westnile"]; $herpes=$r["herpes"]; $tetanus=$r["tetanus"]; $coggins=$r["coggins"]; $picked=$r["picked"]; $trimmed=$r["trimmed"]; $conditioned=$r["conditioned"]; $rasp=$r["rasp"]; $shoe=$r["shoe"]; $polish=$r["polish"]; echo " <br> Certificate of Health <br> Rabies Vaccine: $rabies<br> Equine Influenza Vaccine: $influenza <br> Strangles Vaccine: $strangles<br> West Nile Vaccine: $westnile<br> Equine Herpes Vaccine: $herpes <br> Tetanus Vaccine: $tetanus<br> Recent Coggins Test: $coggins<br> Picked Hooves: $picked<BR> Timmed Hooves: $trimmed<BR> Conitioned Hooves: $conditioned<BR> Rasped Hooves: $rasp<BR> Shoed Hooves: $shoe<BR> Polished Hooves: $polish <BR><BR> <br>"; } ?> </dd> <?php $horseid=$_GET['id']; $sql="SELECT * FROM horsedata WHERE id='$horseid' and Owner='$id' "; $result=mysql_query($sql); while($r=mysql_fetch_array($result)) { $horseid=$r["id"]; $horseid2=$r["id"]; $Name=$r["Name"]; $Log=$r["Log"]; $Forsale=$r["Forsale"]; $Image=$r["Image"]; echo "<dt class='menu2'><a href='/'><b>Care Center</a></b></dt><dd> <font class='page'> <BR>Here you can care for your horse. Caring for your horse everyday will increase his/her trait areas. You can feed, give supplements, groom, tack and exercise your horse. Each care item will give a different number of traits in a different area. No two items give the same trait amount or in the same trait area. <BR>Have fun!<BR><center></font> <form action='horse_care.php' method='get'> <input type='hidden' value='$horseid2' name='horseid'> <input type='submit' value='care center!'> </form></center></dd>"; } ?> <?php $horseid=$_GET['id']; $sql="SELECT * FROM horsedata WHERE id='$horseid' and Owner='$id' "; $result=mysql_query($sql); while($r=mysql_fetch_array($result)) { $horseid=$r["id"]; $horseid2=$r["id"]; $Name=$r["Name"]; $Log=$r["Log"]; $Forsale=$r["Forsale"]; $Image=$r["Image"]; echo "<dt class='menu3'><a href='/'><b>Update Horse</a></b></dt><DD> <font class='tableheader'> Update Horse's Records </font> <br><br> <font class='page'> Use the forms below to edit your horse's details. <br><br> <b> Change Your Horse's Name </b> <br> <form name='upname' action='horse_upname.php' method='post'> <input type='text' name='Name' MAXLENGTH='50' value='$Name'> <input type='hidden' name='id' value='$horseid2'> <input type='submit' value='Change Name!'> </form> <br><br> <b> Change Your Horse's Image </b> <br> <form name='upimage' action='horse_upimage.php' method='post'> <input type='text' value='$Image' name='Image'> <input type='hidden' value='$horseid2' name='id'> <input type='submit' value='Change Image!'> </form> <br><br> <b> Update Your Horse's Log </b> <br> Horse logs are your horse's own little page. Add images, HTML etc. <br> <form name='uplog' action='horse_uplog.php' method='post'> <textarea cols='40' rows='9' name='Log'> $Log </textarea> <input type='hidden' value='$horseid2' name='id'> <input type='submit' value='Update!'> </form> <br><br> <b> Put This Horse Up for Sale </b> <br> <form action='horse_upsale.php' method='post'> Change Sale Status: <select name='Forsale'> <option> No </option> <option> Yes </option> </select> <br> List Price: <input type='text' name='price'><BR> Minimum You Will Consider: <input type='text' name='lowoffer'> <input type='hidden' value='$horseid2' name='id'> <input type='submit' value='Update Listing'> </form> </center> "; } ?> <?php $horseid=$_GET['id']; $sql="SELECT * FROM horsedata WHERE id='$horseid' and Owner='$id' and brand='none'"; $result=mysql_query($sql); while($r=mysql_fetch_array($result)) { $horseid=$r["id"]; $horseid2=$r["id"]; $Name=$r["Name"]; $brand=$r["brand"]; echo " <BR><BR><font color='red'> You can only brand your horse once and you are limited to 10 letters/symbols! </font><form name='brand' action='horse_upbrand.php' method='post'> <input type='text' name='brand' MAXLENGTH='10' value='$brand'> <input type='hidden' name='id' value='$horseid2'> <input type='submit' value='Brand your horse!'> </form> FYI: If you want to sell your horse in the future, branding it could make the value of the horse less! <br><br> "; } ?> <script type="text/javascript"> <!-- function confirmation() { var answer = confirm("Are you sure you want to euthanize this horse?") if (answer){ alert("This horse has been euthanized.") window.location = "horse_euth.php?id=<?PHP $_GET['id']; ?>"; } else{ alert("I'm sure the horse is happy that you didn't kill him/her!") } } //--> </script> <form> <input type="button" onclick="confirmation()" value="Euthanize"> </form> DO NOT CLICK UNLESS YOU WANT TO DELETE ALL YOUR HORSES! IT IS NOT FUNCTIONAL YET! </dd> </td></tr></table></div> <br><br> <center> <?php include 'footer.php'; ?> </center> <?php include 'header.php'; ?> <?php $horseid=$_GET['id']; $sql = "SELECT id FROM horsedata WHERE Sire = ".$horseid." OR Dam = ".$horseid." and Owner='$id' and DOB > 24"; $result=mysql_query($sql); if(mysql_num_rows($sql) > 0){ $sql = "DELETE FROM horsedata WHERE id = '.$horseid.'"; $result=mysql_query($sql); echo "You have Euthanized this horse."; } else{ $query="UPDATE horsedata SET retired='yes' and dead='yes' WHERE id='$horseid' and Owner='$id' and DOB > 24"; $checkresult = mysql_query($query); if ($checkresult) echo "<BR><BR><font size='5pt' face='comic sans ms'><B>Your horse has been retired.</b></font>"; else echo "<BR><BR><font size='5pt' face='comic sans ms'><B>You do not own this horse/or the horse is not old enough to be retired.</b></font>";} ?> <?php include 'footer.php'; ?> Link to comment https://forums.phpfreaks.com/topic/150253-php-javascript-button-help/#findComment-789078 Share on other sites More sharing options...
mrdamien Posted March 20, 2009 Share Posted March 20, 2009 mysql_num_rows wants the result-resource as a paramater, not the query Therefore: $result=mysql_query($sql); if(mysql_num_rows($result) > 0){ // <- change $sql to $result. $sql = "DELETE FROM horsedata WHERE id = '".(int)$horseid."'"; // (int) for safety $result=mysql_query($sql); echo "You have Euthanized this horse."; } Link to comment https://forums.phpfreaks.com/topic/150253-php-javascript-button-help/#findComment-789080 Share on other sites More sharing options...
kendallkamikaze Posted March 20, 2009 Author Share Posted March 20, 2009 <?php include 'header.php'; ?> <?php $horseid=$_GET['id']; $sql = "SELECT id FROM horsedata WHERE (Sire = ".$horseid." OR Dam = ".$horseid.") and Owner='$id' and DOB > 24"; $result=mysql_query($sql) or die ( mysql_error ); if(mysql_num_rows($sql) > 0){ $sql = "DELETE FROM horsedata WHERE id = '.$horseid.'"; $result=mysql_query($sql); echo "You have Euthanized this horse."; } else{ $query="UPDATE horsedata SET retired='yes' and dead='yes' WHERE id='$horseid' and Owner='$id' and DOB > 24"; $checkresult = mysql_query($query); if ($checkresult) echo "<BR><BR><font size='5pt' face='comic sans ms'><B>Your horse has been retired.</b></font>"; else echo "<BR><BR><font size='5pt' face='comic sans ms'><B>You do not own this horse/or the horse is not old enough to be retired.</b></font>";} ?> <?php include 'footer.php'; ?> Link to comment https://forums.phpfreaks.com/topic/150253-php-javascript-button-help/#findComment-789091 Share on other sites More sharing options...
redarrow Posted March 20, 2009 Share Posted March 20, 2009 $result=mysql_query($sql) or die ( mysql_error ); if(mysql_num_rows($sql) > 0){ $sql = "DELETE FROM horsedata WHERE id = '.$horseid.'"; $result=mysql_query($sql); echo "You have Euthanized this horse."; } to $result=mysql_query($sql) or die ( mysql_error ); if(mysql_num_rows($result) > 0){ $sql = "DELETE FROM horsedata WHERE id = '.$horseid.'"; $result=mysql_query($sql); echo "You have Euthanized this horse."; } As advised. also use mysql_error() function and never use the same query names. Link to comment https://forums.phpfreaks.com/topic/150253-php-javascript-button-help/#findComment-789126 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.