note 86700 added to mysql.examples

From: Date: Thu, 30 Oct 2008 16:00:31 +0000
Subject: note 86700 added to mysql.examples
Groups: php.notes 
Request: Send a blank email to php-notes+get-145970@lists.php.net to get a copy of this message
//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> */ ---- Server IP: 69.147.83.197 Probable Submitter: 80.37.147.151 ---- Manual Page -- http://www.php.net/manual/en/mysql.examples.php Edit -- https://master.php.net/note/edit/86700 Del: integrated -- https://master.php.net/note/delete/86700/integrated Del: useless -- https://master.php.net/note/delete/86700/useless Del: bad code -- https://master.php.net/note/delete/86700/bad+code Del: spam -- https://master.php.net/note/delete/86700/spam Del: non-english -- https://master.php.net/note/delete/86700/non-english Del: in docs -- https://master.php.net/note/delete/86700/in+docs Del: other reasons-- https://master.php.net/note/delete/86700 Reject -- https://master.php.net/note/reject/86700 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#145970) next »