PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
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 its also using the same server. The only thing different is I have put the html form into a table.
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
will always be true, and therefore your INSERT code will never run.
second point is that unless you have global variables turned on (which can be a security risk), you have not collected the data from the $_POST array. if global variables is turned off you would need to assign each of the vars from $_POST to your variables
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
For those who would like the full script here it is and it works like a charm:)
Apologies feyd but i have'nt got time to add the code properly
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]