Jump to content


Photo

Unable to insert data


  • Please log in to reply
7 replies to this topic

#1 backinblack

backinblack
  • Members
  • PipPip
  • Member
  • 18 posts

Posted 16 February 2006 - 02:57 AM

For some reason I cannot add information into mysql. Can some one help me figure out what is wrong. Here is my 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>


#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 16 February 2006 - 07:51 PM

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.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 backinblack

backinblack
  • Members
  • PipPip
  • Member
  • 18 posts

Posted 18 February 2006 - 01:16 AM

You were right!. The fields and values did not match. Thank you for your help!

#4 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 18 February 2006 - 02:33 AM

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.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#5 backinblack

backinblack
  • Members
  • PipPip
  • Member
  • 18 posts

Posted 18 February 2006 - 09:17 PM

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.

#6 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 18 February 2006 - 10:21 PM

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?
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#7 backinblack

backinblack
  • Members
  • PipPip
  • Member
  • 18 posts

Posted 19 February 2006 - 01:15 PM

<?php
echo "<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>";
?>



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?

#8 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 19 February 2006 - 08:50 PM

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.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users