473,387 Members | 1,517 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

php/mysql single quatotion problem.

1
Hi,
I have an issue with php and/or mysql. I have a php form that writes "items"
to a mysql database, including a description of the item.

I am testing it now by putting special characters in the description field,
this is what I am entering:

Reader's Digest

Now, this item data always gets written to the db just fine and shows up in the db as entered. Seems correct and working just fine up to this point.

My problem is with my "edit item (PUBLISHER textbox)" page. This page allows users to update items, but when the data is called back up from the db to display in the "edit item" page and the description contains single quotes, the description is cut off, and only shows:

Reader

Here is the code on the "edit item" page:

<?php
session_start();
if ($_SESSION["validuser"]<>"YES") {
Header ("location: ../index.php");
}
include "dbConfig.php";

echo "<form enctype='multipart/form-data' action='editMag3.php' method='post' >";

$id = $_REQUEST['id'];
$_SESSION['id'] = $id;
$mysql_query = "select * from dbMag where id='$id' " ;
$n1 = mysql_query($mysql_query);
$r1 = mysql_num_rows($n1);
if($r1==0) {
die("<script>alert('Magazine Title not found. Try again.');history.back()</script>");
}

$n = mysql_fetch_array($n1);
$title = $n[0];
$_SESSION['magTitle']=$title;
$issue = $n[1];
// $link = $n[2];
$online = $n[3];
$type = $n[4];
$picture = $n[5];
$subtitle = $n[6];
$price = $n[7];
$publisher = $n[8];
//$publisher = htmlentites($n[8]);




//echo "$publisher";

echo "<h1>Edit Magazine</h1>";
echo "<table border='0'>";
echo "<tr>";
echo "<td width='100'>Title:</td>";
echo "<td width='100'>$title";
echo "</tr>";
echo "<tr>";
echo "<td width='100'>Sub Title:</td>";
echo "<td><input size='60' name='i1' value='$subtitle'></td>";
echo "</tr>";
echo "<tr>";
echo "<td width='100'>Issue No:</td>";
echo "<td><input size='60' name='i2' value='$issue'></td>";
echo "</tr>";
echo "<td width='100'>Type:</td>";
echo "<td><input size='60' name='i3' value='$type'></td>";
echo "</tr>";
echo "<tr>";
echo "<td width='100'>Price:</td>";
echo "<td><input size='60' name='i4' value='$price'></td>";
echo "</tr>";
echo "<tr>";
echo "<td width='100'>Publisher:</td>";

echo "<td><input size='60' type=text name=i5 value='$publisher'></td>";

//echo "<td><input size='60' name='i5' value='$publisher'></td>";
echo "</tr>";
echo "<tr>";
// echo "<td width='100'>Link:</td>";
// echo "<td><input size='60' name='i6' value='$link'></td>";
// echo "</tr>";


echo "<td width='100'>Picture:</td>";
echo "<td><input size='60' name='i7' value='$picture'></td>";
echo "</tr>";

echo "<tr>";
echo "<td width='100'><input type='hidden' name='MAX_FILE_SIZE' value='1000000'>Select New Picture:</td>";
echo "<td><input size='60' type='file' name='userfile' value='$newPic'></td>";
//echo"<td><input type='submit' value='upload'></td>";
echo "</tr>";



echo "<tr>";
echo "<td width='100'>Online:</td>";
echo "<td width='20'><select name='i8'>";
if ($online == "ON"){
echo "<option value='$online' selected>$online</option>";
echo "<option value='OFF'>OFF</option>";
} else {
echo "<option value='$online' selected>$online</option>";
echo "<option value='ON'>ON</option>";
}
echo "</select></td>";
echo "</tr>";

echo "<tr><td></td><td><input type='submit' value='submit'></td></tr>";
echo "</form>";
echo "</font>";

//echo "<form action='upnewbookcover.php' method='post'>";
// echo "<tr><td><td><input type='submit' value='change cover'><a href='upnewbookcover.php'></a></td></tr>";
// echo "</form>";



echo "<form action='magList.php' method='post'>";
echo "<tr><td><td><input type='submit' value='Cancel'><a href='magList.php'></a></td></tr>";
echo "</form>";
echo "</table>";


?>
Put your code within php, code or html TAGS!!!! - Ronald :cool:
Nov 22 '06 #1
1 1578
Hi,
I have an issue with php and/or mysql. I have a php form that writes "items"
to a mysql database, including a description of the item.

I am testing it now by putting special characters in the description field,
this is what I am entering:

Reader's Digest

Now, this item data always gets written to the db just fine and shows up in the db as entered. Seems correct and working just fine up to this point.

My problem is with my "edit item (PUBLISHER textbox)" page. This page allows users to update items, but when the data is called back up from the db to display in the "edit item" page and the description contains single quotes, the description is cut off, and only shows:

Reader

Here is the code on the "edit item" page:

<?php
session_start();
if ($_SESSION["validuser"]<>"YES") {
Header ("location: ../index.php");
}
include "dbConfig.php";

echo "<form enctype='multipart/form-data' action='editMag3.php' method='post' >";

$id = $_REQUEST['id'];
$_SESSION['id'] = $id;
$mysql_query = "select * from dbMag where id='$id' " ;
$n1 = mysql_query($mysql_query);
$r1 = mysql_num_rows($n1);
if($r1==0) {
die("<script>alert('Magazine Title not found. Try again.');history.back()</script>");
}

