INSERT INTO doesn't work.[sorted at last. thanks wayne]

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

User avatar
guitarlvr
Forum Contributor
Posts: 245
Joined: Wed Mar 21, 2007 10:35 pm

Post by guitarlvr »

well in your original $insert = mysql_query(INSERT INTO........ you were running the query there then running it again and storing it under $result. I think thats why the query was empty cause it had already run. Is there any information in that table at all? I think there should be as it had already ran. essentially, you want to build the query into the $insert var and then run the query and assign that to $result.

Wayne
User avatar
guitarlvr
Forum Contributor
Posts: 245
Joined: Wed Mar 21, 2007 10:35 pm

Post by guitarlvr »

I'm not a PHP expert by any means as I haven't been coding that long but I don't understand why you need to concatenate all those variables. I would think that would cause a problem to but i guess not.
toby_c500
Forum Commoner
Posts: 50
Joined: Fri May 11, 2007 11:29 am
Location: Leeds, England

Post by toby_c500 »

Cheers for helping me Wayne.

I have just run with what you mentioned earlier about the concats and got:


Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /Applications/MAMP/htdocs/register.php on line 25.

When you say I am running the query twice. What do you mean? $insert once and then where? I think that is probably the key.
User avatar
guitarlvr
Forum Contributor
Posts: 245
Joined: Wed Mar 21, 2007 10:35 pm

Post by guitarlvr »

You are running the query everytime you use mysql_query() function. $insert = mysql_query() and $result = mysql_query().

Can you repost the code that you have. You've changed quite a few things since you've posted it last. Also, what is line 25?

Wayne
toby_c500
Forum Commoner
Posts: 50
Joined: Fri May 11, 2007 11:29 am
Location: Leeds, England

Post by toby_c500 »

Line 25 is the first line of VALUES.

I have changed the concats back now as you can see. This just shows up the empty query statement.

Code: Select all

<?php
$link = mysql_connect('localhost', 'root', 'root');

if(!$link){
        echo "Sorry, we are having a few problems with our system. Please try again later. link";
        exit;
}
else{
        echo "Your details have been stored in our database. Use the the navigation bar at the top to look for jobs.";
}

$db = mysql_select_db('jobs4alltrades', $link);
if (!$db) die('could not select the database');

$insert = mysql_query("INSERT INTO members (loginid, password, firstname, surname, email,
                                                        trade, address1, address2, address3, address4,
                                                        postzip, country, yearsexp, about)
                               VALUES ('".$_POST['loginid']."', '".$_POST['password']."', '".$_POST['firstname']."',
                                                '".$_POST['surname']."', '".$_POST['email']."', '".$_POST['trade']."', '".$_POST['address1']."',
                                                '".$_POST['address2']."', '".$_POST['address3']."','".$_POST['address4']."', '".$_POST['post']."',
                                                '".$_POST['country']."','".$_POST['yearsexp']."','".$_POST['about']."')");

$result = mysql_query($insert, $link) or die("Query: $insert\n<br /.> MySQL Error: " . mysql_error());


?>
toby_c500
Forum Commoner
Posts: 50
Joined: Fri May 11, 2007 11:29 am
Location: Leeds, England

Post by toby_c500 »

is it not a different query when the ($var)'s are different?
User avatar
guitarlvr
Forum Contributor
Posts: 245
Joined: Wed Mar 21, 2007 10:35 pm

Post by guitarlvr »

still looks like its being done twice, try this:

Code: Select all

<?php
$link = mysql_connect('localhost', 'root', 'root');

if(!$link){
        echo "Sorry, we are having a few problems with our system. Please try again later. link";
        exit;
}
else{
        echo "Your details have been stored in our database. Use the the navigation bar at the top to look for jobs.";
}

$db = mysql_select_db('jobs4alltrades', $link);
if (!$db) die('could not select the database');

$insert = "INSERT INTO members (loginid, password, firstname, surname, email,
                                                        trade, address1, address2, address3, address4,
                                                        postzip, country, yearsexp, about)
                               VALUES ('".$_POST['loginid']."', '".$_POST['password']."', '".$_POST['firstname']."',
                                                '".$_POST['surname']."', '".$_POST['email']."', '".$_POST['trade']."', '".$_POST['address1']."',
                                                '".$_POST['address2']."', '".$_POST['address3']."','".$_POST['address4']."', '".$_POST['post']."',
                                                '".$_POST['country']."','".$_POST['yearsexp']."','".$_POST['about']."')";

$result = mysql_query($insert, $link) or die("Query: $insert\n<br /.> MySQL Error: " . mysql_error());


?>
toby_c500
Forum Commoner
Posts: 50
Joined: Fri May 11, 2007 11:29 am
Location: Leeds, England

Post by toby_c500 »

its just echoed the INSERT INTO line with values.

The error: MySQL Error: Unknown column 'address3' in 'field list' has shown at the bottom.
User avatar
guitarlvr
Forum Contributor
Posts: 245
Joined: Wed Mar 21, 2007 10:35 pm

Post by guitarlvr »

Are you positive that address3 is spelled that way in the table?

Wayne
toby_c500
Forum Commoner
Posts: 50
Joined: Fri May 11, 2007 11:29 am
Location: Leeds, England

Post by toby_c500 »

Wayne. Your a bloody ledgend. Its sorted.

I've been a tit. That error on the last has sorted it. A mistake on my part in the mysql end. What a complete tit I am.

Thank you so much mate. You have been amazing. I'm so happy now. Thank you.
toby_c500
Forum Commoner
Posts: 50
Joined: Fri May 11, 2007 11:29 am
Location: Leeds, England

Post by toby_c500 »

I just hope I can return the favor one day.

Thanks again mate. I feel like a fool.
User avatar
guitarlvr
Forum Contributor
Posts: 245
Joined: Wed Mar 21, 2007 10:35 pm

Post by guitarlvr »

Hey we all make mistakes, glad you got it going. :)

Wayne
Post Reply