Can a PDO $statement -> execute more than one parameter? - php

It's the last piece of this that eludes me, I'm hoping someone can shed some light on what's missing.
The longer part of this code works just fine, it's the UPDATE portion (in the
dis_adjust.php file) that's causing the grief.
In place of the hard coded number 13, it needs to accept the variable 'catID'.
The variable 'catID' initially filters for the number 1, and is then UPDATED to 5 when the "Rewarded" button is clicked.
Not sure if I'm explaining it correctly, or clearly...perhaps it's the sleep deprivation.
dis_adjust.php
<?php
require 'dis_db.php';
$tag_h_id = $_GET['id'];
$sql = 'UPDATE `coh_items` SET `enabled`=5, `rewarded_at`= now() WHERE `category_id`=13 AND `tag_h_id`=:id';
$statement = $connection->prepare($sql);
if ($statement->execute([':id' => $tag_h_id])) {
header("Location: http://localhost/green/management/disbursements.php");
}
<?php
require 'dis_db.php';
$sql = 'SELECT
coh_items.id,
coh_items.tag_h_id,
coh_vendors.name,
coh_vendors.phone,
coh_vendors.tax_number,
coh_vendors.currency_code,
coh_items.purchase_price,
COUNT(tag_h_id) AS Reports,
(
purchase_price * COUNT(tag_h_id)
) AS Reward
FROM
coh_items
INNER JOIN coh_vendors ON coh_items.tag_h_id = coh_vendors.id
WHERE
coh_items.enabled = 1 AND category_id = ?
GROUP BY
tag_h_id;';
$statement = $connection->prepare($sql);
//$statement ->bindParam(':category_id', $catID, PDO::PARAM_INT);
$statement->execute([$_POST['catID']]);
$people = $statement->fetchAll(PDO::FETCH_OBJ);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Disbursement</title>
<link rel="stylesheet" href="http://localhost/green/vendor/almasaeed2010/adminlte/bootstrap/css/bootstrap.min.css">
<!-- <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.js"></script>
<!-- <script src="http://localhost/green/vendor/almasaeed2010/adminlte/bootstrap/js/bootstrap.js"></script> -->
<style type="text/css">
</style>
<script type="text/javascript">
$(document).ready(function(){
$('[data-toggle="tooltip"]').tooltip();
});
</script>
</head>
<body>
<div class="wrapper">
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<div class="page-header clearfix">
<h3 class="center">Details by Category</h3>
<div>
<!--Filter Button -->
<div>
<div class="col-md-2">
<p class="margin"></p>
<div class="input-group">
<div class="input-group-btn">
<form action="http://localhost/green/management/disbursements.php" method="post">
<input type="text" name = "catID" placeholder="Category" class="form-control" >
<input type="submit" value= "Filter" class="btn btn-primary ">Filter</button></d>
</div>
</div>
</div>
</div>
</div>
<br>
<br>
<div class="col-md-8">
<table class="table table-bordered">
<tr>
<th>ID</th>
<th>Name</th>
<th>Phone</th>
<th>Zip</th>
<th>Status</th>
<th>Number of Reports</th>
<th>Award</th>
<th>Action</th>
</tr>
<?php foreach($people as $person): ?>
<tr>
<td><?= $person->tag_h_id; ?></td>
<td><?= $person->name; ?></td>
<td><?= $person->phone; ?></td>
<td><?= $person->tax_number; ?></td>
<td><?= $person->currency_code; ?></td>
<td><?= $person->Reports; ?></td>
<td><?= $person->Reward; ?></td>
<td>
<a href="./disbursements/dis_adjust.php?id=<?= $person->tag_h_id ?>" name = 'adjust' class='btn btn-success'>Rewarded</a>
</td>
</tr>
<?php endforeach; ?>
</table>
</div>
</div>
</div>
</div>

PDO prepared statements can accept an arbitrary number of parameters. To modify yours to use the variable $catId, change your query to:
$sql = 'UPDATE `coh_items` SET `enabled`=5, `rewarded_at`= now() WHERE `category_id`=:cat_id AND `tag_h_id`=:id';
and the execute call to:
$statement->execute([':id' => $tag_h_id, ':cat_id' => $catID])

