PHP - Help With Textbox Arrays
I am currently writing a script, well, attempting to write a script where the user is able to add an unlimited amount of text boxes via javascript:
Code: [Select] var i = 1; function AddTxtBox() { new_textbox.innerHTML = new_textbox.innerHTML +"<br />Misc Item " + i + ": <input type='text' name='prod_misc[]' placeholder='Misc Product Info' />" i++; } The js code works fine adding the text boxes. My first question is: in the "name" field; the name I have is "prod_misc[]" is that correct for adding the input into an array? Second question: I want to input that data from the "prod_misc[]" array into SQL, namely PostgreSQL. Should I use a "for()" loop to extract each key of data from the array "prod_misc[]"? If so, what syntax do I use to input an array of data like that into SQL? Thanks so much in advance for this help... I am in great need and it's very appreciative. Similar TutorialsI'm having troubling with trying to create a function to spit out a single array with the following array. I can write it in a away that looks through the arrays manually. the results i am trying to generate is that each item in generated array. Array to convert array( "account" => array( "login", "register", "logout", "edit", ), "p" => array( "report", ), "array1.0" => array( "array2.0" => array( "array3.0", "array3.1 ), "array2.1", ), generating the array will look like this
Array ( [0] => account [1] => account/login [2] => account/register [3] => account/logout [4] => account/edit [5] => p [6] => p/report [7] => array1.0 [8] => array1.0/array2.0 [9] => array1.0/array2.0/array3.0 [10] => array1.0/array2.0/array3.1 [11] => array1.0/array2.1 ) The idea is that id generates a single array with combined labels and arrays inside, etc. I just can't figure out how to create a script that will create this array even If I add a new value or array.
I have this thing that i am trying to make but i cant get it to work.. can anyone help? Code: [Select] function sql_read( $dbname,$dbusername,$dbpassword ) { $names = array(); $password = array(); $connect = @mysql_connect("mysql11.000webhost.com",$dbusername,$dbpassword) or die("Could Not Connect"); @mysql_select_db ($dbname) or die("Could not find DataBase"); $query = mysql_query("select * from users"); $numrows = mysql_num_rows($query); if ($numrows > 0){ while($row = mysql_fetch_assoc($query)){ $names[] = $row["uname"]; $password[] = $row["password"]; $id = $row["id"]; } $return = array($names,$password,$id); }else{ $return = array(); } return $return[]; } $names = array(); $names = sql_read("XXXXXX","XXXXXX","XXXXXXX")[0]; The error i get is Code: [Select] Parse error: syntax error, unexpected '[' in /home/a5480952/public_html/sql/index.php on line 28 Line 28 is "$names = sql_read("XXXXXX","XXXXXX","XXXXXXX")[0];" Please help... i REALLLLD need help with this.. ask questions if you want to know more about what i am trying to do... thanks! I have two arrays, both with the same key values. I'd like to combine them. So for instance... Code: [Select] <?php $array1['abcd'] = array( 'value1' => "blah", 'value2' => "blahblah"); $array1['efgh'] = array( 'value1' => "ha", 'value2' => "haha", 'valuex' => "xyz"); $array2['abcd'] = array('value3' => "three", 'value4' => "four"); $array2['efgh'] = array( 'value3' => "hohoho", 'value6' => "six6"); function combine_arrays($array1,$array2) { //*combining* return $single_array; } echo "<pre>"; print_r(combine_arrays($array1,$array2)); echo "</pre>"; /* would produce ['abcd'] = ( 'value1' => "blah", 'value2' => "blahblah", 'value3' => "three", 'value4' => "four" ) ['efgh'] = ( 'value1' => "ha", 'value2' => "haha", 'valuex' => "xyz", 'value3' => "hohoho", 'value6' => "six6" ) */ ?> What's the easiest way to do this? I have a problem where I am unable to display a DB entry that for exampe says "John Doe". The code I am using is: Code: [Select] <tr> <td>Agent Full Name:</td> <td><input type="text" name="fullname" value='.$agentdata['fullname'].'></td> </tr> The output shows "John" instead of "John Doe", have I missed something here Hi all i have been trying for 6 hours to write some code that will show a text box and the user puts in there id then it provides a link with the id in the middle of it so say the id is 111555 the link is http://example.com.au/data/users/111555/2011/1/1 i want the user to insert their id and do if the id 343034 the link is http://example.com.au/data/users/343034/2011/1/1 can any one give me the code to this i have gotten no where from tutorials please matt <INPUT TYPE = "Text" VALUE ="0" ID = "username2" NAME = "username2"> <?php $value1 = $_POST['username2']; $nine=$value1; $codx =$characters[$nine]->name; ?> Im tring to get '0' in username2 inputbox readit in php $nine $codx =$characters[$nine]->name;
It only works like this <?php $nine='0' $codx =$characters[$nine]->name; ?>
What i need is to get the users
the $nine will hold the number
How do I read the user input my textbox post pulls the input $nine = $_POST['username2']; $codx =$characters[$nine]->name; i noticed it wouldn't work it only works this way
$nine='0';
Let me know how to read in user input
sorry to repeat i needed to explain none I would appreciate if someone could figure this out or tell me the easiest way to do this. I need a count up counter that appears in a textbox so I can record the time a user is on a page. On a side note, I do have their Start and finish time timestamp recorded in myphpadmin database but I am looking for the easiest (or best) way to do this. Any advice or scripts would be very much appreciated.
Thanks in advanced.
I did find this counter that works but the numbers appear 0.0.1 if counting up. I don't want to confuse the user. I really want to display to the user how long they was on a certain page.
<script> $(document).ready(function() { var time = '00:00:00', parts = time.split(':'), hours = +parts[0], minutes = +parts[1], seconds = +parts[02], input = $('#timeInput'); var timer = setInterval(function(){ seconds++; if(seconds == 60) { seconds = 00; minutes++; if(minutes == 60) { minutes = 00; hours++; } } var newTime = hours + ":" + minutes + ":" + seconds; $('#timeInput').val(newTime); }, 1000); }); </script> <input type="text" name="time" id="timeInput"/> Like Youtube; when submitting a video; You can insert words into a Textbox named Tags. Each space you leave is considered the start of a new word. How can I do this using PHP + MYSQL. Thanks! Hi, I am working on a script that will add 3 sets of information to a MySQL table. I had a script that had the fields of username password and password2. It worked just fine when password2 was used for verification to make sure you typed it right. But now I want to take password and turn it into a new data field that is submitted into the new row with the other information. The problem is it wont add the row. The script says it worked just fine but i check the db and no new row. here it is: <?php // Connects to your Database mysql_connect("//", "//", "//") or die(mysql_error()); mysql_select_db("//") or die(mysql_error()); //This code runs if the form has been submitted if (isset($_POST['submit'])) { //This makes sure they did not leave any fields blank if (!$_POST['username'] | !$_POST['pass'] | !$_POST['pass2'] ) { die('You did not complete all of the required fields'); } // checks if the username is in use if (!get_magic_quotes_gpc()) { $_POST['username'] = addslashes($_POST['username']); } $usercheck = $_POST['username']; $check = mysql_query("SELECT username FROM users WHERE username = '$usercheck'") or die(mysql_error()); $check2 = mysql_num_rows($check); //if the name exists it gives an error if ($check2 != 0) { die('Sorry, the username '.$_POST['username'].' is already in use.'); } // this makes sure both passwords entered match if ($_POST['pass'] != $_POST['pass']) { die('Your passwords did not match. '); } // here we encrypt the password and add slashes if needed $_POST['pass'] = md5($_POST['pass']); if (!get_magic_quotes_gpc()) { $_POST['pass'] = addslashes($_POST['pass']); $_POST['username'] = addslashes($_POST['username']); $_POST['pass2'] = addslashes($_POST['pass2']); } // now we insert it into the database $insert = "INSERT INTO users (username, password, Human-Readable) VALUES ('".$_POST['username']."', '".$_POST['pass']."', '".$_POST['pass2']."')"; $add_member = mysql_query($insert); ?> <h1>Registered</h1> <p>Thank you, you have registered - you may now login</a>.</p> <?php } else { ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <table border="0"> <tr><td>Username:</td><td> <input type="text" name="username" maxlength="60"> </td></tr> <tr><td>Password:</td><td> <input type="password" name="pass" maxlength="10"> </td></tr> <tr><td>HR:</td><td> <input type="password" name="pass2" maxlength="10"> </td></tr> <tr><th colspan=2><input type="submit" name="submit" value="Register"></th></tr> </table> </form> <?php } ?> And incase you want to see it here is the original: <?php // Connects to your Database mysql_connect("//", "//", "//") or die(mysql_error()); mysql_select_db("//") or die(mysql_error()); //This code runs if the form has been submitted if (isset($_POST['submit'])) { //This makes sure they did not leave any fields blank if (!$_POST['username'] | !$_POST['pass'] | !$_POST['pass2'] ) { die('You did not complete all of the required fields'); } // checks if the username is in use if (!get_magic_quotes_gpc()) { $_POST['username'] = addslashes($_POST['username']); } $usercheck = $_POST['username']; $check = mysql_query("SELECT username FROM users WHERE username = '$usercheck'") or die(mysql_error()); $check2 = mysql_num_rows($check); //if the name exists it gives an error if ($check2 != 0) { die('Sorry, the username '.$_POST['username'].' is already in use.'); } // this makes sure both passwords entered match if ($_POST['pass'] != $_POST['pass2']) { die('Your passwords did not match. '); } // here we encrypt the password and add slashes if needed $_POST['pass'] = md5($_POST['pass']); if (!get_magic_quotes_gpc()) { $_POST['pass'] = addslashes($_POST['pass']); $_POST['username'] = addslashes($_POST['username']); } // now we insert it into the database $insert = "INSERT INTO users (username, password) VALUES ('".$_POST['username']."', '".$_POST['pass']."')"; $add_member = mysql_query($insert); ?> <h1>Registered</h1> <p>Thank you, you have registered - you may now login</a>.</p> <?php } else { ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <table border="0"> <tr><td>Username:</td><td> <input type="text" name="username" maxlength="60"> </td></tr> <tr><td>Password:</td><td> <input type="password" name="pass" maxlength="10"> </td></tr> <tr><td>Confirm Password:</td><td> <input type="password" name="pass2" maxlength="10"> </td></tr> <tr><th colspan=2><input type="submit" name="submit" value="Register"></th></tr> </table> </form> <?php } ?> Many Thanks in advanced I have a text box for users to enter new text in. The box also contains text that is determined by a variable that is created from a mysql query and some other added text. I want to make a portion of the added text within the textbox bold. How would I achieve this with php? Code: [Select] <?php result = mysql_query("SELECT `something` FROM `table` WHERE `this` = '$that'"); row = mysql_fetch_row($result); $variable = $row[0]; $text = "<strong>Here is the text that I want bold</strong> $variable"; echo "<textarea name=\"textbox\">"; echo "$text"; echo "</textarea> ?> Doing this gives me this result in the textbox: "<strong>Here is the text that I want bold</strong> This is what the variable text says." Any ideas? hey, im trying to show data in a text box thats being retrived from a database, but if there is a ' in it, it will only show the text up to that point. (ie. if it has "You're" it will only show "You") here is the code im using echo "<input type='text' value='$picComment'>"; Hi, I would like to know how to get The Value Of An Hidden TextBox From an External Website than Mine. I'm Coding an Addons for CCBChurch.com (mychurch.ccbchurch.com/app/trx_submit_bp.php), This is a donation website, They want me to code an addons so people can place it on their website and people can donate. I made it in cURL with POST but they generate a TimeStamp and a TimeStamp encoded, The 2 are on mychurch.ccbchurch.com/app/trx_submit_bp.php on hidden textbox. I would like to get the TS and TSH from the hidden textbox on the website, Is that possible ? I would too like to put it in Variable $ts and $tsh... Thanks ! Hi,
i'm trying to display db(name,email,telephone no) values in textbox.please help me.
::HTML part::
<form class="form-signin" role="form" id="form1" action="post_user.php"> sorry for posting..i already make it hello, i have implemented a jquery function like this: http://jsbin.com/ujuse i need to grab the contents of the textarea to store it in a session, but without sending a form, is this possible?? thanks for looking hello, is there a way to have it so that when somebody enters information into a textbox in a form, it will keep the formatting (if they have 5 lines, it will show as 5, not 1) Code: [Select] $name = $_POST['name']; $resume = $_POST['resume']; $to = "mike@web.com"; $subject = "Resume From Website"; $message = "Name: $name <br /> Resume: $resume "; $from = "resume@web.com"; $headers = "From: $from \r\n Content-Type: text/html; charset=ISO_8859-1\r\n Content-Transfer_Encoding: 7bit\r\n\r\n"; mail($to,$subject,$message,$headers); I have some problem when I want to echo out a text which is retrieve from my database and place it inside a text box but it stops showing when there's a space. If I echo it out outside of the textbox, then there's no problem. May I know how to resolve this problem. Thanks For example, I've got 10 input boxes (textbox) and 5 of them must contain date that user enters using calender script, the problem is, all of the boxes that requires date as input have the same id and now only first textbox is populated (logic I know), how can I populate the other ones? Code for showing calendar images next to textboxes which IDs are "a": if ($row['fieldtype'] == 'a') { echo '<input type="text" id="a" name="textbox[]" value=""></td><td>'; echo '<input type="hidden" id="a" name="textbox[]" value=""></td><td>'; echo '<a href="javascript:viewcalendar()"><img src="calendar.png"></a></td><td>'; } And the code in scripts.js that populates fields Code: [Select] function insertdate(d) { window.close(); window.opener.document.getElementById('a').value = d; } Hi there, I am working on a PHP website. The scenario is that there is page where users can enter a Group name and can specify its Members name. A group can have n-number of members under it. We cannot predict how many members will be assigned to a group. So therefore, I have given a link or button under the group name as 'add more member' where users can click and add member names in the textbox at runtime. Please see the Screenshot for a clear idea as to what I am trying to accomplish here. Thank you! All comments and feedback are always welcomed.
I've been working on this html/php page for class and I just don't understand why my code is acting like this. This is my code <?php //error_reporting(E_ALL); //ini_set('display_errors', 1); $title = "Listing Search"; $file = "listing-search.php"; $description = "Listing Search page for real estate website (WEBD3201)"; $date = "2019-10-01"; $banner = "Listing Search page"; require "header.php"; ?> <?php $headline = ""; $minPrice = ""; $maxPrice = ""; $city = ""; $error = ""; $output = ""; $error = ""; $output = ""; if(isset($_GET["city"])) { $city = $_GET["city"]; setcookie('city',$city,COOKIE_LIFESPAN); $_SESSION['city'] = $city; } else if (isset($_COOKIE['city'])) { $city = $_COOKIE['city']; $_SESSION['city'] = $city; } if(!isset($city)) { $_SESSION['RedirectError'] = "Please select a city<br/>"; header("Location:listing-select-city.php"); } if(isPost()) { $minPrice = trim($_POST["minPrice"]); $output .=$_POST["minPrice"]; $maxPrice = trim($_POST["maxPrice"]); $output .=$_POST["maxPrice"]; $headline = trim($_POST["headline"]); $output .=$_POST["headline"]; $city = trim($_POST["city"]); $output .=$_POST["city"]; $error = ""; $output = ""; if($headline == "") { $error .= "<br/>Headline was not specified"; } if($city == "") { $error .= "<br/>City was not specified"; } if($minPrice == "") { $error .= "<br/>Minimum price was not specified"; } elseif (preg_match(PRICE_FILTER, $minPrice) == '0') { $error .= "<br/>Minimum price needs to be a number"; $minPrice = ""; } if($maxPrice == "") { $error .= "<br/>Maximum price was not specified"; } elseif (preg_match(PRICE_FILTER, $maxPrice) == '0') { $error .= "<br/>Maximum price needs to be a number"; $minPrice = ""; } if($maxPrice < $minPrice) { $error .= "<br/>Minimum price must be smaller than maximum price"; } } ?> <?php echo $error; ?> <?php echo $output;?> <h2>Search for a home.</h2> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <table style="margin-left: auto; margin-right: auto;"> <tr> <td> Listing Name </td> <td> <input type="text" name="newlist" value="<?php echo $headline ?>" /> </td> <td> City </td> <td> <input type="text" name="city" value="<?php echo $city ?>" /> </td> </tr> <tr> <td> Min Price </td> <td> <input type="text" name="minPrice" value="<?php echo $minPrice ?>" /> </td> <td> Max Price </td> <td> <input type="text" name="maxPrice" value="<?php echo $maxPrice ?>" /> </td> </tr> </table> <table style="margin-left: auto; margin-right: auto;"> <tr> <td> <input type="submit" value = "Search" /> </td> <td> <input type="reset" value = "Clear" /> </td> </tr> <tr> <td> <?php echo build_checkbox("internet", "DSL"); ?> </td> <td> <?php echo build_checkbox("heating", ""); ?> </td> </tr> </table> </form> <?php require "footer.php"; ?>
|