Jump to content

Unable to insert data


backinblack

Recommended Posts

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]
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

[code]
<?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>";
?>


[/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?
Link to comment
Share on other sites

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