Jump to content

Trying to connect to DB part 2


VinceGledhill

Recommended Posts

Hi People.

 

Thanks to everyone that helped me yesterday with my file that finally connected to the database.

 

However, I have added a new field to my DB and now get further problems. 

 

Here is the error message I am getting after I added the "ppr" stuff to both files.

 

Please could someone look at my code and tell me where I'm going wrong.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>

<body>
<?php include "config01.php"?>

<form name = 'form1' method = 'post' action='config01.php'>
<table width="700" border="1" cellspacing="5" cellpadding="5">
  <caption>
    Submit Your Airfield Details
  </caption>
  <tr>
    <td width="100"> </td>
    <td width="200">Your Name</td>
    <td width="200"><input type='text' name='username' maxlength='30'></td>
    <td width="100"> </td>
  </tr>
  <tr>
    <td> </td>
    <td>Height Above MSL</td>
    <td><input type='text' name='height_above'maxlength= '30'></td>
    <td> </td>
  </tr>
  <tr>
    <td> </td>
    <td>Mb Difference</td>
    <td><input type='text' name='mb_diff'maxlength='40'></td>
    <td> </td>
  </tr>
  <tr>
    <td> </td>
    <td>Alternative Airfield</td>
    <td><input type='text' name='alternative' maxlength='30'></td>
    <td> </td>
  </tr>
  <tr>
    <td> </td>
    <td>PPR</td>
    <td><input type='radio' name='ppr' value="Y"/>
    Yes
      <input type='radio' name='ppr' value="N" />
      No</td>
    <td> </td>
  </tr>
  <tr>
    <td><input type='submit' name='submit' value='post' /></td>
    <td> </td>
    <td> </td>
    <td> </td>
  </tr>
</table>
</form>


</body>
</html>

 

Then the code from config01.php

<?php
$host = 'localhost';
$usr = "VinnyG";
$password = 'thepassword';
$db_name = 'sitename';

$username = $_POST["username"];
$height_above = $_POST["height_above"];
$mb_diff = $_POST["mb_diff"];
$alternative = $_POST["alternative"];
$ppr = $_POST["ppr"];

//connect to database
mysql_connect ("$host","$usr","$password") or die ('Error During Connect:<br>'.mysql_error());
mysql_select_db ("$db_name") or die ('Error Selecting DB:<br>'.mysql_error());

/*
$sql01 = "INSERT INTO users SET username = '$username',height_above = '$height_above', mb_diff = $mb_diff, alternative = $alternative";
$result=mysql_query($sql01);
*/
//mysql_query("INSERT INTO users VALUES ('$username','$height_above','$mb_diff','$alternative')");
//mysql_query("INSERT INTO users (username, height_above, mb_diff, alternative) VALUES ('$username', '$height_above', '$mb_diff', '$alternative'"); 
//$insert_query = "INSERT INTO users (username, height_above, mb_diff, alternative) VALUES ('$username', '$height_above', '$mb_diff', '$alternative')";
//$insert_action = mysql_query($insert_query) or die ('Error Dring Insert :<br>'.mysql_error().'<br><br>Error occured running the following code :<br>'.$insert_query);

//mysql_query("INSERT INTO users VALUES ('$username','$height_above','$mb_diff','$alternative')"); CHANGES FOLLOW THIS LINE . . 
$query = "INSERT INTO users (username, height_above, mb_diff, alternative, ppr) VALUES ('$username', '$height_above', '$mb_diff', '$alternative', '$ppr'";
if( !$result = mysql_query($query) ) {
     echo "<br>Query: $query<br>Produced error: " . mysql_error() .'<br>';
} else {
     echo "Query ran and inserted " . mysql_affected_rows() . "row(s).";
}
?>

 

I only added the one thing and I've gone and broken it already.  It was working last night too.. :-(

 

 

Link to comment
Share on other sites

Hi Muddy_Funster

 

Sorry I don't know what you mean about closing the braces round the INSERT values.  everywhere I've got a ( I've got a corresponding ) as far as I can see.  Sorry for being STUPID. 

 

All I have inserted is the "ppr" into the form which it two radio buttons for "Y" and "N" and then into the various places in the config01.php file.

 

If you load the files and do a search for "ppr" then that's what I've inserted.

 

Thanks for you help.

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.