Keep Line Break on Textarea and MySQL - php

I coded some Form to send Text to MySql. One of my Problem is to keep the line break. Found some Code over Google but i don't have any idea how i could use it. Some tries was not really successful.
The Code i found is that below which i don't know how to set up.
function my_nl2br($string){
$string = str_replace("\n", "<br />", $string);
if(preg_match_all('/\<pre\>(.*?)\<\/pre\>/', $string, $match)){
foreach($match as $a){
foreach($a as $b){
$string = str_replace('<pre>'.$b.'</pre>', "<pre>".str_replace("<br />", "", $b)."</pre>", $string);
}
}
}
return $string;
}
Another code i found is this but if i try to read it from database the line break will not work.
if (isset($_POST['submit']))
{
$text = trim($_POST['text']);
$text = stripslashes($text);
$text = htmlspecialchars($text);
echo 'you entered:<br><br>' . nl2br($text);
}
This is my Code where i want to implant it.
if(isset($_POST['title']))
{
$title = mysql_real_escape_string(htmlspecialchars($_POST['title']));
$description = mysql_real_escape_string(htmlspecialchars($_POST['description']));
$applepart = mysql_real_escape_string(htmlspecialchars($_POST['applepart']));
$partnumber = mysql_real_escape_string(htmlspecialchars($_POST['partnumber']));
$productcode = mysql_real_escape_string(htmlspecialchars($_POST['productcode']));
$compatibility = mysql_real_escape_string(htmlspecialchars($_POST['compatibility']));
$url_bild = mysql_real_escape_string(htmlspecialchars($_POST['url_bild']));
$price = mysql_real_escape_string(htmlspecialchars($_POST['price']));
$insert = mysql_query("INSERT INTO `adressbuch` (`title`,`description`,`applepart`,`partnumber`,`productcode`,`compatibility`,`url_bild`,`price`) VALUES ('$title','$description','$applepart','$partnumber','$productcode','$compatibility','$url_bild','$price')");
if (!$insert)
{
die('Eintrag konnte nicht gespeichert werden: ' . mysql_error());
}
}
?>
<form method="POST" action="?page= ">
<span>Neuer Eintrag:</span> <br />
<span>Title</span><input type="text" name="title" /> <br />
<span>Description</span><textarea cols="16" rows="5" name="description"></textarea> <br />
<span>Apple Part</span><input type="text" name="applepart" /> <br />
<span>Part Number</span><input type="text" name="partnumber" /> <br />
<span>Product Code</span><input type="text" name="productcode" /> <br />
<span>Compatibility</span><input type="text" name="compatibility" /> <br />
<span>Image</span><input type="text" name="url_bild" /> <br />
<span>Price</span><input type="text" name="price" /> <br />
<input type="submit" value="Speichern"/> <br />
</form>
cheers guys

To store title in the database, try:
$title = real_escape_string(nl2br(htmlspecialchars($_POST['title'])));

Related

Extract emails from a list of url

