kcm2611
Members-
Posts
10 -
Joined
-
Last visited
Never
Profile Information
-
Gender
Not Telling
kcm2611's Achievements
Newbie (1/5)
0
Reputation
-
your right that query doesnt do anything should have deleted that...
-
Mod-jay that didn't work any other thoughts?
-
Hi I am looking for help with a working script to input multiple lines of data , but i am looking for each line of data to have the $_SESSION[userid] entered into each line, ie into the table $_SESSION[userid], name, surname, age Many Thanks <? include "include/session.php"; include "include/z_db.php"; // check the login details of the user and stop execution if not logged in require "check.php"; // If member has logged in then below script will be execuated. // let us collect all data of the member $row=mysql_fetch_object(mysql_query("select * from plus_signup where userid='$_SESSION[userid]'")); if(isset($_POST['submit'])) { foreach($_POST['person'] as $person) { $name= mysql_real_escape_string($person['name']); $surname= mysql_real_escape_string($person['surname']); $age= mysql_real_escape_string($person['age']); $values[] = "('$name', '$surname', '$age')"; } $query = "INSERT INTO plus_signup (name,surname,age) VALUES " . implode(', ', $values); $result = mysql_query($query) or die("Error!<br />Query: $query<br />Error: " . mysql_error()); } ?> <form method="POST" action='multi.php' name=""> <table> <tr> <td>Name<input type="text" name="person[0][name]"></td> <td>surname<input type="text" name="person[0][surname]"></td> <td>age<input type="text" name="person[0][age]"></td> </tr> <tr> <td>name<input type="text" name="person[1][name]"></td> <td>surname<input type="text" name="person[1][surname]"></td> <td>age<input type="text" name="person[1][age]"></td> </tr> <tr> <td>name<input type="text" name="person[2][name]"></td> <td>surname<input type="text" name="person[2][surname]"></td> <td>age<input type="text" name="person[2][age]"></td> </tr> </table> <td><p> <input type="submit" name="submit" value="add"> </p> <p> </p>| <a href=update-profile.php>back</a>| </form> <? require "bottom.php"; ?> <center><br>| <a href=update-profile.php>back</a>|<br></center> </body> </html>
-
Thanks again for all your help How can I now add the userid='$_SESSION[userid] to the table that i am using for my multiple line form, from the table that the user logs onto . i.e the person loged in then populates the multiple form & they all have the loged in users id in there table I have tried combining the multiple line form table with the login table but I cant seem to get it to work, but if i have 2 different tables it works ok ie inserting 'plus_signup' instead of 'plus_user' $query = "INSERT INTO plus_user (name,surname,age) VALUES " . implode(', ', $values); <? include "include/session.php"; include "include/z_db.php"; // check the login details of the user and stop execution if not logged in require "check.php"; // If member has logged in then below script will be execuated. // let us collect all data of the member $row=mysql_fetch_object(mysql_query("select * from plus_signup where userid='$_SESSION[userid]'")); if(isset($_POST['submit'])) { foreach($_POST['person'] as $person) { $name= mysql_real_escape_string($person['name']); $surname= mysql_real_escape_string($person['surname']); $age= mysql_real_escape_string($person['age']); $values[] = "($name', '$surname', '$age')"; } $query = "INSERT INTO plus_user (name,surname,age) VALUES " . implode(', ', $values); $result = mysql_query($query) or die("Error!<br />Query: $query<br />Error: " . mysql_error()); } ?> <form method="POST" action='multi.php' name=""> <table> <tr> <td>Name<input type="text" name="person[0][name]"></td> <td>surname<input type="text" name="person[0][surname]"></td> <td>age<input type="text" name="person[0][age]"></td> </tr> <tr> <td>name<input type="text" name="person[1][name]"></td> <td>surname<input type="text" name="person[1][surname]"></td> <td>age<input type="text" name="person[1][age]"></td> </tr> <tr> <td>name<input type="text" name="person[2][name]"></td> <td>surname<input type="text" name="person[2][surname]"></td> <td>age<input type="text" name="person[2][age]"></td> </tr> </table> <td><p> <input type="submit" name="submit" value="add"> </p> <p> </p>| <a href=update-profile.php>back</a>| </form> <? require "bottom.php"; ?> <center> <br>| <a href=update-profile.php>back</a>|<br></center> </body> </html>
-
Hi thanks for all the help on this it working a treat.. I have one more question if there is a line of fields that is not completed how can I stop it inserting a blank set of fields Many thanks again
-
hopefully this will be better to read now, have added those quotes & now get this error Error! Query: INSERT INTO plus_signup (name,surname,age) VALUES ('n0', 's0', 'a0'), ('n1', 's1', 'a1'), ('n2', 's2', 'a2') Error: Duplicate entry '' for key 1 <?php error_reporting (E_ALL); include "include/z_db.php"; include "include/session.php"; if(isset($_POST['submit'])) { foreach($_POST['person'] as $person) { $name= mysql_real_escape_string($person['name']); $surname= mysql_real_escape_string($person['surname']); $age= mysql_real_escape_string($person['age']); $values[] = "('$name', '$surname', '$age')"; } $query = "INSERT INTO plus_signup (name,surname,age) VALUES " . implode(', ', $values); $result = mysql_query($query) or die("Error!<br />Query: $query<br />Error: " . mysql_error()); } ?> <form method="POST" action='multi.php' name="multi"> <table> <tr> <td>name<input type="text" name="person[0][name]"></td> <td>surname<input type="text" name="person[0][surname]"></td> <td>age<input type="text" name="person[0][age]"></td> </tr> <tr> <td>name<input type="text" name="person[1][name]"></td> <td>surname<input type="text" name="person[1][surname]"></td> <td>age<input type="text" name="person[1][age]"></td> </tr> <tr> <td>name<input type="text" name="person[2][name]"></td> <td>surname<input type="text" name="person[2][surname]"></td> <td>age<input type="text" name="person[2][age]"></td> </tr> </table> <td><input type="submit" name="submit" value="add"> </form>
-
getting closer I feel I now get this error when I fill all fields in Error! Query: INSERT INTO plus_signup (name,surname,age) VALUES ('n0', 's0', a0), ('n1', 's1', a1), ('n2', 's2', a2) Error: Unknown column 'a0' in 'field list' I have a field 'age' <?php error_reporting (E_ALL); include "include/z_db.php"; include "include/session.php"; if(isset($_POST['submit'])) { foreach($_POST['person'] as $person) { $name= mysql_real_escape_string($person['name']); $surname= mysql_real_escape_string($person['surname']); $age= mysql_real_escape_string($person['age']); $values[] = "('$name', '$surname', $age)"; } $query = "INSERT INTO plus_signup (name,surname,age) VALUES " . implode(', ', $values); $result = mysql_query($query) or die("Error!<br />Query: $query<br />Error: " . mysql_error()); } ?> <form method="POST" action='multi.php' name="multi"> <table> <tr> <td>name<input type="text" name="person[0][name]"></td> <td>surname<input type="text" name="person[0][surname]"></td> <td>age<input type="text" name="person[0][age]"></td> </tr> <tr> <td>name<input type="text" name="person[1][name]"></td> <td>surname<input type="text" name="person[1][surname]"></td> <td>age<input type="text" name="person[1][age]"></td> </tr> <tr> <td>name<input type="text" name="person[2][name]"></td> <td>surname<input type="text" name="person[2][surname]"></td> <td>age<input type="text" name="person[2][age]"></td> </tr> </table> <td><input type="submit" name="submit" value="add"> </form>
-
Thanks Wildteen88 for your help, I am not sure if I have still got something wrong but still doesnt work any suggestions thanks <?php error_reporting (E_ALL); include "include/z_db.php"; include "include/session.php"; if(isset($_POST['submit'])) { foreach($_POST['person'] as $person) { $name = mysql_real_escape_string($person['name']); $surname = mysql_real_escape_string($person['surname']); $age = (int) $person['age']; $values[] = "('$name', '$surname', $age)"; } $query = "INSERT INTO plus_signup (name,surname,age) VALUES " . implode(', ', $values); $result = mysql_query($query); } ?> <form method="POST" action='multi.php' name="multi"> <table> <tr> <td>name<input type="text" name="prrson[0][name]"></td> <td>surname<input type="text" name="person[0][surname]"></td> <td>age<input type="text" name="person[0][age]"></td> </tr> <tr> <td>name<input type="text" name="person [1][name]"></td> <td>surname<input type="text" name="person[1][surname]"></td> <td>age<input type="text" name="person[1][age]"></td> </tr> <tr> <td>name<input type="text" name="person [2][name]"></td> <td>surname<input type="text" name="person[2][surname]"></td> <td>age<input type="text" name="person[2][age]"></td> </tr> </table> <td><input type="submit" name="submit" value="add"> </form>
-
I am trying to write a script to add multiple lines into the database with one submit, this is my effort - can anyone suggest anything better that works Many Thanks <?php error_reporting (E_ALL); include "include/z_db.php"; // $query = "INSERT INTO table(name,surname,age)VALUES"; foreach ($_POST["name"] as $key => $value) { $query = "('$key','$_POST[surname][$key]','$_POST[age][$key]')"; $result = mysql_query($query)or die(mysql_error()); if (isset($_POST['addto'])) { $name = $_POST['name']; $surname = $_POST['surname']; $age = $_POST['age']; if ($age == '0' && $surname == '0') { echo "0"; } else { $queries = array(); for ($i = 0; $i < count($name); $i++) { if (!get_magic_quotes_gpc()) { $name[$i] = addslashes($name[$i]); $surname[$i] = addslashes($surname[$i]); $age[$i] = addslashes($age[$i]); # etc } $queries[] = "('$userid ','$name[$i]','$surname[$i]','$age[$i]')"; } if (count($queries) == 0) { # Nothing passed # exit } $piece = implode(", ", $queries); $query = "INSERT INTO 'TABLE' (id,name,surname,age) VALUES $piece"; $result = mysql_query($query) or die(mysql_error()); } } ?> <form action='result.php'method="POST"> <table> <tr> <td>name<input type="text" name="name[]"></td> <td>surname<input type="text" name="qty[]"></td> <td>age<input type="text" name="qty2[]"></td> </tr> <tr> <td>name<input type="text" name="name[]"></td> <td>surname<input type="text" name="qty[]"></td> <td>age<input type="text" name="qty2[]"></td> </tr> <tr> <td>name<input type="text" name="name[]"></td> <td>surname<input type="text" name="qty[]"></td> <td>age<input type="text" name="qty2[]"></td> </tr> <tr> <td>name<input type="text" name="name[]"></td> <td>surname<input type="text" name="qty[]"></td> <td>age<input type="text" name="qty2[]"></td> </tr> <tr> <td>mane<input type="text" name="name[]"></td> <td>surname<input type="text" name="qty[]"></td> <td>age<input type="text" name="qty2[]"></td> </tr></table> <td><input type="submit" name="submit" value="add">
-
Hi I am looking for help with this script to update mysql db, the script will not update data but gets data from the db Many thanks ############### Code <?php $host="localhost"; // Host name $username=""; // Mysql username $password=""; // Mysql password $db_name="test"; // Database name $tbl_name="test_mysql"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // get value of id that sent from address bar $id=$_GET['id']; // Retrieve data from database $sql="SELECT * FROM $tbl_name WHERE id='$id'"; $result=mysql_query($sql); $rows=mysql_fetch_array($result); ?> <table width="400" border="0" cellspacing="1" cellpadding="0"> <tr> <form name="form1" method="post" action="update_ac.php"> <td> <table width="100%" border="0" cellspacing="1" cellpadding="0"> <tr> <td> </td> <td colspan="3"><strong>Update data in mysql</strong> </td> </tr> <tr> <td align="center"> </td> <td align="center"> </td> <td align="center"> </td> <td align="center"> </td> </tr> <tr> <td align="center"> </td> <td align="center"><strong>Name</strong></td> <td align="center"><strong>Lastname</strong></td> <td align="center"><strong>Email</strong></td> </tr> <tr> <td> </td> <td align="center"><input name="name" type="text" id="name" value="<? echo $rows['name']; ?>"></td> <td align="center"><input name="lastname" type="text" id="lastname" value="<? echo $rows['lastname']; ?>" size="15"></td> <td><input name="email" type="text" id="email" value="<? echo $rows['email']; ?>" size="15"></td> </tr> <tr> <td> </td> <td><input name="id" type="hidden" id="id" value="<? echo $rows['id']; ?>"></td> <td align="center"><input type="submit" name="Submit" value="Submit"></td> <td> </td> </tr> </table> </td> </form> </tr> </table> <? // close connection mysql_close(); ?> ############### Code [i]update_ac.php[/i] <?php $host="localhost"; // Host name $username=""; // Mysql username $password=""; // Mysql password $db_name="test"; // Database name $tbl_name="test_mysql"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // update data in mysql database $sql="UPDATE $tbl_name SET name='$name', lastname='$lastname', email='$email' WHERE id='$id'"; $result=mysql_query($sql); // if successfully updated. if($result){ echo "Successful"; echo "<BR>"; echo "<a href='list_records.php'>View result</a>"; } else { echo "ERROR"; } ?>