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
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.

Link to comment
Share on other sites

the VALUES need be encased by single quotes - ie '$var1', '$var2'  etc etc

 

Thanks! Ill try that now! what is the reason for this? just out of interest. for example I have not put $random2 in quotes and it works ok, it it because they are varchars?

Link to comment
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.

 

 

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.