Jump to content

cant insert data into mysql


christophe

Recommended Posts

Hi i have this script but it will not let me insert the data into mysql can anyone see were i am going wrong

 


<html>
<head>
</head>
<body>

<?php
if (!isset($_POST['submit'])) {
// form not submitted
?>


<table width="700" border="0" cellspacing="5">
  <tr>
    <td align="right">
    
    <form action="<?=$_SERVER['PHP_SELF']?>" method="post">
    
    Name:</td>
    
    <td><input type="text" name="name" size="30"></td>
  </tr>
  <tr>
    <td align="right">Surname:</td>
    <td><input type="text" name="surname" size="30"></td>
  </tr>
  <tr>
    <td align="right">Username:</td>
    <td><input type="text" name="userrname" size="30"></td>
  </tr>
  <tr>
    <td align="right">Headline:</td>
    <td><input type="text" name="headline" size="30"></td>
  </tr>
  <tr>
    <td align="right">About Me:</td>
    <td><input type="text" name="aboutme" height="30" size="30"></td>
  </tr>
  <tr>
    <td align="right">i'd like to meet:</td>
    <td><input type="text" name="meet" size="30"></td>
  </tr>
  <tr>
    <td align="right">Music:</td>
    <td><input type="text" name="music" size="30"></td>
  </tr>
  <tr>
    <td align="right">Films:</td>
    <td><input type="text" name="films" size="30"></td>
  </tr>
  <tr>
    <td align="right">T.V:</td>
    <td><input type="text" name="tv" size="30"></td>
  </tr>
  <tr>
    <td align="right">Books</td>
    <td><input type="text" name="books" size="30"></td>
  </tr>
  <tr>
    <td align="right">Heroes:</td>
    <td><input type="text" name="heroes" size="30"></td>
  </tr>
  <tr>
    <td></td> 
    <td><input type='submit' value='Submit'></td>
  </tr>
  </form>
</table>

<?php
}
else{
// form submitted
// set server access variables
$host = "*********";
$user = "**********";
$pass = "**********";
$db = "**********";

    // open connection
    $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");
    
    // select database
    mysql_select_db($db) or die ("Unable to select database!");
    
    // create query
    $query = "INSERT INTO members_profile (name, surname, username, headline, aboutme, meet, music, films, tv, books, heroes) VALUES ('$name', '$surname', '$username', '$headline', '$aboutme', '$meet', '$music', '$films', '$tv', '$books', '$heroes')";
    
    // execute query
    $result = mysql_query($query)or die("Error in query: $query. ".mysql_error()); 
    
    // print message with ID of inserted record
    echo "New record inserted with ID ".mysql_insert_id();
    echo "<br><br><a href='#' onClick='history.go(-1)'>Back</a>";
    
    // close connection
    mysql_close($connection);
}
    
    
?>

</body>
</html>

 

 

I have the exact same script on another program and it works fine. The only thing different is I have put the html form into a table.

 

Thanks

Alex

Link to comment
Share on other sites

Im also using the same database as the original form

 

Forms don't have databases, so I'm not sure what you mean exactly.

 

Have you changed all the variables within your query to corilate with the fact they are comming from the $_POST array? ie; Instead of $name you need $_POST['name'].

 

Also, place this at the very top of the script.

 

<?php error_reporting(E_ALL) ; ini_set('display_errors','1'); ?>

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.