Jump to content


Photo

Mysql / PHP Insert problem


  • Please log in to reply
4 replies to this topic

#1 darvexwomp

darvexwomp
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 09 October 2006 - 03:26 AM

I have a basic form that I am collecting data with and trying to pass the variables to a PHP script that will insert the values into a database.  It seems to work except none of the data is being inserted in the database - it gets filled with blank values and not the ones from the form.  I have been pulling my hair out with this and I am sure it is something simple.  Any help would be greatly appericated.  Here is a link to the form:  http://www.darvex.co...nator_form.php¬† Here is the PHP script:

<?php
include("dbconnect.php");
if ($submit = "Submit")
{
$query = "insert into alternator (name,driveline,email,transmission,ac,mounting_style,make,model,year,mandate,cylinders,displacement,displacement_type,requirments,original_engine,total_output,add_req,pulley_type,grooves,location,idle)
values ('$name', '$driveline', '$email', '$transmission', '$ac', '$mounting_style', '$make', '$model', '$year', '$mandate', '$cylinders', '$displacment', '$displacement_type', '$requirments', '$original_engine', '$total_output', '$add_req', '$pulley_type', '$grooves', '$location', '$idle')"
;
mysql_query($query) or
die (mysql_error());
?> Thanks
<?php
}
else
{
include("alternator_form.php");
}
?>


#2 trench coat man

trench coat man
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 09 October 2006 - 04:37 AM

i have an insert page just like yours, hope you find something here. the only difference that i see is that im using isset($_POST[]) in the "if statement"

<html>
<head>
<title>Add Mysql User</title>
<meta http-equiv = "Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php
if(isset($_POST['add']))
{
  include 'library/config.php';
  include 'library/dbopen.php';
  
  $username = $_POST['username'];
  $password = $_POST['password'];
  
  $query = "INSERT INTO users (name, password) VALUES ('$username', PASSWORD
  ('$password'))";
  mysql_query($query) or die ('error! insert query failed!');
  
  $query = "FLUSH PRIVILEGES";
  mysql_query($query) or die ('error! insert query failed!');
  
  include 'library/close.php';
  echo 'New MySql added!';
}
else
{
?>
<form method="post">
<table width="400" border="0" cellspacing="1" cellpadding="2">
<tr>
<td width="100">Username</td>
<td><input name="username" type="text" id="username"></td>
</tr>
<tr>
<td width="100">Password</td>
<td><input name="password" type="password" id="password"></td>
</tr>
<tr>
<td width="100">&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td width="100">&nbsp;</td>
<td><input name="add" type="submit" id="add" value="Add New User"></td>
</tr>
</table>
</form>
<?php
}
?>
</body>
</html>


#3 fenway

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

Posted 09 October 2006 - 05:58 AM

Where are these variables coming from?
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#4 darvexwomp

darvexwomp
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 09 October 2006 - 02:05 PM

The variables are coming from a form - Here is a link to it:  http://www.darvex.co...rnator_form.php


#5 fenway

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

Posted 10 October 2006 - 03:22 PM

Well, those would be in a POST hash... I'm not seeing that in your script.
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