mR-mONKEY Posted December 9, 2006 Share Posted December 9, 2006 Hello all,iam just starting to learn php and iam having a little problem getting it to do what i want. i've got a basic form that allows me to insert data into my mySQL database, underneath that ive got the content of the database + a edit and remove button. ive got the remove and edit script working but what i really want to do is to have it when i click the edit button it removes the add form and displays the edit form if you know what i mean i presume some type of if statement? if you dont know what i mean take a look at [url=http://www.cheeky-chimp.com/pub/pubwar/delete_results.php]http://www.cheeky-chimp.com/pub/pubwar/delete_results.php[/url] and click edit then the 2 forms appear cheersJonhaving problems getting all the code up as you might see below so the code is here if you want to look http://www.cheeky-chimp.com/pub/code.html Link to comment https://forums.phpfreaks.com/topic/30004-basic-form-help/ Share on other sites More sharing options...
mR-mONKEY Posted December 9, 2006 Author Share Posted December 9, 2006 Add Match code[code]<form>here</form><?phpinclude 'mysql_connect.php';if (isset($_POST['team'])) { $team = $_POST['team']; $orderdate =$_POST['orderdate']; $ladder =$_POST['ladder']; $opp_name =$_POST['opp_name']; $pub_score =$_POST['pub_score']; $opp_score =$_POST['opp_score']; $website =$_POST['website']; $sql = "INSERT INTO war_results SET team='$team', date='$orderdate', ladder='$ladder', opp_name='$opp_name', pub_score='$pub_score', opp_score='$opp_score', website='$website'";if (@mysql_query($sql)) {echo '<p> Match submitted.</p>';}else{echo '<p>Error Adding Submitted Match:'.mysql_error().'</p>';}}?>[/code] Link to comment https://forums.phpfreaks.com/topic/30004-basic-form-help/#findComment-137916 Share on other sites More sharing options...
mR-mONKEY Posted December 9, 2006 Author Share Posted December 9, 2006 Update Code[code]<?phpinclude 'mysql_connect.php';//Update Match Result$editid= $_GET['editresult'];$query="SELECT * FROM war_results WHERE id='$editid'";$results=mysql_query($query);$num=mysql_numrows($results);mysql_close();$i=0;while ($i <$num){ $team=mysql_result($results,$i,"team"); $ladder=mysql_result($results,$i,"ladder"); $opp_name=mysql_result($results,$i,"opp_name"); $pub_score=mysql_result($results,$i,"pub_score"); $opp_score=mysql_result($results,$i,"opp_score"); $website=mysql_result($results,$i,"website"); ++$i; [/code] Link to comment https://forums.phpfreaks.com/topic/30004-basic-form-help/#findComment-137917 Share on other sites More sharing options...
mR-mONKEY Posted December 9, 2006 Author Share Posted December 9, 2006 [code]<?php//Connect to server include 'mysql_connect.php';$result = @mysql_query('SELECT * FROM war_results ORDER BY `id` DESC ');if (!$result){exit ('<p>Error Performing query: '.mysql_error().'</p>');}//let's get the number of rows in our result so we can use it in a for loop$numofrows = mysql_num_rows($result);//Table Topecho "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n";echo "<tr bgcolor=\"#EEEEEE\"><th scope=\"col\">Date</th><th scope=\"col\">Ladder</th><th scope=\"col\">Opponents</th><th scope=\"col\">Score</th><th scope=\"col\">Win/Loss</th><th scope=\"col\">Remove</th><th scope=\"col\">Edit</th></tr>\n";// Display Results for($i = 0; $i < $numofrows; $i++) { $row = mysql_fetch_array($result); //get a row from our result set $id= $row['id']; if($i % 2) { //this means if there is a remainder echo "<tr bgcolor=\"#999999\">\n"; } else { //if there isn't a remainder we will do the else echo "<tr bgcolor=\"#CCCCCC\">\n"; }echo '<td>' .$row['date'].'</td><td><img src="images/'.$row['ladder'].'.gif" border="0"/></td>';//echos date and images of ladder if ( $row['website'] == '')//Check Website == blank {echo '<td>'.$row['team'].' vs. '.$row['opp_name'].'</td>';}//echos Team vs Opp else {echo '<td>'.$row['team'].' vs. <a href="'.$row['website'].'">'.$row['opp_name'].'</a></td>';}//echos team vs Opp + Opp Websiteecho'<td>' .$row['pub_score'].' - '.$row['opp_score'].'</td>';//echos scores if ( $row['pub_score'] == $row['opp_score'])//checks for draw {echo '<td>DRAW</td>';} elseif ( $row['pub_score'] > $row['opp_score']) {echo '<td>WIN</td>';} else {echo '<td>LOSS</td>';}echo '<td><a href="'.$_SERVER['PHP_SELF'].'?deleteresult='.$id.'">'.'<img src="images/delete.png" border="0"/></a></td><td><a href="'.$_SERVER['PHP_SELF'].'?editresult='.$id.'">'.'<img src="images/b_edit.png" border="0"/></a></td>';//delete functionecho '</tr>';}//Delete Match Result$id= $_GET['deleteresult'];if (isset($_GET['deleteresult'])){$sql = "DELETE FROM war_results WHERE id='$id'";if (@mysql_query($sql)) {echo '<p> Match Result Deleted</p>';}else{echo '<p>Error Deleting match:'.mysql_error().'</p>';}}echo "</table>\n"?>[/code]having problems getting all the code up so the code is here if you want to look http://www.cheeky-chimp.com/pub/code.html Link to comment https://forums.phpfreaks.com/topic/30004-basic-form-help/#findComment-137919 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.