Page 1 of 1

How is String 5'9" inserted into a Table

Posted: Wed Jun 09, 2010 9:01 pm
by bigbug
Hi There,

How to make the following statement work?

Code: Select all

$sql="INSERT INTO FeetInch (NAME, HEIGHT) VALUES('$_POST[sName]','$_POST[height]')";
Here $_POST[name] = 'David', and $_POST[height] = 5'9"

The error is as below:

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 '9"')' at line 2

Code: Select all

<html>
<body>

<form action="AdE.php" method="post">
Name:<input type="text" name="sName" size="20" maxlength="30" />
Height:<input type="text" name="height" size="20" maxlength="40"/>
<input type="submit" name="submit" value="Submit AD" />
</form>

</body>
</html>

And

<html>
<body>

<?php
$con = mysql_connect("localhost","bigbug","32432jhH");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("test", $con);

$sql="INSERT INTO FeetInch (NAME, HEIGHT)
VALUES('$_POST[sName]','$_POST[height]')";

if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "1 record added";

mysql_close($con)
?> 

</body>
</html> 
Database is MySQL.

It works well if $_POST[name] = 'David', and $_POST[height] = 180cm

Thanks,

Re: How is String 5'9" inserted into a Table

Posted: Wed Jun 09, 2010 11:14 pm
by requinix