0

hi all!
i'm new with php and i have problem. I have a submit form in which every user places code.when they submit it in database its displayed normally there, but when i try to view the data in php there are missing elements , as b<<c or <iostream> etc. is it possible to configure it so it will accept <br> tags as line brakes, and the other code to display as text?

example of the error :

code entered in database or thru form(in database im using varchar):

#include<iostream.h>
int main()
{ 
int year;
cout<<"year=";
cin>>year;
if(!(year%4)&&(year%100)||!(year%400))
cout<<"error1"; else cout< <"error2";
return 0;
}

code received in php:

#include 
int main() 
{ 
int year; 
cout<
cin>>year; 
if(!(year%4)&&(year%100)||!(year%400)) 
cout<<
return 0; 
} 
)

php files im using:

submit.php

<form method="post" action="insert.php">
    <p><br>
      <b>code:</b><br>
      <input type="Text" name="code" size="200">
      <input type="Submit" name="submit" value="Enter information">
    </p>
    </form>

insert.php

<?php
include("contentdb.php"); //here is the connection to db
include("data.php"); //here are declared the variables
$sql = "INSERT INTO $table (code) VALUES ('$code')";
$result = mysql_query($sql);
echo "<br><br>code added to quiz.<br><br>";
?>
<a href="editquizlist.php">Back to list of codes</a>

Please help me all help is appreciated .

sorry for my bad English...

Edited by solarb: n/a

3
Contributors
6
Replies
7
Views
7 Years
Discussion Span
Last Post by solarb
1

Actually funny enough, he does have some sort of security in place. The tag <iostream> was removed because of it's containing < and > (which generally signifies an HTML tag). What needs to be done though, is not stripslashes or addslahses. It's mysql_real_escape string():

<?php
include("contentdb.php"); //Connect to MySQL
include("data.php"); //Declares Variables
//Perform query
if(mysql_query("INSERT INTO $table (code) VALUES ('".mysql_real_escape_string($code)."')")) echo "<br><br>Your Code  was Added to the Quiz.<br><br>";
?>
<a href="editquizlist.php">Return to the Code List</a>

To really diagnose the problem, we would need to see the data.php file. Can you post it?

0

To really diagnose the problem, we would need to see the data.php file. Can you post it?

well its very simple :

data.php

<?php
$code=$_POST['code'];
$name=$_POST['name'];
$email=$_POST['email'];
$country=$_POST['country'];
?>

its combination with other scripts,where its needed there i place it.

will the tag <br> work or is it possible to make it work? bucause without <br> tag everything will be shown on one line. the php which shows the code is code1.php

its simple code i created but its making this strange things.I will check your solution thanks

code1.php

<?php

include("contentdb.php");
include("data.php");

$display = mysql_query("SELECT * FROM $table ORDER BY id",$db);

if (!$submit)
{
       echo "codes:"

        while ($row = mysql_fetch_array($display)) {

        echo "<br><b>";
        echo $code;
        echo "</b><br>";
        }
?>

Edited by solarb: n/a

0

thanks it worked,but everything is on one line.
is it possible to enable only <br> tag?

Thanks again

0

Maybe try nl2br() on the code:

<?php
include("contentdb.php");
include("data.php");
 
$display = mysql_query("SELECT code FROM $table ORDER BY id", $db);
if (!$submit)
{
       echo "Code:"
        while ($row = mysql_fetch_array($display)) {
        echo "<br><b>".nl2br($row['code'])."</b><br>";
        }
}
?>
0

I've made it work. for thoose who have mine problem change this :

<form method="post" action="insert.php">
    <p><br>
      <b>code:</b><br>
      <input type="Text" name="code" size="200"> 
      <input type="Submit" name="submit" value="Enter information">
    </p>
    </form>

this :

<input type="Text" name="code" size="200">

to :

<TEXTAREA name="code" rows="3" cols="40"  size="50"></TEXTAREA>

and add in this file :

<?php

include("contentdb.php");
include("data.php");

$display = mysql_query("SELECT * FROM $table ORDER BY id",$db);

if (!$submit)
{
       echo "codes:"

        while ($row = mysql_fetch_array($display)) {

        echo "<br><b>";
        echo $code;
        echo "</b><br>";
        }
?>

this :

echo $code;

to :

echo nl2br($code);

this will allow you to have line breaks in your code without <br> or \n .

Thanks again to all who helped

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.