Related

How to display data from selected table in the same database in the form of table, in php?

I am working on a website where I am getting input of semester number from the user and I want to display the subjects in the semester they entered accordingly.
For this, I planned to create tables for each semester which would have the subjects in it.
For now, I am successful to retrieve data from one table. But I am required to get subjects as per the entered semester by the student.
Following is the code,which works perfectly for semester 5. Please suggest alterations as per the requirements asked above.
<!DOCTYPE html>
<html>
<head>
<title></title>
<!-- very important -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="subject.css">
</head>
<body>
<h1 class="text-center text-capitalize font-weight-bold">Subject Information</h1>
<div class="container">
<div>
<br>
<div>
<form class="form-inline">
<!-- <div class="mx-auto" style="width: 200px;"> -->
<div class="form-group">
<label for="Sem"> Semester: </label>
<div>
<input type="text" name="sem_no" placeholder="Enter current semester" id=sem class="form-control">
</div>
<br>
</div>
</form>
</div>
</div>
</div>
<div>
<!-- TABLE DISPLAYED WITH DATA FROM RESPECTIVE DATABASE -->
<div class= "container">
<div class="col-lg-12 ">
<br><br>
<h2 class="text-center">Subjects</h2>
<table class="table table-striped table-hover table-bordered">
<tr>
<th>Subject code</th>
<th>Subject Name</th>
<th>Faculty name</th>
</tr>
<?php
$con = mysqli_connect('localhost','root');
mysqli_select_db($con,'subjects');
$q= "select * from sem5";
$query = mysqli_query($con,$q);
while($res = mysqli_fetch_array($query))
{
?>
<tr>
<td><?php echo $res['subject_no']; ?></td>
<td><?php echo $res['subject_name']; ?></td>
<td><?php echo $res['faculty_name']; ?></td>
</tr>
<?php
}
?>
</table>
</div>
</div>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
</body>
</html>
Please suggest alterations. Will be highly obliged.
You need to do a HTTP GET request and use PHP to get the value. Then use PHP to make the SQL query. Here it is in its simplest form.
I've added a submit button which submits the form and executes the HTTP GET with the parameters attached to the URL. You will see ?sem_no=x after it is submitted. That's the Query String.
...
...
<div class="form-group">
<label for="Sem"> Semester: </label>
<div>
<input type="text" name="sem_no" placeholder="Enter current semester" id=sem class="form-control">
</div>
<div>
<input type="submit"/>
</div>
<br>
...
...
...
...
//check the value was submitted and it is not blank
<?php if(isset($_GET['sem_no']) && !empty($_GET['sem_no'])) { ?>
<!-- TABLE DISPLAYED WITH DATA FROM RESPECTIVE DATABASE -->
<div class= "container">
<div class="col-lg-12 ">
<br><br>
<h2 class="text-center">Subjects</h2>
<table class="table table-striped table-hover table-bordered">
<tr>
<th>Subject code</th>
<th>Subject Name</th>
<th>Faculty name</th>
</tr>
<?php
$con = mysqli_connect('localhost','root');
mysqli_select_db($con,'subjects');
$q= 'select * from sem'.$_GET['sem_no'];
$query = mysqli_query($con,$q);
while($res = mysqli_fetch_array($query))
{
?>
<tr>
<td><?php echo $res['subject_no']; ?></td>
<td><?php echo $res['subject_name']; ?></td>
<td><?php echo $res['faculty_name']; ?></td>
</tr>
<?php
}
?>
</table>
</div>
</div>
<?php
//closing if
} ?>
...
...
As mentioned in the comments earlier, this database design is quite poor. I know you are learning though. Have you considered having a subjects table that has a Semester column? Then you could do a query like:
SELECT * FROM subjects where semester_number = x
There are even better ways to do it beyond that but this would be a good starting point for you.

