the request url not found in php - php

my home.php is
required("conn.php");
<html>
<body>
<form action="like.php" name="art" method="post">
<?php
//$email=$data['email'];
?>
<table align="center" border="2">
<tr><th colspan="4"><h2 align="center">Articals</h2></th></tr>
<tr> <th>Name</th><th>Artical</th><th>Status</th><th colspan="2">option</th>
</tr>
<?php
$r = mysql_query("select * from ar ");
while($ro=mysql_fetch_array($r)){
?>
<tr>
<td> <?php echo $ro["fname"]?></td>
<td><textarea rows="2" cols="25"><?php echo $ro["post"]?></textarea></td>
<td><?php echo $ro["status"]?></td>
<td><a name="like" href="like.php?id=<?php echo $ro['id']?>"> like</a></td>
<!--<td><a href="delart.php?id=<?php //echo $row["id"]?>" >Delete</a></td>
<td>Upadate</td>
-->
</tr>
<?php
}
mysql_close($con);
?>
</form>
</table>
</body>
</html>
and like.php is
<?php
session_start();
if(!isset($_SESSION['user']))
{
header('Location:index.php');
}
require("conn.php");
$id=$_GET['id'];
mysql_query("insert into `like` ar where id='$id'");
?>
when i am click on link like so the error "The requested URL /25-8/like.php was not found on this server." is come pls help i am new to php
i want there to count the no of like and on click on that like button it automatically change to unlike

YOu Must put the home.php and like.php in the same directory?

Related

how to stop do-while looping and fixing the button function?

I want to make it stop looping, but I dont know what's wrong. I want it to be like..
Clicking the button then shows the text, and keep repeating like that in one page.
I have the code tht goes like this:
<?php
include "koneksi.php";
$query = mysqli_query($connection,"SELECT * FROM buatsoal_db ORDER BY ID DESC");
$id = mysqli_query($connection, "select 'ID' from buatsoal_db");
?>
<?php
do{ ?>
<form method= 'post'>
<input name='next' type='submit' id='next' value='next'>
</form>
<?php if(isset($_POST['next'])){ ?>
<table width="637" border="0" cellspacing="1" cellpadding="2">
<tr>
<th width="297" scope="col">
<?php $row = mysqli_fetch_array ($query);
echo $row['SOALTXT']; ?>
</tr>
</table>
<?php }
?>
<?php }
while ($id = 'S01');
echo "sudah selesai";
?>
I dont know what's wrong, it keeps looping like this :
first_executes_looping non stops
and the button next shows up all together, and when I clicked it, the txt shows up at the same time too. I want it to shows up one by one, and keeep it repeat until the id="s01"from the txt is over.
There is problem with your while condition. single = is used to assign values and == is used to compare. So here you have to use == to compare. Try below code.
<?php
include "koneksi.php";
$query = mysqli_query($connection,"SELECT * FROM buatsoal_db ORDER BY ID DESC");
$id = mysqli_query($connection, "select 'ID' from buatsoal_db");
?>
<?php
do{ ?>
<form method= 'post'>
<input name='next' type='submit' id='next' value='next'>
</form>
<?php if(isset($_POST['next'])){ ?>
<table width="637" border="0" cellspacing="1" cellpadding="2">
<tr>
<th width="297" scope="col">
<?php $row = mysqli_fetch_array ($query);
echo $row['SOALTXT']; ?>
</tr>
</table>
<?php }
?>
<?php }
while ($id == 'S01');
echo "sudah selesai";
?>
Just use the comparison statement in do while loop like:
do{
//your code block here
}while($id == 'S01');
Issue is in while statement.
what you have to do is:
do {
...
}
while($id == 'S01');
== is the solution

index of fetch array

i want to get the index of td that the user clicked , i have an html table fill from database using php ...
this is my index.php :
<html>
<head>
<title>Last 10 Results</title>
</head>
<body>
<table>
<thead>
</thead>
<tbody>
<tr>
<?php
session_start();
$connect = mysqli_connect("localhost","root","","test");
if (!$connect) {
die(mysql_error());
}
$results = mysqli_query($connect,"SELECT * FROM family where parent_id = 0");
while($row = mysqli_fetch_assoc($results)) {
?>
<td onclick="window.location='index2.php'"
<?php $id = $row['id'];
$_SESSION['varname'] = $id;?>>
<?php echo $row['name']?> <br/>
<?php echo $row['description']?> <br/>
<?php echo $row['parent_id']?> <br/>
</td>
<?php
}
?>
</tr>
</tbody>
</table>
</body>
</html>
this is my index2.php :
<html>
<head>
<title>Last 10 Results</title>
</head>
<body>
<table>
<thead>
</thead>
<tbody>
<tr>
<?php
session_start();
$gg = $_SESSION['varname'];
echo $gg;
$connect = mysqli_connect("localhost","root", "","test");
if (!$connect) {
die(mysql_error());
}
$results = mysqli_query($connect,"SELECT * FROM family where parent_id = '$gg' ");
while($row = mysqli_fetch_array($results)) {
?>
<td>
<?php echo $row['id']?> <br/>
<?php echo $row['name']?> <br/>
<?php echo $row['description']?> <br/>
<?php echo $row['parent_id']?> <br/>
</td>
<?php
}
?>
</tr>
</tbody>
</table>
</body>
</html>
now i want to take the "id" of the td that the user click on,, but this code always give me the last id in my database ...
what can i do ?
Replace in Index.php:
<td onclick="window.location='index2.php'"
With:
<td onclick="window.location='index2.php?parent_id=<?php echo $row['id']; ?>'"
And in
Index2.php:
$gg = $_SESSION['varname'];
With:
$gg = (int)$_GET['parent_id'];
It's better to use $_GET variable for this than $_session (urls are search engine friendly)

