backinblack Posted February 16, 2006 Share Posted February 16, 2006 For some reason I cannot add information into mysql. Can some one help me figure out what is wrong. Here is my code.[code]<html><head><title>Driver Profile Posting</title></head><body><p align="center"><font size="5"><b>Driver Profile Comfirmation Page</b></font></p><hr><p><?php$fullname=$HTTP_POST_VARS['fullname'];$city=$HTTP_POST_VARS['city'];$carnumber=$HTTP_POST_VARS['carnumber'];$class=$HTTP_POST_VARS['class'];$engine=$HTTP_POST_VARS['engine'];$chassis=$HTTP_POST_VARS['chassis'];$sponsors=$HTTP_POST_VARS['sponsors'];$pitcrew=$HTTP_POST_VARS['pitcrew'];$website=$HTTP_POST_VARS['website'];$hobbies=$HTTP_POST_VARS['hobbies'];$startedracing=$HTTP_POST_VARS['startedracing'];$careerhighlights=$HTTP_POST_VARS['careerhighlights'];$extracomments=$HTTP_POST_VARS['extracomments'];$host="xxxxxx";$user="xxxxxxx";$password="xxxxxxx";$database = "ccrace_profiles";$connection = mysql_connect($host,$user,$password) or die ("Could not retrieve information");$db = mysql_select_db("ccrace_profiles",$connection) or die ("Could not make connection");$query="insert into driverprofiles values('".$fullname."', '".$city."', '".$carnumber."', '".$class."', '".$engine."', '".$chassis."','".$sponsors."', '".$pitcrew."', '".$website."' , '".$hobbies."' , '".$startedracing."' , '".$careerhighlights."' , '".$extracomments."')"; $results=mysql_query($query) if ($results);echo 'Your profile has been added!';?></body></html>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/3445-unable-to-insert-data/ Share on other sites More sharing options...
fenway Posted February 16, 2006 Share Posted February 16, 2006 My first guess is that the fields and values don't match, especially since you're not specify which fields to actually use. Add an "or die( mysql_error() )" after you call to mysql_query() to get back the error message -- no need the post the entire script. Quote Link to comment https://forums.phpfreaks.com/topic/3445-unable-to-insert-data/#findComment-11828 Share on other sites More sharing options...
backinblack Posted February 18, 2006 Author Share Posted February 18, 2006 You were right!. The fields and values did not match. Thank you for your help! Quote Link to comment https://forums.phpfreaks.com/topic/3445-unable-to-insert-data/#findComment-11889 Share on other sites More sharing options...
fenway Posted February 18, 2006 Share Posted February 18, 2006 Glad you got it working -- in general, you should NEVER exclude the column list. Using the columns simply in the order that they are found in the table definition is bound to cause other problems in the future. Quote Link to comment https://forums.phpfreaks.com/topic/3445-unable-to-insert-data/#findComment-11890 Share on other sites More sharing options...
backinblack Posted February 18, 2006 Author Share Posted February 18, 2006 Ran into a new problem...thought I could do this by reading a tutorial on it but I am stuck. I have a page called profiles.php that pulls their name out of the database from the form that they filled out. I have added a user_id column set to integer, auto increment, and primary key so each person will be assigned a new user_id. On my profile.php page I have their names there already but I need to be able to link from their name to their profile page. Some how I have to get their id and I am lost. Can any one point me in the right direction. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/3445-unable-to-insert-data/#findComment-11923 Share on other sites More sharing options...
fenway Posted February 18, 2006 Share Posted February 18, 2006 I'm not sure I understand -- if you already have their name, then your must have accessed their user record, which also contains the user_id field, in which case you can simply write it out to the page. What part doesn't make sense? Quote Link to comment https://forums.phpfreaks.com/topic/3445-unable-to-insert-data/#findComment-11928 Share on other sites More sharing options...
backinblack Posted February 19, 2006 Author Share Posted February 19, 2006 [code]<?phpecho "<html> <head><title>Profiles</title></head> <body>";$host="xxxxxx";$user="xxxxxx";$password="xxxxxx";$database = "xxxxxx";$connection = mysql_connect($host,$user,$password) or die ("Could not retrieve information");$db = mysql_select_db("database",$connection) or die ("Could not make connection");$query = "SELECT * FROM driverprofiles";$result = mysql_query($query) or die("Sorry!Could not retrieve the information");$num=mysql_numrows($result);mysql_close();$i=0;while ($i < $num) {$fullname=mysql_result($result,$i,"fullname"); echo "$fullname <br>" ;$i++;}echo "</body></html>";?>[/code]From above code I am pulling there fullname from the database. Say I have ten names there but they do not have links to there profile yet. I am trying to figure how to be able to link to each individual name to go to their profile when it come from the database. Then some how with all there information in the database do I have to make another page that calls thier information? Quote Link to comment https://forums.phpfreaks.com/topic/3445-unable-to-insert-data/#findComment-11944 Share on other sites More sharing options...
fenway Posted February 19, 2006 Share Posted February 19, 2006 Like I said earlier, you have all of the fields from the table -- you're simply only pulling out "fullname". If you use mysql_fetch_assoc(), you can get at all of the fields, and write out whatever you want to the page. I'm not sure I understand what you're hung up on. Please clarify. Quote Link to comment https://forums.phpfreaks.com/topic/3445-unable-to-insert-data/#findComment-11976 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.