Solved

why i cant insert into a field in a table in mysql things like "."  "?"   "," ?????

Posted on 2008-06-10
8
230 Views
Last Modified: 2012-05-05
i have a field in a table and i want to insert in it this symbols
?
.
,
'
but its not working
why is that?
0
Comment
Question by:mgtm3
8 Comments
 
LVL 5

Accepted Solution

by:
vibrazy earned 250 total points
ID: 21749453
Try using mysql_real_escape_string($fieldname);
0
 

Author Comment

by:mgtm3
ID: 21749461
look att the code and tell me what to do?
<?php
 

include 'cpoll.php';
 
 

$subject = $_POST['subject'];

$op1 = $_POST['op1'];

$op2 = $_POST['op2'];

$op3 = $_POST['op3'];

$op4 = $_POST['op4'];

$op5 = $_POST['op5'];

$op6 = $_POST['op6'];

$op7 = $_POST['op7'];

$op8 = $_POST['op8'];

$op9 = $_POST['op9'];

$op10 = $_POST['op10'];

$op11 = $_POST['op11'];

$op12 = $_POST['op12'];

$gen=$_POST['gen'];
 
 

$result = mysqli_query($link, "SELECT count(*) FROM $gen");

$row = mysqli_fetch_array($result, MYSQLI_NUM);

$row[0]++;

$pollname="poll".$gen.$row[0];

echo $pollname; 
 
 
 

echo "subject - ".$subject."<br />op1 - ".$op1."<br />op2 - ".$op2."<br />op3 - ".$op3."<br />op4 - ".$op4."<br />op5 - ".$op5."<br />gen - ".$gen;
 

$sql = "CREATE TABLE $pollname (

`id` int( 255 ) NOT NULL AUTO_INCREMENT,

  `subject` VARCHAR( 700 )NOT NULL,

        `op1` VARCHAR( 700 )NOT NULL,

        `op2` VARCHAR( 700 ) NOT NULL,

        `op3` VARCHAR( 700 ) NOT NULL,

        `op4` VARCHAR( 700 ) NOT NULL,

        `op5` VARCHAR( 700 ) NOT NULL,

		 `op6` VARCHAR( 700 )NOT NULL,

        `op7` VARCHAR( 700 ) NOT NULL,

        `op8` VARCHAR( 700 ) NOT NULL,

        `op9` VARCHAR( 700 ) NOT NULL,

        `op10` VARCHAR( 700 ) NOT NULL,

		`op11` VARCHAR( 700 ) NOT NULL,

        `op12` VARCHAR( 700 ) NOT NULL,

            `date` VARCHAR( 700 ) NOT NULL,

            `user` VARCHAR( 700 ) NOT NULL,

			            `comment` text NOT NULL,
 

            `gen` VARCHAR( 700 ) NOT NULL,

            

        PRIMARY  KEY ( `id` )

       )";
 

 
 
 
 

mysqli_query($link,$sql);
 

mysqli_close($link);

unset($link);

include 'cpoll.php';
 

$f = "INSERT INTO $pollname (op1,op2,op3,op4,op5,subject,gen) VALUES ('$op1','$op2','$op3','$op4','$op5','$subject','$gen')"; 

Open in new window

0
 
LVL 5

Expert Comment

by:vibrazy
ID: 21749493
Try this, if that doesnt work, tell me what error you are getting.

Regards,
Vibrazy
$f = "INSERT INTO $pollname (op1,op2,op3,op4,op5,subject,gen) VALUES ('".$op1."','".$op2."','".$op3."','".$op4."','".$op5."','".$subject."','".$gen."')"; 

mysqli_query($link,$f);

Open in new window

0
 

Author Comment

by:mgtm3
ID: 21749508
can u write me the function to get the error ?
0
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 

Author Comment

by:mgtm3
ID: 21749540
o.k this what i got

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 's Day','Valentine's Day','Favorite holiday?','other')' at line 1
0
 
LVL 28

Assisted Solution

by:gamebits
gamebits earned 250 total points
ID: 21749671
$subject = $_POST['subject'];
$op1 = mysql_real_escape_string ($_POST['op1']);
$op2 = mysql_real_escape_string ($_POST['op2']);
$op3 = mysql_real_escape_string ($_POST['op3']);
$op4 = mysql_real_escape_string ($_POST['op4']);
$op5 = mysql_real_escape_string ($_POST['op5']);
$op6 = mysql_real_escape_string ($_POST['op6']);
$op7 = mysql_real_escape_string ($_POST['op7']);
$op8 = mysql_real_escape_string ($_POST['op8']);
$op9 = mysql_real_escape_string ($_POST['op9']);
$op10 = mysql_real_escape_string ($_POST['op10']);
$op11 = mysql_real_escape_string ($_POST['op11']);
$op12 = mysql_real_escape_string ($_POST['op12']);
$gen = mysql_real_escape_string ($_POST['gen']);


Now you can use it in a query
0
 

Author Comment

by:mgtm3
ID: 21749716
thanksssssssssssssssss
0
 
LVL 4

Expert Comment

by:afzz
ID: 21749726
You can also do the following instead of individually changing the values
foreach($_POST as $key => $val){

${$key} = mysql_real_escape_string($val);

}

Open in new window

0

Featured Post

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now