Problem, "Unknown column 'Jon' in 'field list'"

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

37 Replies - 4457 Views - Last Post: 28 December 2012 - 04:11 AM Rate Topic: -----

#1 sebwerner2  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 27-December 12

Problem, "Unknown column 'Jon' in 'field list'"

Posted 27 December 2012 - 11:23 PM

//Textbox information
$name=$_POST['name'];
$surename=$_POST['surename'];
$day=$_POST['day'];
$month=$_POST['month'];
$year=$_POST['year'];
$gender=$_POST['gender'];
$report=$_POST['raport'];

mysql_query("INSERT INTO raport(firstname,surename,day,month,year,gender,raport) VALUES($name, $surename, $day, $month, $year, $gender, $report) ") or die(mysql_error());  



The error says "Unknown column 'Jon' in 'field list'"
Well, i kinda know why i get the problem, but i have no clue how to fix it...
As you see in my code under the "//Textbox Information" in the "$name" variable. It gets the information from a textbox in another PHP-file where i typed the name "Jon".

My questions is:"Why is this happening? How do i fix it?"

I would appreciate the help!
,cheers Sebwerner

Is This A Good Question/Topic? 0
  • +

Replies To: Problem, "Unknown column 'Jon' in 'field list'"

#2 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: Problem, "Unknown column 'Jon' in 'field list'"

Posted 27 December 2012 - 11:51 PM

Well, can you tell me what all columns exist in your raport table?

I have a feeling you have a typo somewhere...

regards,
Raghav
Was This Post Helpful? 0
  • +
  • -

#3 sebwerner2  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 27-December 12

Re: Problem, "Unknown column 'Jon' in 'field list'"

Posted 28 December 2012 - 12:06 AM

Posted Image

Here you go!
Was This Post Helpful? 0
  • +
  • -

#4 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: Problem, "Unknown column 'Jon' in 'field list'"

Posted 28 December 2012 - 12:12 AM

Well, your table seems fine...now here is a small suggestion.

Instead of using $_POST, try using $_GET and see what happens when you do that...

regards,
Raghav
Was This Post Helpful? 0
  • +
  • -

#5 Sho Ke  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 107
  • View blog
  • Posts: 246
  • Joined: 13-October 11

Re: Problem, "Unknown column 'Jon' in 'field list'"

Posted 28 December 2012 - 12:18 AM

Why would you do this:
$name=$_POST['name'];
//...
mysql_query("INSERT INTO raport(firstname) VALUES($name)");


When you can just do this?
mysql_query("INSERT INTO raport(firstanem) VALUES($_POST['name'])");



It might also help to post full code, both from the form where you input the data and the file that stores it into the database.

This post has been edited by Sho Ke: 28 December 2012 - 12:20 AM

Was This Post Helpful? 1
  • +
  • -

#6 sebwerner2  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 27-December 12

Re: Problem, "Unknown column 'Jon' in 'field list'"

Posted 28 December 2012 - 01:12 AM

[quote name='Sho Ke' date='28 December 2012 - 12:18 AM' timestamp='1356679113' post='1774203']
Why would you do this:
$name=$_POST['name'];
//...
mysql_query("INSERT INTO raport(firstname) VALUES($name)");


When you can just do this?
mysql_query("INSERT INTO raport(firstanem) VALUES($_POST['name'])");



Oh, didnt know that was possible! Started learning some weeks ago, but thanks, good knowing differt ways! :P
I will change that, and come back here to say what happend! :D
Was This Post Helpful? 0
  • +
  • -

#7 Sho Ke  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 107
  • View blog
  • Posts: 246
  • Joined: 13-October 11

Re: Problem, "Unknown column 'Jon' in 'field list'"

Posted 28 December 2012 - 01:15 AM

Well, that wasn't really the cause of the error you're recieving, I was just pointing out that, when you start with variable X, there's no need to create another variable, Y, when you want to use the information variable X contains. Lots of tutorials tend to do what you did, and I don't really understand why. A person in my programming class says he does it because he doesn't like typing out brackets [''] every time he wants to use a variable, but every single time I look at his code, he only uses those variables once, thus wasting his time.
Was This Post Helpful? 0
  • +
  • -

#8 sebwerner2  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 27-December 12

Re: Problem, "Unknown column 'Jon' in 'field list'"

Posted 28 December 2012 - 01:22 AM

[quote name='Sho Ke' date='28 December 2012 - 12:18 AM' timestamp='1356679113' post='1774203']
Why would you do this:
$name=$_POST['name'];
//...
mysql_query("INSERT INTO raport(firstname) VALUES($name)");


When you can just do this?
mysql_query("INSERT INTO raport(firstanem) VALUES($_POST['name'])");



Oh, didnt know that was possible! Started learning some weeks ago, but thanks, good knowing differt ways! :P
I will change that, and come back here to say what happend! :D

