How is String 5'9" inserted into a Table

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bigbug
Forum Newbie
Posts: 1
Joined: Wed Jun 09, 2010 8:37 pm

How is String 5'9" inserted into a Table

Post 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,
Last edited by bigbug on Thu Jun 10, 2010 12:18 pm, edited 2 times in total.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

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

Post by requinix »

Last edited by pickle on Thu Jun 10, 2010 9:56 am, edited 1 time in total.
Reason: Removed the SHOUTING
Post Reply