Rendering success or failure on the same page REMINDER HERE

My error or success message is not in the right place, so I want to know how to get my message in the right place.
I have been searching the internet. I cannot find the right solution.
Here a photo what I mean.
<!DOCTYPE html>
<?php include('import_excel.php') ?>
<?php include('functions.php') ?>
<html lang="en" class=""><head>
<meta name="ac:base" content="/C:/xampp/htdocs/Angular-421-N-WORK-APP">
<meta charset="utf-8">
<title>N-WORK-USER | opslag-Sorting</title>
<meta name="description" content="app, web app, responsive, responsive layout, admin, admin panel, admin dashboard, flat, flat ui, ui kit, AngularJS, ui route, charts, widgets, components">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" href="../libs/assets/animate.css/animate.css" type="text/css">
<link rel="stylesheet" href="../libs/assets/font-awesome/css/font-awesome.min.css" type="text/css">
<link rel="stylesheet" href="../libs/assets/simple-line-icons/css/simple-line-icons.css" type="text/css">
<link rel="stylesheet" href="../libs/jquery/bootstrap/dist/css/bootstrap.css" type="text/css">
<link rel="stylesheet" href="css/app.min.css" type="text/css">
<link rel="stylesheet" type="text/css" href="css/component.css">
<script>
(function(e,t,n){
var r=e.querySelectorAll("html")[0];r.className=r.className.replace(/(^|\s)no-js(\s|$)/,"$1js$2");
}
(document,window,0)
);
</script>
</head>
<body>
<!-- content -->
<div id="content" class="app-content" role="main">
<div class="app-content-body ">
<div ng-controller="FullcalendarCtrl">
<!-- main header -->
<div class="wrapper-md bg-yello b-b">
<h1 class="m-n font-thin h3">Lijst werkkracht TL GL Database</h1>
</div>
<!-- / main header -->
<div class="wrapper-md" ng-controller="FormDemoCtrl">
<div class="panel panel-defaultgrd">
<div class="panel-headinggrd font-bold text-blue">
Uitslag
</div>
<div class="panel-body">
<div class="hbox hbox-auto-xs hbox-auto-sm">
<div class="container">
<div class="row">
<div class="col-md-12 control-label">
<button class="btn btn-info">Database invoegen</button>
<a class="btn btnx btn-orange" id="download-btn" target="_new"><i class="fa fa-download"></i> Export to Excel</a>
<form method="post" action="import_excel.php" enctype="multipart/form-data">
<div class="form-groupp" style="">
<input type="file" name="file-7" id="file-7" class="inputfile inputfile-6" data-multiple-caption="{count} files selected" multiple=""><label for="file-7"><span></span> <strong><svg xmlns="http://www.w3.org/2000/svg" width="20" height="17" viewBox="0 0 20 17"><path d="M10 0l-5.2 4.9h3.3v5.1h3.8v-5.1h3.3l-5.2-4.9zm9.3 11.5l-3.2-2.1h-2l3.4 2.6h-3.5c-.1 0-.2.1-.2.1l-.8 2.3h-6l-.8-2.2c-.1-.1-.1-.2-.2-.2h-3.6l3.4-2.6h-2l-3.2 2.1c-.4.3-.7 1-.6 1.5l.6 3.1c.1.5.7.9 1.2.9h16.3c.6 0 1.1-.4 1.3-.9l.6-3.1c.1-.5-.2-1.2-.7-1.5z"></path></svg> Import Excel..</strong></label>
</div>
<a class="btnl"><button class="btn btn-info" style="">Upload</button></a>
</form>
<div class="table-responsive">
<table id="mytable" class="table table-bordred table-striped">
<thead>
<tr>
<th>#</th>
<th>MBU</th>
<th>Zone</th>
<th>Omschrijving</th>
<th>TL</th>
<th>GL</th>
<th>Stand in lijn</th>
<th>Station</th>
<th>MBU nr</th>
<th>WO stap</th>
<th>LOG stap</th>
<th>Q stap</th>
<th>RA stand</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<?php
$fetchdata=new DB_con();
$sql=$fetchdata->fetchdata();
$cnt=1;
while($row=mysqli_fetch_array($sql))
{
?>
<tr>
<td><?php echo htmlentities($cnt);?></td>
<td><?php echo htmlentities($row['MBU']);?></td>
<td><?php echo htmlentities($row['zone']);?></td>
<td><?php echo htmlentities($row['omschr']);?></td>
<td><?php echo htmlentities($row['tl']);?></td>
<td><?php echo htmlentities($row['gl']);?></td>
<td><?php echo htmlentities($row['stand_in_lijn']);?></td>
<td><?php echo htmlentities($row['station']);?></td>
<td><?php echo htmlentities($row['MBU_nr']);?></td>
<td><?php echo htmlentities($row['WO_stap']);?></td>
<td><?php echo htmlentities($row['LOG_stap']);?></td>
<td><?php echo htmlentities($row['Q_stap']);?></td>
<td><?php echo htmlentities($row['RA_stand']);?></td>
<td><button class="btn btn-info btn-xs"><span class="glyphicon glyphicon-pencil"></span></button></td>
<td><button class="btn btn-danger btn-xs" onclick="return confirm('Wil je bestand echt verwijderen?');"><span class="glyphicon glyphicon-trash"></span></button></td>
</tr>
<?php
// for serial number increment
$cnt++;
}
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- / main -->
</div>
</div>
<!-- /content -->
<!-- footer -->
<footer id="footer" class="app-footer" role="footer">
<div class="wrapper b-t bg-light">
<span class="pull-right">2.3.0 <i class="fa fa-long-arrow-up"></i></span>
© 2018 Copyright.
</div>
</footer>
<!-- / footer -->
<script src="js/app.min.js"></script>
</body>
</html>
my other code import_excel.php
<?php
/**
* RaeCreated by Homensdigiworld.
* Admin: Stefaan
* Date: 26-03-2019
*/
include_once "app_opslag_database_tl_gl.php";
use Box\Spout\Reader\ReaderFactory;
use Box\Spout\Common\Type;
require_once ('connect.php');
require_once ('Spout/Autoloader/autoload.php');
if(!empty($_FILES['file-7']['name']))
{
// Get File extension eg. 'xlsx' to check file is excel sheet
$pathinfo = pathinfo($_FILES['file-7']['name']);
// check file has extension xlsx, xls and also check
// file is not empty
if (($pathinfo['extension'] == 'xlsx' || $pathinfo['extension'] == 'xls')
&& $_FILES['file-7']['size'] > 0 )
{
$file = $_FILES['file-7']['tmp_name'];
// Read excel file by using ReadFactory object.
$reader = ReaderFactory::create(Type::XLSX);
// Open file
$reader->open($file);
$count = 0;
// Number of sheet in excel file
foreach ($reader->getSheetIterator() as $sheet)
{
// Number of Rows in Excel sheet
foreach ($sheet->getRowIterator() as $row)
{
// It reads data after header. In the my excel sheet,
// header is in the first row.
if ($count > 0) {
// Data of excel sheet
$MBU = $row[1];
$zone = $row[2];
$omschr = $row[3];
$tl = $row[4];
$gl = $row[5];
$stand_in_lijn = $row[6];
$station = $row[7];
$MBU_nr = $row[8];
$WO_stap = $row[9];
$LOG_stap = $row[10];
$Q_stap = $row[11];
$RA_stand = $row[12];
//Here, You can insert data into database.
$qry = "INSERT INTO `users`(`MBU`, `zone`, `omschr`, `tl`, `gl`, `stand_in_lijn`, `station`, `MBU_nr`, `WO_stap`, `LOG_stap`, `Q_stap`, `RA_stand`) VALUES ('$MBU','$zone','$omschr','$tl','$gl','$stand_in_lijn','$station','$MBU_nr','$WO_stap','$LOG_stap','$Q_stap','$RA_stand')";
$res = mysqli_query($con,$qry);
}
$count++;
}
}
if($res)
{
echo "Your file Uploaded Successfull";
}
else
{
echo "Your file Uploaded Failed";
}
// Close excel file
$reader->close();
}
else
{
echo "Please Choose only Excel file";
}
}
else
{
echo "File is Empty"."<br>";
echo "Please Choose Excel file";
}
?>
I have that message : Undefined variable: _SESSION in C:\xampp\htdocs\import-excel_08\index.php on line 29
You are including the upload file at the top of your main page file.
<?php include('import_excel.php') ?>
It doesn't need to be included as it does nothing on that page, your form submits to that file.
Remove it from the top of that page and the message should go away.