I have a list of urls that I want to extract the email or from the href or from the text. Each page has one email only.
The problem is that my list is big and can not do it manually.
EMAIL
How can I do this using PHP, regex?
/mailto:([a-zA-Z0-9_\.-]+#[\da-z\.-]+\.[a-z\.]{2,6})"/gm
see this demo https://regex101.com/r/mC7jM3/1
Extract email from url contain
<?php
$the_url = isset($_REQUEST['url']) ? htmlspecialchars($_REQUEST['url']) : '';
if (isset($_REQUEST['url']) && !empty($_REQUEST['url'])) {
$text = file_get_contents($_REQUEST['url']);
}
elseif (isset($_REQUEST['text']) && !empty($_REQUEST['text'])) {
$text = $_REQUEST['text'];
}
if (!empty($text)) {
$res = preg_match_all(
"/[a-z0-9]+([_\\.-][a-z0-9]+)*#([a-z0-9]+([\.-][a-z0-9]+)*)+\\.[a-z]{2,}/i", $text, $matches
);
if ($res) {
foreach (array_unique($matches[0]) as $email) {
echo $email . "<br />";
}
}
else {
echo "No emails found.";
}
}
?>
<form method="post" action="">
Please enter full URL of the page to parse (including http://):<br />
<input type="text" name="url" size="65" value="<?php echo $the_url; ?>"/><br />
<input type="submit" name="submit" value="Submit" />
</form>

Notice: Undefined index variable. PHP script works on Linux but not Windows

I have a PHP script that works on Linux but not on Windows.
I can accept that my PHP coding isn't that great, I'm a newbie.
I have a form, and I post the data to it. Now that it is on a Windows server, I get:
Notice: Undefined index: nmr in C:\Apache24\htdocs\index.php on line 31
...
and so on.
I tried declaring all the variables as 0, and using isset, but it doesn't seem to work.
Perhaps I'm using isset wrong. Can someone help me?
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link rel="shortcut icon" href="http://www.hackmaine.org/favicon.ico">
<link rel="stylesheet" type="text/css" href="sty.css">
<title>NMR Scheduler</title>
</head>
<body>
<?PHP
$Unity = 'unchecked';
$Inova = 'unchecked';
$Experiment = $duration = $ToD = $startTime = $ddate = $nmr = $UName = 0;
if (isset($_POST['Submit1']))
{
$selected_radio = $_POST['nmr'];
switch ($selected_radio)
{
case Unity:
break;
case Inova:
break;
default:
echo "Select an NMR";
}
}
isset($Experiment, $duration, $ToD, $startTime, $ddate, $UName);
$reg_wvar=$_POST['nmr'];
$reg_UName=$_POST['UName'];
$reg_Date=$_POST['ddate'];
$reg_startTime=$_POST['startTime'];
$reg_ToD=$_POST['ToD'];
$reg_duration=$_POST['duration'];
$reg_Experiment=$_POST['Experiment'];
$stringy = "$reg_wvar, $reg_UName, $reg_Date, $reg_startTime $reg_ToD, $reg_duration, $reg_Experiment \n";
echo $stringy;
$filename = 'newEntry.txt';
// Let's make sure the file exists and is writeable first.
if (is_writable($filename)) {
if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file ($filename)";
exit;
}
// Write $somecontent to our opened file.
if (fwrite($handle, $stringy) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
//echo "Success, wrote ($somecontent) to file ($filename)";
fclose($handle);
} else {
echo "Data not written, Make Sure you selected an NMR";
}
?>
<center>
<FORM ACTION="if.php" method="post">
<h2>NMR Usage Scheduler</h2>
<br /><br />
<INPUT TYPE = 'Radio' Name ='nmr' value= 'Unity'>Unity
<INPUT TYPE = 'Radio' Name ='nmr' value= 'Inova' >Inova<br /><br />
<B>Your Name :</B><input type="text" size="20" maxlength="10" name="UName" required><br /><br />
<B>Enter Date (mm/dd):</B> <input type="text" size="20" maxlength="5" name="ddate" required><br /><br />
<B>Start Time (hh:mm):</B> <input type="text" size="8" maxlength="5" name="startTime" required>
<INPUT TYPE = 'Radio' Name ='ToD' value= 'AM' >AM
<INPUT TYPE = 'Radio' Name ='ToD' value= 'PM' checked>PM
<br /><br />
<B>Duration: </B> <input type="text" size="20" maxlength="5" name="duration" required><br /><br />
<B>Experiment:</B> <input type="text" size="20" maxlength="5" name="Experiment" required><br /><br />
<INPUT TYPE = "Submit" Name = "Submit1" VALUE = "Submit">
</FORM>
</center>
</body>
</html>
if(isset($_POST['nmr'], $_POST['UName'], ...) {
$reg_wvar=$_POST['nmr'];
$reg_UName=$_POST['UName'];
...
}

I am trying to save data from a form app to a cookie using PHP

So, I am creating a HTML 5 game and to create saves I want to store the save data in cookies. In trying to understand how this works I created a form app:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form action="cookieset.php" method="post">
<p> Astate <input type="text" name="astate" size="10px" /></p>
<p> Wstate <input type="text" name="wstate" size="10px" /></p>
<p> Cstate <input type="text" name="cstate" size="10px" /></p>
<p> Gstate <input type="text" name="gstate" size="10px" /></p>
<p> G2state <input type="text" name="g2state" size="10px" /></p>
<p> G3state <input type="text" name="g3state" size="10px" /></p>
<p> AKCstate <input type="text" name="akcstate" size="10px" /></p>
<p> TKCstate <input type="text" name="tkcstate" size="10px" /></p>
<p> FKCstate <input type="text" name="fkcstate" size="10px" /></p>
<input type="submit" name="submit" value="Submit" />
</form>
<form action="retreive.php" method="get">
<input type="submit" name="retreive" value="Retreive" />
</form>
</body>
</html
also, please forgive my noobness as I am sure it is just a stupid mistake or my lack of basic understanding of something, here is cookie set.php, the error handeling is working, I am just getting null for every value insted of the value I put into the form app:
<?php
$_POST['$astate'];
$_POST['$wstate'];
$_POST['$cstate'];
$_POST['$gstate'];
$_POST['$g2state'];
$_POST['$g3state'];
$_POST['$akcstate'];
$_POST['$tkcstate'];
$_POST['$fkcstate'];
setcookie("rqs1", $astate);
setcookie("rqs2", $wstate);
setcookie("rqs3", $cstate);
setcookie("rqs4", $gstate);
setcookie("rqs5", $g2state);
setcookie("rqs6", $g3state);
setcookie("rqs7", $akcstate);
setcookie("rqs8", $tkcstate);
setcookie("rqs9", $fkcstate);
if(isset($_COOKIE['rqs1'])){
echo "$name : $value <br />\n";
}
elseif(!(isset($_COOKIE['rqs1']))){
echo "null \n";
}
if(isset($_COOKIE['rqs2'])){
echo "$name : $value <br />\n";
}
elseif(!(isset($_COOKIE['rqs2']))){
echo "null \n";
}
if(isset($_COOKIE['rqs3'])){
echo "$name : $value <br />\n";
}
elseif(!(isset($_COOKIE['rqs3']))){
echo "null \n";
}
if(isset($_COOKIE['rqs4'])){
echo "$name : $value <br />\n";
}
elseif(!(isset($_COOKIE['rqs4']))){
echo "null \n";
}
if(isset($_COOKIE['rqs5'])){
echo "$name : $value <br />\n";
}
elseif(!(isset($_COOKIE['rqs5']))){
echo "null \n";
}
if(isset($_COOKIE['rqs6'])){
echo "$name : $value <br />\n";
}
elseif(!(isset($_COOKIE['rqs6']))){
echo "null \n";
}
if(isset($_COOKIE['rqs7'])){
echo "$name : $value <br />\n";
}
elseif(!(isset($_COOKIE['rqs7']))){
echo "null \n";
}
if(isset($_COOKIE['rqs8'])){
echo "$name : $value <br />\n";
}
elseif(!(isset($_COOKIE['rqs8']))){
echo "null \n";
}
if(isset($_COOKIE['rqs9'])){
echo "$name : $value <br />\n";
}
elseif(!(isset($_COOKIE['rqs9']))){
echo "null \n";
}
?>
I think you have a problem in get data
$_POST['$astate']; is needed like $_POST['astate']; no need a $ sing in post field name.
for set cookie below is best example
$astate = $_POST['astate'];
<?php
$expire=time()+60*60*24*30;
setcookie("astate", $astate, $expire);
?>
Try like this and if you have problem than inform me
Assign post variables to variables than use them.
it will work
<?php
$astate = $_POST['astate'];
$wstate = $_POST['wstate'];
$cstate = $_POST['cstate'];
$gstate = $_POST['gstate'];
$g2state = $_POST['g2state'];
$g3state = $_POST['g3state'];
$akcstate = $_POST['akcstate'];
$tkcstate = $_POST['tkcstate'];
$fkcstate = $_POST['fkcstate'];
?>
HTML
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form action="cookieset.php" method="post">
<p> Astate <input type="text" name="state[a]" size="10px" /></p>
<p> Wstate <input type="text" name="state[w]" size="10px" /></p>
<p> Cstate <input type="text" name="state[c]" size="10px" /></p>
<p> Gstate <input type="text" name="state[g]" size="10px" /></p>
<p> G2state <input type="text" name="state[g2]" size="10px" /></p>
<p> G3state <input type="text" name="state[g3]" size="10px" /></p>
<p> AKCstate <input type="text" name="state[akc]" size="10px" /></p>
<p> TKCstate <input type="text" name="state[tkc]" size="10px" /></p>
<p> FKCstate <input type="text" name="state[fkc]" size="10px" /></p>
<input type="submit" name="submit" value="Submit" />
</form>
<form action="retreive.php" method="get">
<input type="submit" name="retreive" value="Retreive" />
</form>
</body>
</html>
PHP
<?php
$state = $_POST['state'];
$x = 1;
foreach($state as $name => $value) {
setcookie("rqs".$x, $value);
print $name."state : ".$value." <br>";
$x++;
}
?>
(btw you don't need the second if condition in the else statement because its just the opposite of your first if condition)
I assume the game logic is in Javascript? You can set cookies from javascript, you can also use localstore which would be a better option for large data.
I think you need to change this:
$_POST['$astate'];
$_POST['$wstate'];
$_POST['$cstate'];
$_POST['$gstate'];
$_POST['$g2state'];
$_POST['$g3state'];
$_POST['$akcstate'];
$_POST['$tkcstate'];
$_POST['$fkcstate'];
to this:
$astate=$_POST['astate'];
$wstate=$_POST['wstate'];
$cstate=$_POST['cstate'];
$gstate=$_POST['gstate'];
$g2state=$_POST['g2state'];
$g3state=$_POST['g3state'];
$akcstate=$_POST['akcstate'];
$tkcstate=$_POST['tkcstate'];
$fkcstate=$_POST['fkcstate'];
just changed your code a little :\
<?php
// `$_POST['$some_var']` doesnt create and assign a value to variable `$some_var`,
// Its only check key `$some_var` exists in `$_POST` array and its if exists return its value
// so doing it is WRONG
$params = array( 'astate', 'wstate', 'cstate', 'gstate', 'g2state', 'g3state', 'akcstate', 'tkcstate', 'fkcstate' );
foreach( $params as $param ) {
$cookie = ( isset( $_POST[$param] ) ) ? trim( $_POST[$param] ) : null;
$expire = ( time() + 3600 * 24 * 365 );
if ( $cookie ) {
// everything seems to be fine, now set the cookie
setcookie( $param, $cookie, $expire, "/" );
}
}
// now check here
if ( isset( $_COOKIE["astate"] ) ) {
// yes
}
else {
// no
}
// OR
foreach( $params as $param ) {
if ( isset( $_COOKIE[$param] ) ) {
echo $param." : ".$_COOKIE[$param]." <br />";
}
}
?>
Looking at your setcookie.php, you are receiving the submitted variables in the in the wrong way. To receive a variable submitted via post, you use $variable=$_POST['formVariable'];
You are also setting the cookie in the wrong way. To set a cookie, you use setcookie($cookiename, $cookievalue, $timetoexpire);.
Your setcookie.php should therefore look like this
<?php
$astate=$_POST['astate'];
$wstate=$_POST['wstate'];
$cstate=$_POST['cstate'];
$gstate=$_POST['gstate'];
$g2state=$_POST['g2state'];
$g3state=$_POST['g3state'];
$akcstate=$_POST['akcstate'];
$tkcstate=$_POST['tkcstate'];
$fkcstate=$_POST['fkcstate'];
//Expire after 1 Hour for example
$timetoexpire=time()+60*60;
//set cookies
setcookie("rqs1", $astate,$timetoexpire);
setcookie("rqs2", $wstate,$timetoexpire);
setcookie("rqs3", $cstate,$timetoexpire);
setcookie("rqs4", $gstate,$timetoexpire);
setcookie("rqs5", $g2state,$timetoexpire);
setcookie("rqs6", $g3state,$timetoexpire);
setcookie("rqs7", $akcstate,$timetoexpire);
setcookie("rqs8", $tkcstate,$timetoexpire);
setcookie("rqs9", $fkcstate,$timetoexpire);
if(isset($_COOKIE['rqs1'])){
echo "$name : ".$_COOKIE['rqs1']." <br />\n";
}
elseif(!(isset($_COOKIE['rqs1']))){
echo "null \n";
}
if(isset($_COOKIE['rqs2'])){
echo "$name : ".$_COOKIE['rqs2']." <br />\n";
}
elseif(!(isset($_COOKIE['rqs2']))){
echo "null \n";
}
if(isset($_COOKIE['rqs3'])){
echo "$name : ".$_COOKIE['rqs3']." <br />\n";
}
elseif(!(isset($_COOKIE['rqs3']))){
echo "null \n";
}
if(isset($_COOKIE['rqs4'])){
echo "$name : ".$_COOKIE['rqs4']." <br />\n";
}
elseif(!(isset($_COOKIE['rqs4']))){
echo "null \n";
}
if(isset($_COOKIE['rqs5'])){
echo "$name : ".$_COOKIE['rqs5']." <br />\n";
}
elseif(!(isset($_COOKIE['rqs5']))){
echo "null \n";
}
if(isset($_COOKIE['rqs6'])){
echo "$name : ".$_COOKIE['rqs6']." <br />\n";
}
elseif(!(isset($_COOKIE['rqs6']))){
echo "null \n";
}
if(isset($_COOKIE['rqs7'])){
echo "$name : ".$_COOKIE['rqs7']." <br />\n";
}
elseif(!(isset($_COOKIE['rqs7']))){
echo "null \n";
}
if(isset($_COOKIE['rqs8'])){
echo "$name : ".$_COOKIE['rqs8']." <br />\n";
}
elseif(!(isset($_COOKIE['rqs8']))){
echo "null \n";
}
if(isset($_COOKIE['rqs9'])){
echo "$name : ".$_COOKIE['rqs9']." <br />\n";
}
elseif(!(isset($_COOKIE['rqs9']))){
echo "null \n";
}
?>

MySQL Syntax Error at long entered text

I am trying to build a PHP Form with MySQL. The problem is that I get an error every time if I try to add some long Text into the field.
The error
You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near.....at line 1
The PHP code generating the query is this:
<?php
if ( $_GET['aktion'] == "speichern" )
{
$title = $_GET['title'];
$description = $_GET['description'];
$applepart = $_GET['applepart'];
$partnumber = $_GET['partnumber'];
$productcode = $_GET['productcode'];
$compatibility = $_GET['compatibility'];
$url_bild = $_GET['url_bild'];
$price = $_GET['price'];
$sql = "INSERT INTO adressbuch ";
$sql .= " SET ";
$sql .= " title = '$title', ";
$sql .= " description = '$description', ";
$sql .= " applepart = '$applepart', ";
$sql .= " partnumber = '$partnumber', ";
$sql .= " productcode = '$productcode', ";
$sql .= " compatibility = '$compatibility', ";
$sql .= " url_bild = '$url_bild', ";
$sql .= " price = '$price' ";
require_once ('konfiguration.php');
$db_erg = mysql_query($sql)
or die("Anfrage fehlgeschlagen: " . mysql_error());
echo '<h1>Adresse wurde speichert</h1>';
echo 'Auflistung anzeigen';
exit;
}
?>
<form name="" action="" method="GET" enctype="text/html">
<p>Title:<br />
<input type="text" name="title" value="" size="60" />
</p>
<p>description:<br />
<input type="text" name="description" value="" size="60" />
</p>
<p>applepart:<br />
<input type="text" name="applepart" value="" size="60" />
</p>
<p>partnumber:<br />
<input type="text" name="partnumber" value="" size="60" />
</p>
<p>productcode:<br />
<input type="text" name="productcode" value="" size="60" />
</p>
<p>compatibility:<br />
<input type="text" name="compatibility" value="" size="60" />
</p>
<p>Bild:<br />
<input type="text" name="url_bild" value="" size="60" />
</p>
<p>price:<br />
<input type="text" name="price" value="" size="60" />
</p>
<input type="hidden" name="aktion" value="speichern" />
<input type="Submit" name="" value="speichern" />
</form>
Thanks for your help
Your code is susceptible to SQL injection, and your problem is only a hint as to why.
The rule we always use is: "Never trust data from the user-agent" (i.e. consider anything in $_GET or $_POST as potentially problematic or worse). At a minimum, we should always escape these values using mysqli_real_escape_string or else a more robust DB framework.
Your problem is that when you have long enough input, it has a single quote in it somewhere, or a newline. You can't simply concatenate user input like this and expect it to work. Worse, you are wide-open for SQL injection attacks. Find the right way to use your framework to build SQL queries.
Regardless of the SQL injection vulnerability, it seems like you are sending a query which is too long for MySQL to handle.
You can try to overcome this by changing some configuration: try and raise the parameter "max_allowed_packet" in your MySQL's configuration file. For example:
[mysqld]
max_allowed_packet = 64M
This will set it to 64MB, which means the longest single query you will be allowed to issue is 64MB, and the longest single row you will be able to retriever from a query is 64MB in size.
<?php
require_once ('konfiguration.php');
if(isset($_POST['title']))
{
$title = mysql_real_escape_string(htmlspecialchars($_POST['title']));
$description = mysql_real_escape_string(htmlspecialchars($_POST['description']));
$applepart = mysql_real_escape_string(htmlspecialchars($_POST['applepart']));
$partnumber = mysql_real_escape_string(htmlspecialchars($_POST['partnumber']));
$productcode = mysql_real_escape_string(htmlspecialchars($_POST['productcode']));
$compatibility = mysql_real_escape_string(htmlspecialchars($_POST['compatibility']));
$url_bild = mysql_real_escape_string(htmlspecialchars($_POST['url_bild']));
$price = mysql_real_escape_string(htmlspecialchars($_POST['price']));
$insert = mysql_query("INSERT INTO `adressbuch` (`title`,`description`,`applepart`,`partnumber`,`productcode`,`compatibility`,`url_bild`,`price`) VALUES ('$title','$description','$applepart','$partnumber','$productcode','$compatibility','$url_bild','$price')");
if (!$insert)
{
die('Eintrag konnte nicht gespeichert werden: ' . mysql_error());
}
}
?>
<form method="POST" action="?page= ">
<span>Neuer Gästebucheintrag verfassen:</span> <br />
<span>Title</span><input type="text" name="title" /> <br />
<span>Description</span><textarea cols="16" rows="5" name="description"></textarea> <br />
<span>Apple Part</span><input type="text" name="applepart" /> <br />
<span>Part Number</span><input type="text" name="partnumber" /> <br />
<span>Product Code</span><input type="text" name="productcode" /> <br />
<span>Compatibility</span><input type="text" name="compatibility" /> <br />
<span>Image</span><input type="text" name="url_bild" /> <br />
<span>Price</span><input type="text" name="price" /> <br />
<input type="submit" value="Speichern"/> <br />
</form>

How to add action tag to form?

I have a working php guestbook script. It's only 1 file. I tried to validate it and there is only one error:
Line 147, Column 36: required attribute "action" not specified
<form method="post" name="blogform">
Now the code is this and I'm sure I would need to break up the file to two so that I can create a file for the action tag but I just don't know how. Any help is much appreciated.
<?php
session_start();
include("../../4a/inc/opendb.inc.php");
if(isset($_POST['send'])) //checks if $_POST variable "is set"
if(isset($_SESSION["ellenorzo"]) && !empty($_SESSION["ellenorzo"]) && $_SESSION["ellenorzo"]==$_POST["code"]){
$name = trim($_POST['name']); //eliminating whitespaces
$email = trim($_POST['email']);
$message = addslashes( trim($_POST['message']));
$query = "INSERT INTO blog (name, email, message, date) " .
"VALUES ('$name', '$email', '$message', NOW())";
mysql_query($query) or die('Hey, something is wrong!' . mysql_error());
header('Location: ' . $_SERVER['REQUEST_URI']);
exit;
}
?>
<?php
include('../../4a/inc/head.inc.php');
?>
<body style="color: #ffffff;">
<div class="mainblog">
<div class="top">
<div class="menu">
<?php
include('../menu.inc.php');
?>
</div>
</div>
<div class="middleblog">
<form method="post" name="blogform">
<input name="name" id="name" class="nameblog" type="text" />
<img src="../../4a/img/main/name.jpg" class="name" alt="Name" />
<input name="email" id="email" class="emailblog" type="text" />
<img src="../../4a/img/main/email.jpg" class="email" alt="Email" />
<textarea name="message" id="message" class="messageblog" rows="6" cols="6" onkeyup="return ismaxlength(this)">
</textarea>
<img src="../../4a/img/main/message.jpg" class="message" alt="Message" />
<input name="send" value="submit" id="send" class="sendblog" type="image" src="../../4a/img/main/send.jpg" onclick="return checkform();" />
<input type="hidden" name="send" value="submit" />
<div class="text_check_code">
<font class="text">
Enter the characters as they are shown below.
</font>
</div>
<img src="../../4a/inc/secure.inc.php" class="img_check_code" alt="Nospam" />
<input name="code" class="input_check_code" />
</form>
<?php
$rowsperpage = 10;
$pagenumber = 1;
if(isset($_GET['page']))
{
$pagenumber = $_GET['page'];
}
$offset = ($pagenumber - 1) * $rowsperpage;
$query = "SELECT id, name, email, message, date ".
"FROM blog ".
"ORDER BY id DESC ".
"LIMIT $offset, $rowsperpage";
$result = mysql_query($query) or die('Hey, something is wrong!. ' . mysql_error());
if(mysql_num_rows($result) == 0)
{
print("<br /><br /><br /><br /><br /><br /><br /><br />The blog is empty.");
}
else
{
while($row = mysql_fetch_array($result))
{
list($id, $name, $email, $message, $date) = $row;
$name = htmlspecialchars($name);
$email = htmlspecialchars($email);
$message = htmlspecialchars($message);
$message = stripslashes(nl2br($message)); //real breaks as user hits enter
?>
<br />
<div class="blogentries">
<b><?=$name?></b>
<br />
<?=$message?>
<br />
<i><?=$date?></i>
</div>
<br />
<?php
} //closing while statement
$query = "SELECT COUNT(id) AS numrows FROM blog";
$result = mysql_query($query) or die('Hey, something is wrong!. ' . mysql_error());
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['numrows'];
$maxpage = ceil($numrows/$rowsperpage); //rounding up any integer eg. 4,1=5
$nextlink = '';
if($maxpage > 1)
{
$self = $_SERVER['PHP_SELF'];
$nextlink = array();
for($page = 1; $page <= $maxpage; $page++)
{
$nextlink[] = "$page";
}
$nextlink = "Next: " . implode(' » ', $nextlink); //returns all elements of an array as a string
}
include ("../../4a/inc/closedb.inc.php");
?>
<br />
<div class="nextlink">
<?=$nextlink;?>
</div>
</div>
<br />
<br />
<div class="bottomblog">
<?php
require_once('../../4a/inc/copyright.inc.php');
?>
</div>
<br />
<br />
</div>
<?php //closing the else statement
}
?>
<?php
include('../../4a/inc/footer.inc.php');
?>
The action property specifies the link the form is sent to. If the form calls itself you can leave it blank:
<form action="" method="post" name="blogform">
The action tag tells the form where to submit the data. If it is left blank, it will attempt to submit the data to the current php page. If it's giving you trouble, perhaps you need to specify it and point it to the php page that generates the form.
In the code you provided, the bit of code which handles new inserts is at the top of this page, so you should set the action tag to be the name of the page.
By the way, you should ensure that your inputs are all cleaned; just using trim() before inserting them is asking for trouble. See here for more on this topic.

Categories