I don't know to do the script, when click link, it will send data to form. What im trying to do is . When user click link data will appear at the form. below is my link. generated from database.
<div id="menu_bar" region="west" split="true" title="Pages listing" style="width:200px;padding:10px;">
<?php
$parent = mysql_query("select * from pages where parent = 0");
echo "<ul id='sitemap'>";
while($row = mysql_fetch_array($parent)){
$parent_id = $row['id'];
$parent_name = $row['name'];
echo "<li><a href='#' onclick='editPage()'>$parent_name ($parent_id)</a>";
echo "<ul>";
$child = mysql_query("select * from pages where parent = '$parent_id'");
while($row = mysql_fetch_array($child)){
$child_id = $row['id'];
$child_name = $row['name'];
echo "<li><a href='list2.php?id=$child_id' onclick='editPage()'>$child_name ($child_id)</a></li>";
}
echo "</ul>";
}
echo "</li>";
echo "</ul>";
?>
</div>
And the form.
Basic Information
Name:
Parent:
Order:
Body:
Special:
Please help me, im still in programming field. im using PHP, JSON,JQUERY, EASY-UI.
Thanks
If you want to edit page detail in new page then no need to call onclick='editPage()' instead of that pass the page url in href.
<?php
$parent = mysql_query("select * from pages where parent = 0");
echo "<ul id='sitemap'>";
while($row = mysql_fetch_array($parent)){
$parent_id = $row['id'];
$parent_name = $row['name'];
echo "<li><a href='edit_page.php?id=".$row['id']."' >$parent_name ($parent_id)</a>";
echo "<ul>";
$child = mysql_query("select * from pages where parent = '$parent_id'");
while($row = mysql_fetch_array($child)){
$child_id = $row['id'];
$child_name = $row['name'];
echo "<li><a href='edit_page.php?id=".$row['id']."' >$child_name ($child_id)</a></li>";
}
echo "</ul>";
}
echo "</li>";
echo "</ul>";
?>
edit page code should be like this
<?php
$id = $_REQUEST['id'];
//use ur table name here
//I am considering that ur table contain all the required information
$result = mysql_query("select * from table where id='".$id."'");
$row = mysql_fetch_assoc($result);
?>
<form>
Name <input type="text" name="name" id="name" value="<?php echo $row['name']; ?>" />
Parent <input type="text" name="name" id="name" value="<?php echo $row['parent']; ?>" />
Order <input type="text" name="name" id="name" value="<?php echo $row['order']; ?>" />
Body <input type="text" name="name" id="name" value="<?php echo $row['body_text']; ?>" />
Special <input type="text" name="name" id="name" value="<?php echo $row['special']; ?>" />
</form>
hope this will help you.
Related
I have this piece of code where I query all the rows of data from my database. In my 1st php, I have this link where I will pass the ID from the row into another php page. Here is my code.
<a class="button3" style="float: left;" onclick="return confirm('Are you sure?');" href="adminEditBillboard.php?edit=<?php echo $row['id']; ?>">Edit</a>
My adminEditBillboard.php has this on a input type text.
<input type="text" class="form-control" value="<?php echo $id; ?>" name="owner" placeholder="Enter billboard owner name">
Do I need to add something? like a method post?
This is from my process.php for the edit.
if(isset($_GET['edit'])){
$id = $_GET['edit'];
$result = $mysqli->query("SELECT * FROM billboards WHERE id=$id") or die($mysqli->error);
if(isset($result->num_rows) && $result->num_rows > 0){
$row = $result->fetch_array();
$owner = $row['owner'];
$location = $row['location'];
$email = $row['email'];
$phone = $row['phone'];
$description = $row['description'];
header("location: adminEditBillBoard.php?edit=$id");
}
Your adminEditBillboard.php should pick the id from the HTTP GET parameters as follows
<input type="text" class="form-control" value="<?php echo $_GET['edit']; ?>" name="owner" placeholder="Enter billboard owner name">
I am creating a simple CRUD application that will be used as a blog. For the edit page, I want to have a dropdown menu with the blog titles of each post. When an option/blog post is selected, I want it to populate the "Title" and "Message" fields, so it can then be edited and saved to the database.
I got it to retrieve the titles of the blog posts, but I am struggling to make it populate the "Title" and "Message" fields so it can be edited when the option is selected.
I have 4 rows in my database: row[0] is the title, row[1] is the message, row[2] is the timestamp and row[3] is the ID.
Thanks guys. I appreciate it.
<form action="edit.php" id="myform" method="post" autocomplete=off>
<input type="hidden" name="action" value="show">
<p><label>Entry:</label><select name="blog">
<?php
$result = mysqli_query($con, "SELECT * FROM blog");
while ($row = mysqli_fetch_array($result)) {
$chosen = $row['bid'];
}
if (isset($_GET['blog'])) {
$id = $_GET['blog'];
$result = mysqli_query($con, "SELECT * FROM blog WHERE bid='$id'");
$row = mysqli_fetch_array($result);
}
$result = mysqli_query($con, "SELECT * FROM blog");
while ($row = mysqli_fetch_array($result)) {
$id = $row['bid'];
$title = $row['title'];
$selected = '';
if ($id == $chosen) {
$selected = "selected='selected'";
}
echo "<option value='$id' $selected>$title</option>\n";
}
?>
</select></p>
<p><label>Title:</label> <input type="text" id="newtitle" name="newtitle" value="<?php echo $row[0]; ?>"></p>
<p><label>Message:</label> <input type="text" id="newmessage" name="newmessage" value="<?php echo $row[1]; ?>"></p>
<p><input type="hidden" name="id" value="<?php echo $row[3]; ?>"></p>
<br><p><input type="submit" name="submit" value="Submit"></p>
</form>
I have managed to somewhat figure out the answer on my own. It's probably not the most ideal way of doing it, but for anyone else potentially stuck on this - here is my code:
The only issue I'm having now is figuring out how to keep my option selected.
<form action="edit.php" id="myform" method="post" autocomplete=off>
<input type="hidden" name="action" value="show">
<p><label>Entry:</label><select name="blog" onchange="window.location.href = blog.options[selectedIndex].value">
<option selected disabled>Select One</option>
<?php
$result = mysqli_query($con, "SELECT * FROM blog");
while ($row = mysqli_fetch_array($result)) {
$id = $row['bid'];
$title = $row['title'];
echo "<option value='edit.php?edit=$row[bid]'>$title</option>\n";
}
if (isset($_GET['edit'])) {
$id = $_GET['edit'];
$result = mysqli_query($con, "SELECT * FROM blog WHERE bid='$id'");
$row = mysqli_fetch_array($result);
}
?>
</select></p>
<p><label>Title:</label> <input type="text" id="newtitle" name="newtitle" value="<?php echo $row[0]; ?>"></p>
<p><label>Message:</label> <input type="text" id="newmessage" name="newmessage" value="<?php echo $row[1]; ?>"></p>
<p><input type="hidden" name="id" value="<?php echo $row[3]; ?>"></p>
<br><p><input type="submit" name="submit" value="Submit"></p>
</form>
I'm making a site where the owner has to be able to update their events, but my update code isnt working even though im 99% sure I havent made any errors.
First the form where you press update:
<?php
$sql = "SELECT * FROM events ORDER BY id ASC";
$res = $objCon->query($sql) or die('fejl i query:'.mysqli_error($objCon));
while($row=$res->fetch_array()) {
$id = $row['id'];
echo "<div class='eventpost'>";
echo "<div class='dato'>";
echo $row['id'];
echo "</div>";
echo "<p class='overskrift'>";
echo "<a href='update.php?id=$id'>RET </a>";
echo "<a href='code_delete.php?id=$id'>SLET</a>";
echo $row['overskrift'];
echo "</p>";
echo "</div>";
}
?>
then the update form:
<form action="code_update.php" method="POST">
<label>Dato:<br>
<input type="text" name="dag" value="<?php echo $data['dag']; ?>"></label>
<label>MÃ¥nede:<br>
<input type="text" name="month" value="<?php echo $data['month']; ?>"></label>
<label>Overskrift:<br>
<input type="text" name="overskrift" value="<?php echo $data['overskrift']; ?>"></label>
<label>Tekst:<br>
<input type="text" name="tekst" value="<?php echo $data['tekst']; ?>"></label>
<input type="hidden" name="id" value="<? echo $id; ?>">
<input type="submit" value="Opret">
</form>
and finally the update code
<?php
session_start();
if($_SESSION['auth'] == 2){
include('incl_db.php');
$id = $_POST['id'];
$overskrift = $_POST['overskrift'];
$dag = $_POST['dag'];
$month = $_POST['month'];
$tekst = $_POST['tekst'];
$sql = "UPDATE events SET overskrift='$overskrift', dag='$dag', month='$month', tekst='$tekst' WHERE id='$id'";
$res = $objCon->query($sql);
header('location:events.php');
}else{
header('location:index.php');
}
?>
Probably shorthand tags are disabled in your php version.So try changing this
<input type="hidden" name="id" value="<? echo $id; ?>">
to this
<input type="hidden" name="id" value="<?php echo $id; ?>">
You can check this answer for more.
This is advertisement query
INSERT into advertise_management(advertisement_name,adv_code) values('".$adv_name."','".$adv_code."')
post management:
<input type="text" name="post_name" value="<?php if(isset($post_value)){ echo $post_value['post_name'];} else { echo ''; }?>" required="required">
<?php $res= mysql_query("select * from advertise_management ");
while($result= mysql_fetch_array($res)){
$adv=$result['advertisement_name'];
{ ?>
<input type="checkbox" value="<?php echo $adv?>" name="post_adv[]">
<?php } ?>
Post Management insert query :
$post_name = $_POST['post_name'];
$post_adv1 = $_POST['post_adv'];
$post_adv = implode(",", $post_adv1);
$post_id = $_POST['post_id'];
$res = mysql_query("INSERT into post_managment(post_name,post_adv) values('".$post_name."','".$post_adv."')") or die(mysql_error());
Post management edit :
$result = mysql_query("SELECT * FROM post_managment where post_id='$pid'");
$post_value = mysql_fetch_array($result);
><input type="text" name="post_name" value="<?php if(isset($post_value)){ echo $post_value['post_name'];} else { echo ''; }?>" required="required">
<?php $res= mysql_query("select * from advertise_management ");
while($result= mysql_fetch_array($res)){
$adv=$result['advertisement_name'];
{ ?>
<input type="checkbox" value="<?php echo $adv?>" name="post_adv[]">
<?php } ?>
<input type="submit" value="" id="create"><input type="reset" value="" id="cancel">
I want to return the values that is checked and the values that is not checked.
The browser normally won't send anything for checkboxes that aren't checked. You can work around this by also rendering a hidden input () with the same name and a different value. Make sure it's output right before the checkbox.
I am trying to get records from my DB using 2 seperate tables. The query is
public function get_pages_by_campign_id($campaignID) {
$campaignID = $this->real_escape_string($campaignID);
return $this->query("SELECT pid, campaignid FROM pages,campaigns WHERE 'pages.campaignid = campaigns.id'");
}
And this is called into play by :
$counter = 1;
$userID = PageDB::getInstance()->get_user_id_by_name($_SESSION['user']);
$result = PageDB::getInstance()->get_pages_by_campaign_id($campaignID);
$i=0;
while ($row = mysqli_fetch_array($result)):
$style = "";
if($i%2==0)
{
$style = ' style="background-color: #EFEFEF"';
}
echo "<tr".$style.">";
echo "<td style='width:140px;'> Page " . $counter . "</td>";
echo "<td> </td>";
echo "<td></td>";
//The loop is left open
?>
<td>
<form style="display:none;"></form>
<form name="editPage" action="editPage.php" method="GET">
<input type="hidden" name="pageID" value="<?php echo $pageID = $row['pid']; ?>"/>
<input type="submit" name="editPage" value="Edit"/>
</form>
</td>
<td>
<form name="deletePage" action="deletePage.php" method="POST">
<input type="hidden" name="pageID" value="<?php echo $pageID = $row['pid']?>"/>
<input type="submit" name="deletePage" value="Delete" onclick = "javascript: return confirm('Delete Page <?php echo $counter ?> ?');"/>
</form>
</td>
<?php
$pageID = $row['pid'];
$counter++;
$i++;
echo "</tr>\n";
endwhile;
mysqli_free_result($result);
?>
This should list all "page" Records, but it is returning nothing.
I have set up the "id" column in table "campaigns" to correspond with "campaignid" in table "pages" using foreign keys.
I manged to fix it with this :
public function get_pages_by_campaign_id($campaignID) {
$campaignID = $this->real_escape_string($campaignID);
return $this->query("SELECT pid, campaignid FROM pages WHERE campaignid = 'campaigns.id'");
}
"SELECT pid, campaignid FROM pages,campaigns WHERE pages.campaignid = campaigns.id"
?