How to retrieve the comment IP

I need a code that displays the IP of the person/guest that commented on my website.
Here's the index page;
<?php
include "core/init.php";
?>
<!DOCTYPE html>
<link rel="stylesheet" type="text/css" href="http://hjalplista.comxa.com/daniel_emelie/style.Css">
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>Välkommen till hjälplistan!</title>
<body>
<div id="header">
<div align="right"><img src="http://i.imgur.com/y0aiNIt.jpg"></div>
</div>
<div id="inside">
<center>
<div id="location"><a href='index.php'>Hem</a> - <a href='administrative/adminonlyaccess.php'><i>Admin</i></a><br><br>
</div>
<hr/>
<br>
<div id="text">
<br>
<table border="1" cellpadding="1" cellspacing="1" style="width: 100%;">
<tbody>
<tr>
<td><span style="color:slategray;"><strong><center>Nr</center></strong></span></td>
<td><span style="color:slategray;"><strong><s><center>Fått hjälp</center></s></strong></span></td>
<td><span style="color:slategray;"><strong><center>Namn</center></strong></span></td>
<td><span style="color:slategray;"><strong><center>Uppgift</center></strong></span></td>
<td><span style="color:slategray;"><strong><center>IP-Adress</center></strong></span></td>
</tr>
<?php
include "core/inc/conn.php";
mysql_select_db("comments");
$getquery = mysql_query("SELECT * FROM comments ORDER BY id DESC");
while($rows = mysql_fetch_assoc($getquery))
{
$id = $rows['id'];
$comment_name = $rows['name'];
$comment = $rows['comment'];
echo"<tr><th><font color='lightgray'>$id</font></th>";
echo"<th><font color='red'>Fungerar ej!</font></th>";
echo "<th><u><font color='black'>$comment_name</font></u></th>";
echo"<th><font face='black'>$comment</font></th>";
echo"<th></th></tr>";
}
if(isset($_GET['error']))
{
echo "<p>15 Bokstäver max!";
}
?>
</table>
<br><br>
</body>
<head>
<center>
</div>
<br><br>
<form action="post_comment.php" method="post">
<label> Namn: <input type="text" name="name"></label><br><br>
<label> Uppgift: <input type="text" name="comment"></label><br><br>
<input type="submit" name="post" value="Skicka">
</form>
<br><br>
<br><br>
<?php
echo "<br><br><br>";
echo "<hr/>";
echo "<p> © Wieselgrenskolan. All rights reserved. </p>";
?>
</head>
</html>
<html>
<div align="right">
<!-- START OF HIT COUNTER CODE -->
<br><script language="JavaScript" src="http://www.counter160.com/js.js?img=11"></script><br><img src="http://www.counter160.com/images/11/left.png" alt="Free web hosting" border="0" align="textright"><img alt="Web hosting" src="http://www.counter160.com/images/11/right.png" border="0" align="texttop">
<!-- END OF HIT COUNTER CODE -->
</div>
</html>
And it's supposed to be in the echo "<th></th></tr>";. Do I need a MySQL table for that?
I've created a index in mysql called ''commentip'' but I don't know how to fix the missing parts.
You can get the IP in php in most cases using $_SERVER['REMOTE_ADDR'] However if they are using a proxy or you are using a reverse proxy like cloudflare or incapsula then you can use $_SERVER['HTTP_X_FORWARDED_FOR'].

