Jump to content

forms and database help


autoglass

Recommended Posts

I am quite new to this and am working on a site of my own. I am wanting to input data into a database based on the values of two textboxes. I have the general engine set up but there are some problems.

 

For example when I do the INSERT with values such as:

 

mysql_query("INSERT INTO PageTable (uniqueid, ImageLink, ImageLink2, IP)

VALUES ('3434343',

'http://www.example.com/1.jpg',

'http://www.example.com/1.jpg',

'94.123.123.9')");

 

This will go into the database perfectly. However if I do this:

 

mysql_query("INSERT INTO PageTable (uniqueid, ImageLink, ImageLink2, IP)

VALUES ($random2,

$img1,

$img2,

$ip)");

 

Where random2 is rand() and img1 and img2 are the values of the text boes and ip is the ip of the user.

 

When I do this there is no insert into the database.

 

Another thing I noticed was that if I put in '111111111111111111' into the textbox the value in the database is something like 111111111111111.0904039 or something like that, however if I put '111111111111111111' into the INSERT statement it goes into the database perfectly. Also if I put '1' into the textbox it goes in fine but putting 'a' into the textbox and it doesn't! I am sure I am missing something very very basic but I just can't get my head round this! Any help would be much appreciated.

Link to comment
https://forums.phpfreaks.com/topic/223351-forms-and-database-help/
Share on other sites

Put your query in a string, then echo it to validate it.

Put single quotes around your variables in your insert statement.

Use mysql_error after your query to diagnose sql errors.

We also don't see your form code, so hard to say if you're doing that part right as well.

Put your query in a string, then echo it to validate it.

Put single quotes around your variables in your insert statement.

Use mysql_error after your query to diagnose sql errors.

We also don't see your form code, so hard to say if you're doing that part right as well.

 

 

Thanks! I was validating it so I knew the data that should be going in was fine! It looks like the single quotes are working, just didn't realise I needed them! Can you expand on the mysql_error?

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.