i have a controller name UserController in application/controllers
the base folder is zend-login and there are 3 sub folder 1= application 2 = library 3=web_root
problem is here!! when ever i hit http://localhost/zend_login/web_root/user/login or http://localhost/zend_login/web_root/user/register
i get this error Error 404 Object not found! both the file are there in a folder
<?php
require_once 'Zend/Controller/Action.php';
class UserController extends Zend_Controller_Action{
public function indexAction(){
$this->view->assign('name', 'xainee');
$this->view->assign('title', 'Hello');
}
public function loginAction(){
$request = $this->getRequest();
$this->view->assign('action', $request->getParam());
$this->view->assign('title', 'Login Form');
$this->view->assign('username', 'User Name');
$this->view->assign('password', 'Password');
}
public function registerAction(){
$request = $this->getRequest();
$this->view->assign('action',"process");
$this->view->assign('title','Member Registration');
$this->view->assign('label_fname','First Name');
$this->view->assign('label_lname','Last Name');
$this->view->assign('label_uname','User Name');
$this->view->assign('label_pass','Password');
$this->view->assign('label_submit','Register');
$this->view->assign('description','Please enter this form completely:');
}
}
?>
action for this is here views/scripts/user/register.phtml and
views/scripts/user/login.phtml
this is register.phtml
<?php include "header.phtml"; ?>
<h1><?=$this->escape($this->title);?></h1>
<div id="description">
<?=$this->escape($this->description);?>
</div>
<form name="register" method="post" action="<?=$this->escape($this->action)?>">
<table>
<tr>
<td><?=$this->escape($this->label_fname)?></td>
<td><input type="text" name="first_name"></td>
</tr>
<tr>
<td><?=$this->escape($this->label_lname)?></td>
<td><input type="text" name="last_name"></td>
</tr>
<tr>
<td><?=$this->escape($this->label_uname)?></td>
<td><input type="text" name="user_name"></td>
</tr>
<tr>
<td><?=$this->escape($this->label_pass)?></td>
<td><input type="password" name="password"></td>
</tr>
</table>
<input type="submit" name="submit" value="<?=$this->escape($this->label_submit);?>">
</form>
<?php include "footer.phtml"; ?>
recommended .htaccess is
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
Related
I have Apache on Ubuntu OS. My Ubuntu use amazon Lightsail. I set up a VirtualHost for use the Perfect web server like this
<Location "/PerfectTemplate">
ProxyPass http://localhost:8182
ProxyPassReverse http://localhost:8182
</Location>
I was trying POST actions from HTML, but programs refer to Apache
var try_post_action = """
<form action="./tow" method="post">
//<form action="/tow" method="post">
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
<input type="submit" value="Submit">
</form>
"""
The following Apache conf snippet
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) - [L,NS,H=perfect-handler]
and swift file
import PerfectHTTP
import PerfectHTTPServer
func handler(request: HTTPRequest, response: HTTPResponse) {
response.setHeader(.contentType, value: "text/html")
response.appendBody(string: """
<form action="./PerfectTemplate/test" method="get">
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
<input type="submit" value="Submit">
</form>
""")
response.completed()
}
let confData = [
"servers": [
[
"name":"localhost",
"port":8182,
"routes":[
["method":"get", "uri":"/", "handler":handler],
["method":"get", "uri":"/test", "handler":handler],
["method":"get", "uri":"/**", "handler":PerfectHTTPServer.HTTPHandler.staticFiles,
"documentRoot":"./webroot",
"allowResponseFilters":true]
],
"filters":[
[
"type":"response",
"priority":"high",
"name":PerfectHTTPServer.HTTPFilter.contentCompression,
]
]
]
]
]
do {
try HTTPServer.launch(configurationData: confData)
} catch {
fatalError("\(error)")
}
The code gets error saying Object of class mysqli could not be converted to int. When i try to load the page i get this error,i checked other questions but it was not helpful
<?php
$conn = mysqli_connect("localhost", "root", "", "coinlion");
if ($conn == 0) {
echo "could not connect";
} else {
mysqli_select_db("coinlion");
echo "connected";
}
?>
<form method="post">
<style>
#newlink {
width: 600px
}
</style>
<div id="newlink">
<div>
<table border=0>
<tr>
<td> Link URL:</td>
<td><input type="text" name="linkurl" value="" required></td>
</tr>
<tr>
<td> Link Description:</td>
<td><textarea name="linkdesc" cols="50" rows="5" required></textarea>
</td>
</tr>
</table>
</div>
</div>
<p>
<br>
<input type="submit" name="submit1">
<input type="reset" name="reset1">
</p>
php code
<?php
if (isset($_POST['submit1'])) {
$linkurl = $_POST['linkurl'];
$linkdesc = $_POST['linkdesc'];
mysqli_query($conn, "insert into
test(linkurl,linkdesc)values('$_POST[linkurl]','$_POST[linkdesc]')");
echo "data inserted";
}
?>
Well the issue was with the line if($conn==0) ,This value was taken as an integer so the error occured and an Connection variable to Mysqli_select_db was missing , after fixing it , the code ran successfully
I have here the page for update.php my problem was I keep getting this error
Notice: Undefined index: province in D:\wamp\www\PDO\sampleCRUD\update.php on line 13
every time I select this value "---" in my dropdown list it keeps showing this error but if select the rest of the list in the dropdown there's no error I tried to set the province but I still getting this error.
here my code for update.php
<?php
include_once 'dbconfig.php';
$username = isset($_GET['username']) ? $_GET['username'] : '';
$password = isset($_GET['password']) ? $_GET['password'] : '';
$province = isset($_GET['province']) ? $_GET['province'] : '';
if(isset($_POST['btn-update']))
{
$user_id = $_GET['user_id'];
$username = $_POST['username'];
$password = $_POST['password'];
$province = $_POST['province'];
if($crud->update($user_id,$username,$password,$province))
{
echo "<script type='text/javascript'>alert('Record was updated Successfully!');</script>";
}
else
{
echo "<script type='text/javascript'>alert('Updating Failed!'); </script>";
}
}
if(isset($_GET['user_id']))
{
$user_id = $_GET['user_id'];
extract($crud->getID($user_id));
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-type" content="text/html; charset=UTF-8">
<title>Survey Update Landholdings</title>
<link rel="shortcut icon" href="image/icon.ico"/>
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<div class="container">
<p><strong>Survey Update</strong></p>
<br />
<div id="Survey-Update">
<form method='post'>
<table class='table table-bordered'>
<tr>
<td>First Name</td>
<td><input type='text' name='username' class='form-control' value="<?php echo $username; ?>" required></td>
</tr>
<tr>
<td>Last Name</td>
<td><input type='text' name='password' class='form-control' value="<?php echo $password; ?>" required></td>
</tr>
<tr>
<td>Province</td>
<?php
include_once 'dbconfig.php';
$sql = "SELECT username FROM sample";
$stmt = $DB_con->prepare($sql);
$stmt->execute();
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
if ($stmt->rowCount() > 0)
{
?>
<td><select class='form-control' name='province'>
<option selected="selected" disabled>---</option>
<?php foreach ($results as $row)
{
?>
<option value="<?php echo $row['username']; ?>"><?php echo $row['username']; ?></option>
<?php
}
?>
</select>
<?php
}
?>
</td>
</tr>
<tr>
<td colspan="2">
<button type="submit" class="btn btn-primary" name="btn-update">
<span class="edit"></span>Update</button>
CANCEL
</td>
</tr>
</table>
</form>
</div>
the error is in this line
$province = $_POST['province'];
Change this line
<option selected="selected" disabled>---</option>
to
<option selected="selected" value="" disabled>---</option>
to send an empty value for province instead of none.
Edit: the above code does not work.
The issue here is the disabled and selected="selected". It seems, disabled options don't get submitted.
If you want to stick with disabled and selected I suggest using
$province = isset($_POST['province']) ? $_POST['province'] : '';
My problem is that when i try to update my DB table (hold) it makes all fields blank.
im using three files a config to connect.This is the config.php file.
<?php
$hostname='localhost';
$username='root';
$password='kv5772';
try {
$db = new PDO("mysql:host=$hostname;dbname=gade",$username,$password);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // <== add this line
echo 'Connected to Database<br/>';
}
catch(PDOException $e)
{
echo $e->getMessage();
}
?>
Then there is a print page print.php. With a delete button. It works. But the edit dont.
<?php include "config.php" ?>
<?php
$sql = "SELECT * FROM hold";?>
<table>
<tr>
<td>hold</td>
<td>leder</td>
<td>telefon</td>
<td>mail</td>
</tr>
<?php
foreach($db->query($sql) as $row){
?>
<tr>
<td><input name="hold" type="text" placeholder="<?php echo "{$row['hold']}";?>"/></td>
<td><input name="leder" type="text" placeholder="<?php echo "{$row['leder']}";?>"/></td>
<td><input name="telefon" type="text" placeholder="<?php echo "{$row['telefon']}";?>"/></td>
<td><input name="email" type="text" placeholder="<?php echo "{$row['email']}";?>"/></td>
<td>
<form action="formupdatecode.php" method="post">
<input type="hidden" name="action" value="edit" />
<input type="hidden" name="id" value="<?php echo $row['id'] ?>" />
<input type="submit" value="edit" />
</form>
</td>
<td>
<form action="slet.php" method="post">
<input type="hidden" name="action" value="delete" />
<input type="hidden" name="id" value="<?php echo $row['id'] ?>" />
<input type="submit" value="delete" />
</form>
</td>
</tr>
</table>
<?php
}
$db = null;
?>
The edit button is connected to formupdatecode.php.
<?php include "config.php" ?>
<?php
$sql = "UPDATE hold SET hold = :hold,
leder = :leder,
telefon = :telefon,
email = :email
WHERE id = :id";
$stmt = $db->prepare($sql);
$stmt->bindParam(':id', $_POST['id'], PDO::PARAM_INT);
$stmt->bindParam(':hold', $_POST['hold'], PDO::PARAM_STR);
$stmt->bindParam(':leder', $_POST['leder'], PDO::PARAM_STR);
$stmt->bindParam(':telefon', $_POST['telefon'], PDO::PARAM_STR);
$stmt->bindParam(':email', $_POST['email'], PDO::PARAM_STR);
if($stmt->execute()){
echo "Successfully redigeret hold";
}// End of if profile is ok
else{
print_r($stmt->errorInfo()); // if any error is there it will be posted
$msg=" Database problem, please contact site admin ";
}
?>
Your HTML code has a problem with the location of the input tags.
Your edit/input fields are located outside the form and will not be included in the POST back to the server.
I am creating a rails 3 app using batman.js for the front end. I am able to submit a successful delete request when I'm in the show.html view of an individual record. But when I am in the index.html view, the same pattern is not triggering the delete method. I am guessing there's a little magic occurring when Batman.js triggers a delete request which I do not understand. Probably something to do with the scope of the venue variable in the index.html view. I'll show my code for the controller and the two views in question. If you need something else, please ask.
/app/assets/javascripts/controllers/venues_controller.js.coffee
class Plansandpictures.VenuesController extends Batman.Controller
routingKey: 'venues'
index: (params) ->
#set 'newVenue', new Plansandpictures.Venue
Plansandpictures.Venue.load (err, venues) =>
#set 'venues', Plansandpictures.Venue.get('loaded')
show: (params) ->
Plansandpictures.Venue.find parseInt(params.id, 10), (err,result) =>
throw err if err
#set 'venue', result
#render source: 'venues/show'
create: (params) ->
#newVenue.save (err, venue) =>
if !err
#set 'newVenue', new Plansandpictures.Venue
Plansandpictures.Venue.get('loaded').add(venue)
update: (params) ->
destroy: (params) ->
#get('venue').destroy (err) =>
if err
throw err unless err instanceof Batman.ErrorsSet
else
Plansandpictures.flashSuccess "Removed successfully!"
#redirect '/venues'
/app/assets/javascripts/views/venues/show.html
<h4 data-bind="venue.name"></h4>
<h6>Description</h6>
<p data-bind="venue.description"></p>
<h6>Address</h6>
<p data-bind="venue.address"></p>
<h6>City</h6>
<p data-bind="venue.city"></p>
<h6>State</h6>
<p data-bind="venue.state"></p>
<a data-event-click="controllers.venues.destroy | withArguments venue">delete</a>
/app/assets/javascripts/views/venues/index.html
<h2>Venues</h2>
<table>
<thead>
<th>Name</th>
<th>Description</th>
<th>Address</th>
<th>City</th>
<th>State</th>
</thead>
<tbody>
<tr data-foreach-venue="venues">
<td data-bind="venue.name"></td>
<td data-bind="venue.description"></td>
<td data-bind="venue.address"></td>
<td data-bind="venue.city"></td>
<td data-bind="venue.state"></td>
<td><a data-route="routes.venues[venue]">show</a></td>
<td><a data-event-click="controllers.venues.destroy | withArguments venue">delete</a></td>
</tr>
</tbody>
</table>
<h3>Add a Venue</h3>
<form data-formfor-venue="controllers.venues.newVenue" data-event-submit="controllers.venues.create">
<input class="new-item" placeholder="Name" data-bind="venue.name" />
<input class="new-item" placeholder="Description" data-bind="venue.description" />
<input class="new-item" placeholder="Address" data-bind="venue.address" />
<input class="new-item" placeholder="City" data-bind="venue.city" />
<input class="new-item" placeholder="State" data-bind="venue.state" />
<input class="new-item" type="number" placeholder="1" data-bind="venue.user_id" />
<input type="submit" value="Add Venue" />
</form>
Your controller assumes it can fetch the venue via #get('venue'), but that's not necessarily set on the index view. So change:
destroy: (params) ->
#get('venue').destroy (err) =>
to:
destroy: (venue) ->
venue.destroy (err) =>
And this ought to work from both contexts.