473,698 Members | 2,181 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

php/mysql single quatotion problem.

1 New Member
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.p hp";

echo "<form enctype='multip art/form-data' action='editMag 3.php' method='post' >";

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

$n = mysql_fetch_arr ay($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'>Tit le:</td>";
echo "<td width='100'>$ti tle";
echo "</tr>";
echo "<tr>";
echo "<td width='100'>Sub Title:</td>";
echo "<td><input size='60' name='i1' value='$subtitl e'></td>";
echo "</tr>";
echo "<tr>";
echo "<td width='100'>Iss ue No:</td>";
echo "<td><input size='60' name='i2' value='$issue'> </td>";
echo "</tr>";
echo "<td width='100'>Typ e:</td>";
echo "<td><input size='60' name='i3' value='$type'></td>";
echo "</tr>";
echo "<tr>";
echo "<td width='100'>Pri ce:</td>";
echo "<td><input size='60' name='i4' value='$price'> </td>";
echo "</tr>";
echo "<tr>";
echo "<td width='100'>Pub lisher:</td>";

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

//echo "<td><input size='60' name='i5' value='$publish er'></td>";
echo "</tr>";
echo "<tr>";
// echo "<td width='100'>Lin k:</td>";
// echo "<td><input size='60' name='i6' value='$link'></td>";
// echo "</tr>";


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

echo "<tr>";
echo "<td width='100'><in put 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'>Onl ine:</td>";
echo "<td width='20'><sel ect name='i8'>";
if ($online == "ON"){
echo "<option value='$online' selected>$onlin e</option>";
echo "<option value='OFF'>OFF </option>";
} else {
echo "<option value='$online' selected>$onlin e</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='upnewbo okcover.php' method='post'>" ;
// echo "<tr><td><td><i nput type='submit' value='change cover'><a href='upnewbook cover.php'></a></td></tr>";
// echo "</form>";



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


?>
Put your code within php, code or html TAGS!!!! - Ronald :cool:
Nov 22 '06 #1
1 1595
scriptee
17 New Member
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.p hp";

echo "<form enctype='multip art/form-data' action='editMag 3.php' method='post' >";

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

$n = mysql_fetch_arr ay($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'>Tit le:</td>";
echo "<td width='100'>$ti tle";
echo "</tr>";
echo "<tr>";
echo "<td width='100'>Sub Title:</td>";
echo "<td><input size='60' name='i1' value='$subtitl e'></td>";
echo "</tr>";
echo "<tr>";
echo "<td width='100'>Iss ue No:</td>";
echo "<td><input size='60' name='i2' value='$issue'> </td>";
echo "</tr>";
echo "<td width='100'>Typ e:</td>";
echo "<td><input size='60' name='i3' value='$type'></td>";
echo "</tr>";
echo "<tr>";
echo "<td width='100'>Pri ce:</td>";
echo "<td><input size='60' name='i4' value='$price'> </td>";
echo "</tr>";
echo "<tr>";
echo "<td width='100'>Pub lisher:</td>";

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

//echo "<td><input size='60' name='i5' value='$publish er'></td>";
echo "</tr>";
echo "<tr>";
// echo "<td width='100'>Lin k:</td>";
// echo "<td><input size='60' name='i6' value='$link'></td>";
// echo "</tr>";


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

echo "<tr>";
echo "<td width='100'><in put 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'>Onl ine:</td>";
echo "<td width='20'><sel ect name='i8'>";
if ($online == "ON"){
echo "<option value='$online' selected>$onlin e</option>";
echo "<option value='OFF'>OFF </option>";
} else {
echo "<option value='$online' selected>$onlin e</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='upnewbo okcover.php' method='post'>" ;
// echo "<tr><td><td><i nput type='submit' value='change cover'><a href='upnewbook cover.php'></a></td></tr>";
// echo "</form>";



echo "<form action='magList .php' method='post'>" ;
echo "<tr><td><td><i nput type='submit' value='Cancel'> <a href='magList.p hp'></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
2488
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 enclosed in `<' and `>'). SEND-PR: From: dtutanes To: mysql@lists.mysql.com Subject:
0
1462
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. I've installed the RPM binary distribution of MySQL 4.0.14 right from the MySQL website. The only thing I have done is disable InnoDb in my my.cnf file. Database Table: I have a database with 21.4 million records. One field is a VARCHAR(255)...
39
8402
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 of stammering and sputtering, and managed to pull out something I heard a couple of years back - that there was no real transaction safety in MySql. In flight transactions could be lost.
2
3814
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 breaking point. The application is a typical web application w/ 2 web servers running Apache/Tomcat connecting to a dedicated DB server running only MySQL. This seems to occur as a result of running many statements in a single transaction, both...
7
2720
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 of the queries work fine when I use them to query the MySQL server directly. My guess is that the MySQL extension only expects a single resource back from the database, but get's several, or that it just checks the statement first, and decides...
110
10577
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 case scenario for MyISAM backend? Also is it possible to not to lose data but get them corrupted?
30
2819
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', '$img', '$descr', '$user', '$size', '$format', '$cat', '$host', '$link', '$date')" or die(mysql_error()); And when the query gets executed i get back the following error:
221
367510
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 needs to store entire files, the preferred method is to save the file onto the server’s file-system, and store the physical location of the file in your database. This is generally considered to be the easiest and fastest way to store files. ...
0
2163
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 'summary' which contains all the stats data for up to 15 days. After that we begin to move the data in a daily basis to a single 'archived like' unique table in another fast performance mysql instance. Why we do this ? to respect the 80%-20% rule: 80% of...
0
8671
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9016
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8887
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6515
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5858
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4360
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4613
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2321
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.