How to print some specific part of a page via window.print()

i'm working on a form in php mysql. so in my page there is a form and below that i shown the data of that form in table format.now i want to print only the table structure thats why i just made a PRINT button as:
<span style="float:right;">PRINT</span>
but it will print the whole page with form field and table and i just want the tableto print.
Here is the design of my whole page with form and table:
<html>
<head></head>
<body>
<div class="container">
<form class="form-horizontal" action="" method="post" name="userform1" id="company-form" enctype="multipart/form-data">
<?php if($_GET[id]){?>
<fieldset>
<legend>Add Company</legend>
<div class="control-group">
<label class="control-label">Company Name</label>
<div class="controls">
<input type="text" name="company" id="company" value="<?php echo $selup['company']?>">
</div>
</div>
<div class="control-group">another field</div>
<div class="control-group">another field</div>
<div class="control-group">
<div class="controls">
<button type="submit" class="btn" name="submit" id="submit" value="Submit">Submit</button>
</div>
</div>
<table class="table table-bordered">
<tbody>
<tr>
<td>S.No.</td>
<td>Company Name</td>
<td>Type</td>
<td>Action</td>
</tr>
<?php
// to print the records
$select = "select * from company where type='Miscellaneous'";
$query1 = mysql_query($select);
while($value = mysql_fetch_array($query1)){ ?>
<tr>
<td><?php echo $value[id];?></td>
<td><?php echo $value[company ];?></td>
<td><?php echo $value[type];?></td>
<!--<td> </td>-->
<?php /*?><td><?php echo $value[amount];?></td>
<td><?php echo $value[date];?></td><?php */?>
<td><i class="icon-edit"></i>
<i class="icon-trash"></i></td>
</tr><?php }?>
</tbody>
</table>
</fieldset>
<form>
</div>
</body>
so i just want to print the table not whole page.
Use css to hide elements you don't want to print:
#media print {
.control-group {
display: none;
}
}
function printContent(el){
var restorepage = document.body.innerHTML;
var printcontent = document.getElementById(el).innerHTML;
document.body.innerHTML = printcontent;
window.print();
document.body.innerHTML = restorepage;
}
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1>My page</h1>
<div id="div1">DIV 1 content...</div>
<button onclick="printContent('div1')">Print Content</button>
<div id="div2">DIV 2 content...</div>
<button onclick="printContent('div2')">Print Content</button>
<p id="p1">Paragraph 1 content...</p>
<button onclick="printContent('p1')">Print Content</button>
</body>
</html>
You could make a print-css (which does the same as #media print, but I think it is cleaner, and you can disable the css include via javascript, if you need it):
<link rel="stylesheet" type="text/css" href="print.css" media="print" />
In that css, you hide all elements which should not get printed, for example:
.wrapper, .header {display: none;}
One posible solution, perhaps not the best option:
1. Open a new window with JS
2. Copy the whole table into the new window (with jQuery for example)
3. Print the new window
4. Close the window
Sure it has a blink effect but It will work.

HTML Formular is redirecting wrong!

So, my formular is redirecting to the wrong site!
Look at my example:
ATM I've got the internet address:
http://localhost/myworkspace/mywebsite/index.php
It's hosted on a localhost-xampp server. It's homepage is:
http://localhost/xampp/
Ok ... Now I tried several things to get into the file where the script is that is working with the data of the formular:
<form action="index.php">
-> I'm getting redirected to the Xampp Homepage
<form action="index.php?mod=home">
-> I'm getting redirected to the Xampp Homepage
<form action="myworkspace/mywebsite/index.php">
-> I'm getting redirected on "http://localhost/myworkspace/mywebsite/myworkspace/mywebsite/index.php"
(the arrows express what happens when clicking on "send")
Why is this happening? As seen in the examples, the browser is not moving outside the myworkspace/mywebsite-folders. But still, it loads the index.php which is located in localhost/xampp (it's localhost/index.php). If you see my original link of the website, there actually is an index.php file in "myworkspace/mywebsite".
Here's some code of me:
the addguestbook.php, which is included into the index.php (see below)
<?php
//******************************************************//
//********************Database stuff********************//
//******************************************************//
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="mywebsite"; // Database name
//********************Tables***************************//
$tbl_name="guestbook"; // Guestbook
echo $hostname.$path.$get;
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
$name = $_POST['name'];
$email = $_POST['email'];
$website = $_POST['website'];
$comment = $_POST['comment'];
$datetime = date("l, jS M Y, g:i a"); //date time
// Connect to server and select database.
mysql_connect($host, $username, $password)or die("cannot connect server: ".mysql_error());
mysql_select_db($db_name)or die("cannot select DB: ".mysql_error());
$sql="INSERT INTO ".$tbl_name."(id, name, email, website, comment, datetime)VALUES('".$post_id."', '".$name."', '".$email."', '".$website."', '".$comment."', '".$datetime."')";
$result=mysql_query($sql);
mysql_close();
} else
?>
<form method="post" action="myworkspace/mywebsite/index.php">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="guestbookFormCell" colspan='2'><input
class="guestbookInputFieldText" name="name" type="text"
value="Name *" size="40" maxlength="30" /></td>
</tr>
<tr>
<td class="guestbookFormCell" colspan='2'><input
class="guestbookInputFieldText" name="email" type="text"
value="E-Mail (won't become displayed)" size="40" maxlength="40" />
</td>
</tr>
<tr>
<td class="guestbookFormCell" colspan='2'><input
class="guestbookInputFieldText" name="website" type="text"
value="Website" size="40" maxlength="50" /></td>
</tr>
<tr>
<td class="guestbookFormCell" colspan='2'><textarea
class="guestbookInputFieldText" name="comment" cols="37" rows="5">Comment *</textarea>
</td>
</tr>
<!--
<tr>
<td>CAPTCHA</td>
</tr>
-->
<tr>
<td><button class="guestbookFormCell guestbookButton" type="submit"
name="submit">
<span class='guestbookButtonText'>Send</span>
</button></td>
<td><button class="guestbookFormCell guestbookButton" style="float:right;"type="reset"
name="reset">
<span class='guestbookButtonText'>Reset</span>
</button></td>
</tr>
</table>
</form>
and the index.php (it's pretty big. most of it is just a design-structure, so ignore the html stuff. it's just divs and tables.
<html>
<head>
<title>JustBasti's website</title>
<script type="text/javascript" src="lightbox/js/prototype.js"></script>
<script type="text/javascript"
src="lightbox/js/scriptaculous.js?load=effects,builder"></script>
<script type="text/javascript" src="lightbox/js/lightbox.js"></script>
<link rel="stylesheet" href="lightbox/css/lightbox.css" type="text/css"
media="screen" />
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<?php
session_start();
// Path-parameters for link-building
$hostname = $_SERVER['HTTP_HOST'];
$path = $_SERVER['PHP_SELF'];
$_SESSION['basepath'] = dirname($_SERVER['PHP_SELF']);
?>
<div id='top'>
<div id='header'>
<div id='headerText' class='lightText text bigText'>
<div>
Hello, My name is <font class='blueText'>Sebastian Fast</font>
</div>
<div>
I just finished my <font class='blueText'>education in IT</font>
</div>
<div>
and am now <font class='blueText'>aiming to</font>
</div>
<div>
experience the <font class='blueText'>most wonderful places</font>
</div>
<div>
around <font class='blueText'>the world</font>
</div>
<div>
Read more about myself <font class='blueText'>here</font>
</div>
</div>
<div id='headerLineBox'>
<div class='lineTopDiv'>
<div id='headerTopLine' class='lineTopEnd'></div>
</div>
<div class='verticalLine'>
<div id='headerLine' class='line'></div>
</div>
<div class='lineBottomDiv'>
<div class='lineBottomEnd'></div>
</div>
</div>
<div id='headerNavigation' class='lightText text bigText'>
<div>
<a href='index.php?mod=home' class='lightLink'>Home</a>
</div>
<div>
<a href='index.php?mod=news' class='lightLink'>News</a>
</div>
<div>
<a href='index.php?mod=countries' class='lightLink'>Countries</a>
</div>
<div>
<a href='index.php?mod=gallery' class='lightLink'>Gallery</a>
</div>
</div>
</div>
</div>
<div id='middle'>
<div id='content'>
<table>
<!-- CONTENT -->
<?
// Paths
echo " <a href='index.php?mod=home'>Home</a>
<a href='index.php?mod=news'>News</a>
<a href='index.php?mod=allnews'>All News</a>
<a href='index.php?mod=countries'>Countries</a>
<a href='index.php?mod=gallery'>Gallery</a>
<a href='index.php?mod=guestbook'>Guestbook</a>
<a href='index.php?mod=admin'>Administrator</a>";
if (!isset($_SESSION['angemeldet']) || !$_SESSION['angemeldet']) {
include('login/login.php');
}
// Check which link got clicked & import data
if (!$_GET){
include('data/home.php');
} elseif (isset($_GET['mod']) && !isset($_GET['post']) && !isset($_GET['album']) && !isset($_GET['country'])){
Switch($_GET['mod']){
case 'home':
include('data/home.php');
exit;
case 'news':
include('data/latestPosts.php');
exit;
case 'allnews':
include('data/allPosts.php');
exit;
case 'countries':
include('data/viewCountries.php');
exit;
case 'gallery':
include('data/gallery.php');
exit;
case 'admin':
include('admin/admin.php');
exit;
}
} elseif (isset($_GET['mod']) && isset($_GET['post'])){
$get = "?mod=".$_GET['mod']."&post=".$_GET['post'];
$post_id = $_GET['post'];
include('data/viewPost.php');
include('data/guestbook.php');
} elseif (isset($_GET['mod']) && isset($_GET['album'])){
$get = "?mod=".$_GET['mod']."&album=".$_GET['album'];
$post_id = $_GET['album'];
include('data/viewAlbum.php');
include('data/guestbook.php');
} elseif (isset($_GET['mod']) && isset($_GET['country'])){
$country = $_GET['country'];
include('data/viewCountry.php');
}
?>
</table>
</div>
</div>
<div id='graphicDIV'>
<div id='graphic'></div>
</div>
<div id='bottom'>
<div id='guestbook'>
<table border='0' cellspacing='0' cellpadding='0'>
<tr>
<td id='guestbookHeadline1'><font class='lightText bigText text'>Allgemeines Gästebuch</font>
</td>
<td id='guestbookTopLine' class='lineTopEnd'></td>
<td id='guestbookHeadline2'><font class='lightText bigText text'>Schreibe selbst</font>
</td>
</tr>
<tr id='guestbook2'>
<?
$post_id = 000000000000;
$get = "?mod=home";
?>
<td id='guestbookComment'>
<? include('data/viewguestbook.php'); ?>
</td>
<td id='guestbookLine'></td>
<td id='guestbookFormular'>
<? include('data/addguestbook.php'); ?>
</td>
</tr>
</table>
</div>
<div id='footerLeftLine' class='lineLeftEnd'>
<!-- LineLeftEnd -->
</div>
<div id='footerLine' class='horizontalLine'>
<!-- Line -->
</div>
<div id='footerRightLine' class='lineRightEnd'>
<!-- LineRightEnd -->
</div>
<div id='footer'>
<div class='footerLink'>
<!-- AdministratorLink -->
</div>
<div class='footerLink'>
<!-- ImpressumLink -->
</div>
<div class='footerLink'>
<!-- NewsArchiveLink -->
</div>
</div>
</div>
</body>
</head>
</html>
Thanks for help!
<form action="myworkspace/mywebsite/index.php">
should be
<form action="/myworkspace/mywebsite/index.php">
What you currently have is a path relative to your current page. The path that I have given is relative to your document root, which is http://localhost.
See also:
Absolute and Relative Paths, from About.com
Path (computing), from Wikipedia

Categories