note 86700 deleted from mysql.examples by danbrown
| From: | danbrown@php.net | Date: | Thu, 30 Oct 2008 16:04:24 +0000 |
| Subject: | note 86700 deleted from mysql.examples by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-145971@lists.php.net to get a copy of this message | ||
Note Submitter: cpkalex at hotmail dot com
Reason: bad code
----
//Form processing
<?php
//MySQL Connection
$con = mysql_connect("localhost", "user", "pass");
if (!$con) {
die('Could not connect. Reason: ' . mysql_error());
}
//Database selection
mysql_select_db("Users", $con);
//Insert data
$sql_1="INSERT INTO user (name, surname) VALUES
('$_POST[name]','$_POST[surname]')";
if (!mysql_query($sql_1,$con)) {
die('Error in the first insertion: ' . mysql_error());
}
else {
$index = mysql_query("SELECT id FROM user
WHERE (name='$_POST[name]'
AND surname='$_POST[surname]')");
while($row_index = mysql_fetch_array($index)) {
$num_index = $row_index['id'];
}
$sql_2="INSERT INTO userdata (login, password, email, iduser)
VALUES
('$_POST[login]','$_POST[password]','$_POST[email]','$num_index')";
if (!mysql_query($sql_2,$con)) {
die('Error in the second insertion: ' . mysql_error());
}
else {
echo "Your data has been recorded.";
}
}
//List of users
echo "<br />****************<br />These are the registered users by now: <br
/>";
$result_1 = mysql_query("SELECT * FROM user");
echo "<table border='1'><tr>
<th>Name</th>
<th>Surname</th>
<th>User</th>
<th>e-Mail</th></tr>";
while($row_1 = mysql_fetch_array($result_1)) {
echo "<tr>";
echo "<td>" . $row_1['name'] . "</td>";
echo "<td>" . $row_1['surname'] . "</td>";
$acc = $row_1['id'];
$result_2 = mysql_query("SELECT * FROM userdata WHERE (iduser='$acc')");
while($row_2 = mysql_fetch_array($result_2)) {
echo "<td>" . $row_2['login'] . "</td>";
echo "<td>" . $row_2['email'] . "</td>";
}
echo "</tr>";
}
echo "</table>";
//Close connection
mysql_close($con);
?>
//This is the action file of a form like this:
/*
<form action="senddata.php" method="post">
Name: <input type="text" name="name" /><br />
Surname: <input type="text" name="surname" /><br />
Login: <input type="text" name="login" /><br />
Password: <input type="password" name="password" /><br />
e-Mail: <input type="text" name="email" /><br />
<input type="submit" value="Send data" />
</form>
*/