Cannot Input image to database. Image File Upload Error: Undefined index: file_img

Hi everyone i need some help regarding this error. Im trying to create a module that will allow users to upload their image and display it to the other page. I am using 3 forms (index.php for displaying, create.php for sql query and addform.php for adding records). But everytime I run the program it always shows an error: Undefined index: file_img
index.php
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="assets/jquery-1.11.3-jquery.min.js"> </script>
</head>
<body>
<div class="container">
<h2 class="form-signin-heading">Employee Records.</h2><hr />
<button class="btn btn-info" type="button" id="btn-add"> <span class="glyphicon glyphicon-pencil"></span> Add Employee</button>
<button class="btn btn-info" type="button" id="btn-view"> <span class="glyphicon glyphicon-eye-open"></span> View Employee</button>
<hr />
<div class="content-loader">
<table cellspacing="0" width="100%" id="example" class="table table-striped table-hover table-responsive">
<thead>
<tr>
<th>Title</th>
<th>Content</th>
<th>Photos</th>
</tr>
</thead>
<?php
require_once 'dbconfig.php';
$sql = $db_con->prepare("select id, name, content, imgname from tblkeanu");
$sql->execute();
while($result=$sql->fetch(PDO::FETCH_ASSOC))
{
echo '<tr>';
echo '<td>' . $result["name"] . '</td>';
echo '<td>' . $result["content"] . '</td>';
echo "<td><img src = 'images/" . $result['imgname'] . "' height='350px;' width='300px;' class='img'></td>";
echo "<td><a id = $result[id] class = 'edit_link' href='#' title = 'EDIT'> EDIT </a></td>";
echo "<td><a id = $result[id] class = 'delete_link' href='#' title = 'DELETE'> DELETE </a></td>";
echo ' </td>';
echo '</tr>';
}
?>
</table>
</div>
</div>
<br />
<div class="container">
<div class="alert alert-info">
Tutorial Link
</div>
</div>
</body>
</html>
create.php
<?php
require_once 'dbconfig.php';
if($_POST)
{
$name = $_POST['txtname'];
$content = $_POST['txtcontent'];
$filetmp = $_FILES['file_img']['tmp_name'];
$filename1 = $_FILES['file_img']['name'];
$filetype = $_FILES['file_img']['type'];
$filepath = 'images/'.$filename1;
try{
move_uploaded_file($filetmp,$filepath);
$sql = $db_con->prepare("INSERT INTO `tblkeanu`(`name`, `content`, `imgname`, `imgpath`, `imgtype`) Values (:name,:content,:filename1,:filepath,:filetype)");
$sql->bindParam(":name",$name);
$sql->bindParam(":content",$content);
$sql->bindParam(":filename1",$filename1);
$sql->bindParam(":filetype",$filetype);
$sql->bindParam(":filepath",$filepath);
if($sql->execute())
{
echo "Successfully Added";
}
else{
echo "Query Problem";
}
}
catch(PDOException $e){
echo $e->getMessage();
}
}
?>
addform.php
<form method='post' id='emp-SaveForm' action="#" enctype="multipart/form-data">
<table class='table table-bordered'>
<tr>
<td>Title</td>
<td><input type='text' name='txtname' class='form-control' placeholder='EX : john doe' required /></td>
</tr>
<tr>
<td>Content</td>
<td><input type='text' name='txtcontent' class='form-control' placeholder='EX : Web Design, App Design' required></td>
</tr>
<tr>
<td>Photo</td>
<td><input type='file' name='file_img'/></td>
</tr>
<tr>
<td colspan="2">
<button type="submit" class="btn btn-primary" name="btn-save" id="btn-save">
<span class="glyphicon glyphicon-plus"></span> Save this Record
</button>
</td>
</tr>
</table>
The tricky part here is if i combined the addform.php to create.php and address bar is "..../..../create.php" the program runs smoothly and the input type was identified. but i need these 2 to be separated and not combined on one page so the webpage will not be refreshed everytime because im also using a javascript and jquery and the address should only be "..../..../index.php".
It will be much appreciated if you could help me out.
In your addform.php file the form dosen't have an action yet, The form action should be create.php.
In the create.php file the condition:
if($sql->execute())
{
echo "Successfully Added";
}
else{
echo "Query Problem";
}
Should be modified as :
if($sql->execute())
{
header("Location: index.php");
}
else{
echo "Query Problem";
}
This way after saving the records to the database you will be redirected to index.php .
**IN This Section **
<tr>
<td>Photo</td>
<td><input type='file' name='file_img'/></td>
</tr>
Please try this edit, It may help..
<tr>
<td>Photo</td>
<td><input type='file' name='file_img' accept='image/*'/></td>
</tr>