$n = mysql_fetch_array($n1);
$title = $n[0];
$_SESSION['magTitle']=$title;
$issue = $n[1];
// $link = $n[2];
$online = $n[3];
$type = $n[4];
$picture = $n[5];
$subtitle = $n[6];
$price = $n[7];
$publisher = $n[8];
//$publisher = htmlentites($n[8]);




//echo "$publisher";

echo "<h1>Edit Magazine</h1>";
echo "<table border='0'>";
echo "<tr>";
echo "<td width='100'>Title:</td>";
echo "<td width='100'>$title";
echo "</tr>";
echo "<tr>";
echo "<td width='100'>Sub Title:</td>";
echo "<td><input size='60' name='i1' value='$subtitle'></td>";
echo "</tr>";
echo "<tr>";
echo "<td width='100'>Issue No:</td>";
echo "<td><input size='60' name='i2' value='$issue'></td>";
echo "</tr>";
echo "<td width='100'>Type:</td>";
echo "<td><input size='60' name='i3' value='$type'></td>";
echo "</tr>";
echo "<tr>";
echo "<td width='100'>Price:</td>";
echo "<td><input size='60' name='i4' value='$price'></td>";
echo "</tr>";
echo "<tr>";
echo "<td width='100'>Publisher:</td>";

echo "<td><input size='60' type=text name=i5 value='$publisher'></td>";

//echo "<td><input size='60' name='i5' value='$publisher'></td>";
echo "</tr>";
echo "<tr>";
// echo "<td width='100'>Link:</td>";
// echo "<td><input size='60' name='i6' value='$link'></td>";
// echo "</tr>";


echo "<td width='100'>Picture:</td>";
echo "<td><input size='60' name='i7' value='$picture'></td>";
echo "</tr>";

echo "<tr>";
echo "<td width='100'><input type='hidden' name='MAX_FILE_SIZE' value='1000000'>Select New Picture:</td>";
echo "<td><input size='60' type='file' name='userfile' value='$newPic'></td>";
//echo"<td><input type='submit' value='upload'></td>";
echo "</tr>";



echo "<tr>";
echo "<td width='100'>Online:</td>";
echo "<td width='20'><select name='i8'>";
if ($online == "ON"){
echo "<option value='$online' selected>$online</option>";
echo "<option value='OFF'>OFF</option>";
} else {
echo "<option value='$online' selected>$online</option>";
echo "<option value='ON'>ON</option>";
}
echo "</select></td>";
echo "</tr>";

echo "<tr><td></td><td><input type='submit' value='submit'></td></tr>";
echo "</form>";
echo "</font>";

//echo "<form action='upnewbookcover.php' method='post'>";
// echo "<tr><td><td><input type='submit' value='change cover'><a href='upnewbookcover.php'></a></td></tr>";
// echo "</form>";



echo "<form action='magList.php' method='post'>";
echo "<tr><td><td><input type='submit' value='Cancel'><a href='magList.php'></a></td></tr>";
echo "</form>";
echo "</table>";


?>
Hi !

I suggest, its always a best practice to use " addslashes() " when you are inserting into the database and use " stripslashes() " when you read it back .
Try it.
Good luck !
Nov 29 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Dennis Francis B. Tutanes | last post by:
$B$*@$OC$K$J$C$F$*$j$^$9!#(B $B%D%?%M%9(B@TSTI$B$G$9!#(B SEND-PR: -*- send-pr -*- SEND-PR: Lines starting with `SEND-PR' will be removed automatically, as SEND-PR: will all comments (text...
0
by: Henry Hank | last post by:
Environment: I'm setting up a database server on a Dell Poweredge 2650, dual 1.8GHZ pentium with 1GB of memory and RAID5 drives. I've installed RedHat 9, and updated the kernel to 2.4.20-19.9smp....
39
by: Mairhtin O'Feannag | last post by:
Hello, I have a client (customer) who asked the question : "Why would I buy and use UDB, when MySql is free?" I had to say I was stunned. I have no experience with MySql, so I was left sort...
2
by: saran | last post by:
I am having a problem with MySQL consuming a lot of memory and eventually throwing an Out of Memory error and restarting itself. The symptoms are that swap usage continues to rise until some...
7
by: Daz | last post by:
Hi. I am trying to select data from two separate MySQL tables, where I cannot use join, but when I put the two select queries into a single query, I get an error telling me to check my syntax. Both...
110
by: alf | last post by:
Hi, is it possible that due to OS crash or mysql itself crash or some e.g. SCSI failure to lose all the data stored in the table (let's say million of 1KB rows). In other words what is the worst...
30
by: Einstein30000 | last post by:
Hi, in one of my php-scripts is the following query (with an already open db-connection): $q = "INSERT INTO main (name, img, descr, from, size, format, cat, host, link, date) VALUES ('$name',...
221
Atli
by: Atli | last post by:
You may be wondering why you would want to put your files “into” the database, rather than just onto the file-system. Well, most of the time, you wouldn’t. In situations where your PHP application...
0
by: jllanten | last post by:
I will appreciate any help you can provide me. In the company where i work we have a project which creates about 4-5M records daily of stats. We're currently storing this data in a db named...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.