I changed the $_POSTs to $_GETs and i changed the mehtod from post to get in the script with the form in.

When i try it out i get a new error this: "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 ' , , , , , )' at line 1"
Was This Post Helpful? 0
  • +
  • -

#9 sebwerner2  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 27-December 12

Re: Problem, "Unknown column 'Jon' in 'field list'"

Posted 28 December 2012 - 01:39 AM

Here is the whole code

The mysql script
<?php
//Database login information
$mysql_host="mysql14.000webhost.com";
$mysql_username="a6862757_MyDB";
$mysql_password="letmeinpl0x";
$mysql_database_name="a6862757_myDB";

//Textbox information
$name=$_GET['name'];
$surename=$_GET['surename'];
$day=$_GET['day'];
$month=$_GET['month'];
$year=$_GET['year'];
$gender=$_GET['gender'];
$report=$_GET['raport'];

// Make a MySQL Connection
mysql_connect($mysql_host, $mysql_username, $mysql_password) or die(mysql_error());
mysql_select_db($mysql_database_name) or die(mysql_error());

// Insert a row of information into the table "report"
mysql_query("INSERT INTO report(firstname,surename,day,month,year,gender,report) VALUES($name, $surename, $day, $month, $year, $gender, $report)") or die(mysql_error());  

//Suceeed message
echo "Data Inserted!";

?>



The "Form" code

<table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form name="form1" method="get" action="checkreport.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td colspan="3"><strong>Raport </strong></td>
</tr>

<tr>
<td width="78">Fornavn</td>
<td width="6">:</td>
<td width="294"><input name="name" type="text" id="name"></td>
</tr>

<tr>
<td>Etternavn</td>
<td>:</td>
<td><input name="surename" type="text" id="surename"></td>
</tr>

<tr>
<td>Født(d/m/y)</td>
<td>:</td>
<td>
<input name="day" type="text" id="day" style="width:23px; height:20px;">
<input name="month" type="text" id="month" style="width:23px; height:20px;">
<input name="year" type="text" id="year" style="width:35px; height:20px;">
</td>
</tr>

<tr>
<td>Kjønn (M/F)</td>
<td>:</td>
<td><input name="gender" type="text" id="gender" style="width:23px; height:20px;"></td>
</tr>

<tr>
<td>Raport</td>
<td>:</td>
<td><input name="raport" type="text" id="raport" style="width:300px; height:60px;"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><input type="submit" name="submit" value="Legg til"></td>
</tr>

</table>
</td>
</form>
</tr>
</table>


Was This Post Helpful? 0
  • +
  • -

#10 sebwerner2  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 27-December 12

Re: Problem, "Unknown column 'Jon' in 'field list'"

Posted 28 December 2012 - 01:57 AM

Ichanged all the "$_GET"s and the Get in the Form script back to post btw.
Was This Post Helpful? 0
  • +
  • -

#11 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: Problem, "Unknown column 'Jon' in 'field list'"

Posted 28 December 2012 - 01:59 AM

Well,try this instead of line 18
mysql_connect("localhost","root","") or die(mysql_error());


regards,
Raghav
Was This Post Helpful? 0
  • +
  • -

#12 sebwerner2  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 27-December 12

Re: Problem, "Unknown column 'Jon' in 'field list'"

Posted 28 December 2012 - 02:00 AM

I know i've posted a shitload of post now, but i got it working.. It work when i use numbers, and only when i use numbers :/ Kinda strange Oo
Was This Post Helpful? 0
  • +
  • -

#13 sebwerner2  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 27-December 12

Re: Problem, "Unknown column 'Jon' in 'field list'"

Posted 28 December 2012 - 02:05 AM

View Postraghav.naganathan, on 28 December 2012 - 01:59 AM, said:

Well,try this instead of line 18
mysql_connect("localhost","root","") or die(mysql_error());


regards,
Raghav


That can't be the problem, because it works with numbers...
Was This Post Helpful? 0
  • +
  • -

#14 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: Problem, "Unknown column 'Jon' in 'field list'"

Posted 28 December 2012 - 02:10 AM

View Postsebwerner2, on 28 December 2012 - 02:35 PM, said:

it works with numbers...


You mean to say day, month and year works with numbers right?...that is because you have given the datatype as int

regards,
Raghav

This post has been edited by raghav.naganathan: 28 December 2012 - 02:10 AM

Was This Post Helpful? 0
  • +
  • -

#15 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3402
  • View blog
  • Posts: 9,611
  • Joined: 08-June 10

Re: Problem, "Unknown column 'Jon' in 'field list'"

Posted 28 December 2012 - 02:50 AM

I may remind you that string values have to be passed quoted into a plain SQL query, otherwise they are interpreted as columns.

on the other hand side, Prepared Statements do not suffer from that the data to fill in do not need any quotation.
Was This Post Helpful? 1
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3