Update query is not working correctly

I am making a code for editing a text area. The query runs correctly without any errors but the textarea is not updated. Can anyone help me with it please?
<html>
<body bgcolor="skyblue">
<form method= "post" enctype="multipart/form-data" action="upd.php">
<table align="center" width="795" border="2" bgcolor="#CCC">
<?php
$i=0;
$sel="select * from video";
$sel_query=mysqli_query($con, $sel);
while($row=mysqli_fetch_array($sel_query)){
$i++;
$var_id=$row['v_id'];
$var=$row['video'];
?>
<tr align="center">
<td align="right">
<br>
<h2>Upadte Video <?php echo $i; ?> Link: </h2>
<button type="submit" name="btn">
<a name="upd" href="upd.php?insert_brand=<?php echo $var_id; ?>&fram=<?php echo $var; ?>">Update</a>
</button>
<td align="left"><br><textarea name="vids" rows="4" cols="50"><?php echo $var; ?>"</textarea></td>
</td>
</tr>
<?php
}
?>
</table>
</form>
upd.php
<?php
include ("includes/db.php");
$check=#$_GET['insert_brand'];
if(isset($_POST['btn'])){
$vids=$_POST['vids'];
$upds="UPDATE `video` SET `video`='$vids' WHERE `v_id`='$check'";
$query=mysqli_query($con, $upds);
if($query){
echo 'The query is executed';
}
else{
echo 'There was an error'. mysqli_error($con);
}
}
?>
Have you tried mysql_real_escape_string() to retrieve textarea data.

Display error when the query dont return result in mysql

I am building an application that gives user the opportunity to click on the day of the calendar and when there is an activity registered on that day, it shows a table with the activity registered...my problem is that when there is no activity on that day, I wont it to return the string : There is no activity.. I try to make it using if($nrofrows>0)like below but all the time it returns me the string :there is not activity, even I have activity on that day.
Please can you help me ? where is my error? Thanks in advance...
<body>
<?php
mysql_connect("127.0.0.1","root","") or die("Smund te lidhet me serverin");
mysql_select_db("axhenda") or die("Kjo databaze nuk u gjet");
session_start();
$perdoruesi=$_SESSION['user_id'];
$result= mysql_query("SELECT * FROM Aktiviteti where Data= '$_POST[dataoutput]' and Perd_Id='$perdoruesi'");
$nrofrows= mysql_num_rows($result);
if($nrofrows>0)
{
?>
<div class="title"> Aktivitetet per daten <?php print ("$_POST[dataoutput]"); ?></div>
<form name="form1" method="post" action="delete.php">
<table >
<th>
<th ><strong>Emri </strong></th>
<th ><strong>Pershkrimi </strong></th>
<th><strong>Ora</strong></th>
</th>
<?php
while ($row=mysql_fetch_array($result)) {
?>
<tr>
<td ><input name="checkbox[]" type="checkbox" value="<?php echo $row['Id_Akt']; ?>"></td>
<td style="font-size:0.9em"><?php echo $row['Emri']; ?></td>
<td ><?php echo $row['Pershkrimi']; ?></td>
<td><?php echo $row['Ora']; ?></td>
</tr>
<?php
}
?>
</table>
<input class="button" name="delete" type="submit" value="Delete" style="margin-left:40%; margin-top:100px; width:15%">
</form>
<?php
}
else {
echo "<span id='errorformat'>There is no activity on this day!<span>";}
?>
</body>
</html>
Might be a problem with the query you can add this to see:
$result= mysql_query("SELECT * FROM Aktiviteti where Data= '$_POST[dataoutput]' and Perd_Id='$perdoruesi'") or die ("query error" .mysql_error());
mysql_num_rows($result) returns false when there is an error so you might want to add this:
if($nrofrows && $nrofrows>0)
try this
if ( mysql_num_rows($result) > 0 ) {
}

Categories