mattsmithadelaide Posted August 6, 2011 Share Posted August 6, 2011 Hi all, My mysql database is creating around 30 fields when i insert in an extra field on my cloning system. Could you please explain where i have gone wrong? <?php require_once('../Connections/databaseconnect.php'); ?> <?php if($_POST['add']) if($_POST['event']) if($_POST['hour']) if($_POST['minute']) if($_POST['ampm']) { $array=$_POST['add']; $title=$_POST['event']; $hr=$_POST['hour']; $min=$_POST['minute']; $am=$_POST['ampm']; foreach($array as $add) foreach($title as $event) foreach($hr as $hour) foreach($min as $minute) foreach($am as $ampm) { if(strlen($add)>0) { mysql_query("INSERT INTO `ade23566_event_timeline`.`template` ( `hour` , `minute` , `ampm` , `event` , `add_info` ) VALUES ( '$hour', '$minute', '$ampm', '$event', '$add' )"); } } } ?> <link rel="stylesheet" type="text/css" href="../content.css" /> <link rel="stylesheet" type="text/css" href="../menu_style.css" /> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Jquery Duplicate Fields Submit Form</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script type="text/javascript" src="http://ajax.googleapis.com/ ajax/libs/jquery/1.4.2/jquery.min.js"></script> <script type="text/javascript" src="reCopy.js"></script> <script type="text/javascript"> $(function(){ var removeLink = ' <a class="remove" href="#" onclick="$(this).parent().slideUp(function(){ $(this).remove() }); return false">remove</a>'; $('a.add').relCopy({ append: removeLink}); }); </script> <style type="text/css"> body{ font-family:Arial, Helvetica, sans-serif; font-size:13px; } .remove {color:#cc0000} .input{ border: solid 1px #006699; padding:3px} </style> </head> <body> <div id="logo"><img src="../ade_name.jpg" alt="Suni" class="center" /></div> <div id="site"> <div id="header"> <div class="menu"> <br><br> <ul> <li><a href="/home.html" target="_self" >Home</a> </li> <li><a href="#" target="_self" >About</a> <ul> <li><a href="#" target="_self">Who Are ADE?</a></li> <li><a href="#" target="_self">ADE</a></li> </ul> </li> <li><a href="#" target="_self" >Services</a> <ul> <li><a href="#" target="_self">Informal Events</a></li> <li><a href="#" target="_self">Formal Events</a></li> <li><a href="#" target="_self">School Events</a></li> </ul> </li> <li><a href="/client_login.html" target="_self" >Client Login</a> </li> <li><a href="/contact.html" target="_self" >Contact Us</a> </li> </ul> </div> </div> <br><br> <span class="menu"><br> </span> <div class="ex1" id="info"> </br></br></br></br> <p class="menu"><br> Please Place your songs in the below section! <form method="post" action=""> <p class="clone">Time Event Starts:<br/> <select name="hour[]" class='input'> <option value="12">12</option> <option value="11">11</option> <option value="10">10</option> <option value="9">9</option> <option value="8">8</option> <option value="7">7</option> <option value="6">6</option> <option value="5">5</option> <option value="4">4</option> <option value="3">3</option> <option value="2">2</option> <option value="1">1</option>:<br> </select>: <select name="minute[]" class='input'> <option value="00">00</option> <option value="05">05</option> <option value="10">10</option> <option value=15">15</option> <option value="20">20</option> <option value="25">25</option> <option value="30">30</option> <option value="35">35</option> <option value="40">40</option> <option value="45">45</option> <option value="50">50</option> <option value="55">55</option> </select> <select name="ampm[]" class='input'> <option value="am">AM</option> <option value="pm">PM</option> </select> <input type="text" name="event[]" class='input'/> Additional Info <input type="text" name="add[]" class='input'/></p> <p><a href="#" class="add" rel=".clone">Add More</a></p> <input type="submit" value=" Submit " /> </form> <br> </p> </div> <br><br> <div id="footer">Adelaide DJ Events 2011 Copyright<br>Contact Adelaide DJ Events via email on events@adelaidedjevents.com.au or call Matt on 0449861220</div></p> </div> <br><br><br> </body> </html> MOD EDIT: . . . tags added. Quote Link to comment https://forums.phpfreaks.com/topic/244046-mysql-creating-huge-amounts-of-data/ Share on other sites More sharing options...
AyKay47 Posted August 6, 2011 Share Posted August 6, 2011 1. your code needs cleaned up a bit... <?php require_once('../Connections/databaseconnect.php'); if(!empty($_POST['add']) && !empty($_POST['event']) && !empty($_POST['hour']) && !empty($_POST['minute']) && !empty($_POST['ampm'])) { $array = mysql_real_escape_string($_POST['add']); $title = mysql_real_escape_string($_POST['event']); $hr = mysql_real_escape_string($_POST['hour']); $min = mysql_real_escape_string($_POST['minute']); $am = mysql_real_escape_string($_POST['ampm']); $query = mysql_query("INSERT INTO `ade23566_event_timeline`.`template` ( `hour` , `minute` , `ampm` , `event` , `add_info` ) VALUES ( '$hour', '$minute', '$ampm', '$event', '$add' )"); if($query){ print "success"; }else{ trigger_error("Error:".mysql_error(),E_USER_ERROR); } } ?> 2. change your input names from arrays... "hour[]" to a string... "hour" as you will receive one value as it is Quote Link to comment https://forums.phpfreaks.com/topic/244046-mysql-creating-huge-amounts-of-data/#findComment-1253323 Share on other sites More sharing options...
mattsmithadelaide Posted August 7, 2011 Author Share Posted August 7, 2011 thankyou for your response! i inserted this into my php script and it didnt work. it does not output to the mysql database. What i want is system where a person can input multiple details of their event, and then if they want more events they can add them. If you would like to see what i mean here is the url http://adelaidedjevents.com.au/clone/timeline.php All i need is the script to only output each "line of information e.g time and the two text fields into seperate rows. I tried using tutorials but there is not much out there, Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/244046-mysql-creating-huge-amounts-of-data/#findComment-1253655 Share on other sites More sharing options...
AyKay47 Posted August 7, 2011 Share Posted August 7, 2011 the code i provided will work if incorporated correctly, have to tried outputting something in the if condition to make sure that it is being met...any errors? Quote Link to comment https://forums.phpfreaks.com/topic/244046-mysql-creating-huge-amounts-of-data/#findComment-1253819 Share on other sites More sharing options...
mattsmithadelaide Posted August 7, 2011 Author Share Posted August 7, 2011 there are no errors, simply when i use this code it sends out one row in myphp. What i need is if i click the add more button if i put two rows of data on the screen then two rows will show on the mysql database. at the moment it is picking the last inputs i put it. i also changed your script in the mysql values section to VALUES ( '$hr', '$min', '$am', '$title', '$array' )"); I don't know whether that could have changed it. Quote Link to comment https://forums.phpfreaks.com/topic/244046-mysql-creating-huge-amounts-of-data/#findComment-1253912 Share on other sites More sharing options...
mattsmithadelaide Posted August 11, 2011 Author Share Posted August 11, 2011 so to clarify, when i clone multiple fields they come up as large amounts of data, I need each clone to print to the database as a seperate row. If anyone can finish this with me with this i will make it in someway financially advantageous. Cheers Quote Link to comment https://forums.phpfreaks.com/topic/244046-mysql-creating-huge-amounts-of-data/#findComment-1255642 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.