Jump to content

Whats wrong with my code???


amitojduggal

Recommended Posts

Hello everybody,

The code is driving me nuts from couple of days
i just can't spot whats wrong in that.
i am inserting data in the database, but its not working , please someone verify the code
[code] $linkid=mysql_connect("localhost","root","")or die ('Couldnt Connect To database');
  mysql_select_db("details");
  $query ="INSERT INTO all(name,company_name,designation,response,ph_number,email,review) VALUES('$_POST[textfield3]','$_POST[textfield]','$_POST[textarea]','$_POST[textfield4]','$_POST[textfield5]', '$_POST[q]')";
  $result=mysql_query($query);[/code]
someone please tell me whats wrong in that.
I will be highly thankful

Amitoj
Link to comment
https://forums.phpfreaks.com/topic/27572-whats-wrong-with-my-code/
Share on other sites

Can you please try the query like this:

$query ="INSERT INTO all(name,company_name,designation,response,ph_number,email,review) VALUES('".$_POST[textfield3]."','".$_POST[textfield]."','".$_POST[textarea]."','".$_POST[textfield4]."','".$_POST[textfield5]."', '".$_POST[q]."');";

Please post the error you get
Well firstly if you are going to define link resource objects you should use them by supplying them as parameters to your subsewuent mySQL functions. Secondly, the 'all' in your query is both incorrect and unnecessary, SQL assumes all unless you qualify your statement somehow with a WHERE.
i don't get any error but the code simply doesn't make data inserted in sql database, i still see 0 records there,
please someone check my code, i really need help.
and please tell me whats the difference between
[code]$query ="INSERT INTO all(name,company_name,designation,response,ph_number,email,review) VALUES('".$_POST[textfield3]."','".$_POST[textfield]."','".$_POST[textarea]."','".$_POST[textfield4]."','".$_POST[textfield5]."', '".$_POST[q]."');";[/code]

and this way

[code]$query ="INSERT INTO all(name,company_name,designation,response,ph_number,email,review) VALUES('$_POST[textfield3]','$_POST[textfield]','$_POST[textarea]','$_POST[textfield4]','$_POST[textfield5]', '$_POST[q]');";[/code]

isn't both same
Need space between all and (
[code]

$query ="INSERT INTO all (name,company_name,designation,response,ph_number,email,review) VALUES('".$_POST[textfield3]."','".$_POST[textfield]."','".$_POST[textarea]."','".$_POST[textfield4]."','".$_POST[textfield5]."', '".$_POST[q]."');";

[/code]
some field names are reserved in MySQL
try to add ` before and after the field name.
like :
[code]
$query ="INSERT INTO all(`name`,company_name,designation,response,ph_number,email,`review`) VALUES('$_POST[textfield3]','$_POST[textfield]','$_POST[textarea]','$_POST[textfield4]','$_POST[textfield5]', '$_POST[q]')";
[/code]
you may have trouble with the filed names (name,review) I said maybe.
Also you should use mysql_real_escape_string to make your script safe.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.