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
https://forums.phpfreaks.com/topic/37304-cant-insert-data-into-mysql/
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'); ?>

Archived

This topic is now archived and is closed to further replies.

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