wildteen88
Staff Alumni-
Posts
10,480 -
Joined
-
Last visited
Never
Everything posted by wildteen88
-
If you're planning on adding all ids into an array again then you can just open the file with file. That function will load each line into an array. So you won't need to add $ID[] = at the start of each line.
-
You need to convert the array into a string. For this you can use implode file_put_contents($file, implode("\n", $matches[1]));
-
You may be better of using the Document Object Model. Or better yet regex rather than explode. Regex is a lot more powerful.
-
Then replace code <?php for($i = 1; $i <= 8; $i++): $titleNum = "title$i"; $titleText = $$titleNum; if(!empty($titleText)): ?> <input type="text" name="<?php echo $titleNum; ?>" value="<?php echo $titleText; ?>" /> <?php endif; endfor; ?> With your old code <?php if (!empty($title1)) { echo "<select name=\"title1\" id=\"title1\"> <option value=\"$title1\">$title1</option>";} if (!empty($title2)) { echo "<select name=\"title2\" id=\"title1\"> <option value=\"$title2\">$title2</option>";} if (!empty($title3)) { echo "<select name=\"title3\" id=\"title1\"> <option value=\"$title3\">$title3</option>";} if (!empty($title4)) { echo "<select name=\"title4\" id=\"title1\"> <option value=\"$title4\">$title4</option>";} if (!empty($title5)) { echo "<select name=\"title5\" id=\"title1\"> <option value=\"$title5\">$title5</option>";} if (!empty($title6)) { echo "<select name=\"title6\" id=\"title6\"> <option value=\"$title6\">$title6</option>";} if (!empty($title7)) { echo "<select name=\"title7\" id=\"title1\"> <option value=\"$title7\">$title7</option>";} if (!empty($title8)) { echo "<select name=\"title8\" id=\"title1\"> <option value=\"$title8\">$title8</option>";} ?> </select> Which just displays separate menus for each event title that isn't empty
-
Parenthesis's () are optional. @Vince, If you change echo "Thank you, Your airfield has been submitted."; include "resultcard.php"; to echo "Thank you, Your airfield has been submitted."; include "resultcard.php"; echo "ABC"; If you now fill in the form and submit it does it just show this Or just and then nothing else after that? If that is the case then for some reason PHP is halting the script at the include. This could be due to an error. Check your severs error logs for any errors.
-
So you want the script to change the event title if they are already assigned to an event?
-
You posted score.php twice there . Line 20 should read if(isset($_POST['question'][$question_id])) I only had one ) there should be of been two.
-
To display a dropdown menu change <?php for($i = 1; $i <= 8; $i++): $titleNum = "title$i"; $titleText = $$titleNum; if(!empty($titleText)): ?> <input type="text" name="<?php echo $titleNum; ?>" value="<?php echo $titleText; ?>" /> <?php endif; endfor; ?> To <select name="title"> <?php for($i = 1; $i <= 8; $i++): $title= ${"title$i"}; ?> <option value="<?php echo $$title; ?>"><?php echo $$title; ?>" /> <?php endfor; ?> </select> However now that you have the drop down menu. We now have a problem. A drop menu can only have one name and submits the chosen values. It doesn't submit the unchosen ones, so how are you supposed to add the chosen title into the corresponding title field? You're better of getting rid of the fields title1-8 in your events table and have a single field (call it event_title) for storing the chosen event title. If you go this route then change for($i = 1; $i <= 8; $i++) ${"title$i"} = isset($_POST["title$i"]) ? $_POST["title$i"] : ''; $query_values[] = "('$title1', '$title2', '$title3', '$title4', '$title5', '$title6', '$title7', '$title8', '$userid', '$name','$eventid', '$event', '$email', 'quick', 'quick', 'quick', 'quick', 'quick', 'quick', 'quick', 'quick', 'quick', 'quick', '$id')"; } $query = "insert into Events (\n\ttitle1, title2, title3, title4, title5, title6, title7, title8, userid, name, eventid, event, email, \n\t" . To for($i = 1; $i <= 8; $i++) $event_title = $_POST["title"]); $query_values[] = "('$event_title', '$userid', '$name','$eventid', '$event', '$email', 'quick', 'quick', 'quick', 'quick', 'quick', 'quick', 'quick', 'quick', 'quick', 'quick', '$id')"; } $query = "insert into Events (\n\event_title, userid, name, eventid, event, email, \n\t" . Either comment out or remove this line echo "Generated query: <pre>$query</pre>"; I only added that for debug purposes. So I could see how the query was being generated. The query inserts multiple records at once. Rather than inserting a new record one by one.
-
How are creating your links? Can you show an example. I'd make your links like this <a href="brand.php?brand=$brand_name">$brand_name</a> Now in brand.php you can get the brand via the $_GET['brand'] variable. You shouldn't be creating separate php files for each brand.
-
Save the result card form into another file, call this file resultcard.php Now change line 109 to echo "hank you for submitting the airfield data, the resulting card will look like this...."; include "resultcard.php"; Next change this } } //} ?> <form name = "form1" method ="post" action=""> to } } if(!isset($_POST['submit']) || (isset($_POST['submit']) && !empty($errorstring))) { ?> <form name = "form1" method ="post" action=""> Lastly change </body> </html> to </body> </html> <?php } ?> Now the form will be displayed when the form hasn't been submitted yet or there are errors ($errorstring). If there are no errors then the resultcard will be shown.
-
That is the "object operator" or, more colloquially, the "arrow operator". Its token name when PHP parses your code into pieces is T_OBJECT_OPERATOR. And in which situations exactly is it used? When you're using/assigning an objects properties/methods. Its all in the manual.
-
Or Use regex $text = "1. item number 1 12. item number 12 101. item number 101"; $text = preg_replace('~\d+\.\s~', '', $text); echo $text;
-
By assign do you mean something like this? $data = $db->select->where('name', $name); Rather than having to type out $query = "SELECT name from table WHERE name = '$name'"; $result = mysql_query($query); $data = mysql_fetch_assoc($result); If thats what you mean, then you'll want to look for a third party active record class, like PHP Active Record.
-
Okay I now understand what your code is supposed to do. You want it to add the members you have chosen to an event. Looking at the screenshoot above, your form is displaying like due to this line of code. echo '<input type="checkbox" name="user[]" value="'.$member[name].'">'.$member[name].'<br><input type="hidden" name="email1[]" value="'.$member[email].'"><input type="text" name="userid1[]" value="'.$member[userid].'"><input type="text" name="id1[]" value="'.$member[userid].','.$eventid.'">'; You need to wrap that line of code in a block level element, such as a div. On to why it may be displaying your users in an disorderly fashion. This maybe due to you not telling mysql to fetch the results in a particular order. $select = mysql_query("SELECT * FROM members") or die(mysql_error()); You'll want to use an ORDER BY clause to sort the data, in your case the userid field. So we'll change the query to $select = mysql_query("SELECT * FROM members ORDER BY userid ASC") or die(mysql_error()); That should now display the members in ascending order based on the userid. In order for this to work correctly make sure the data type of the userid column is set to INT in your table schema. Try this code and see if the script works <?php if(isset($_POST['submit'])) { if(isset($_POST['event_members']) && is_array($_POST['event_members'])) { $members = $_POST['members']; foreach($_POST['event_members'] as $userid) { $name = $members[$userid]['name']; $email = $members[$userid]['email']; $id = $members[$userid]['id']; $eventid = $_POST['eventid']; $event = $_POST['event']; for($i = 1; $i <= 8; $i++) ${"title$i"} = isset($_POST["title$i"]) ? $_POST["title$i"] : ''; $query_values[] = "('$title1', '$title2', '$title3', '$title4', '$title5', '$title6', '$title7', '$title8', '$userid', '$name','$eventid', '$event', '$email', 'quick', 'quick', 'quick', 'quick', 'quick', 'quick', 'quick', 'quick', 'quick', 'quick', '$id')"; } $query = "insert into Events (\n\ttitle1, title2, title3, title4, title5, title6, title7, title8, userid, name, eventid, event, email, \n\t" . "price1, price2, price3, price4, price5, price6, price7, price8, barcode, verified, id\n)\nVALUES\n\t"; $query .= implode(",\n\t", $query_values); echo "Generated query: <pre>$query</pre>"; $result = mysql_query($query); if(!$result) trigger_error("Mysql Error!" . mysql_error()); else echo "Added " . mysql_affected_rows() . " new users to the event!"; } } $myvar = escapeMysql($_GET['eventid']); $sql = mysql_query("SELECT * FROM Registration WHERE eventid='".$myvar."'"); if(mysql_num_rows($sql) == 1) { $row = mysql_fetch_assoc($sql); $eventid = $row["eventid"]; $event = $row["event"]; $startdate = $row["startdate"]; $enddate = $row["enddate"]; $description = $row["description"]; $location = $row["location"]; $title1 = $row['title1']; $title2 = $row['title2']; $title3 = $row['title3']; $title4 = $row['title4']; $title5 = $row['title5']; $title6 = $row['title6']; $title7 = $row['title7']; $title8 = $row['title8']; $price1 = $row['price1']; $price2 = $row['price2']; $price3 = $row['price3']; $price4 = $row['price4']; $price5 = $row['price5']; $price6 = $row['price6']; $price7 = $row['price7']; $price8 = $row['price8']; $date1 = $row['date1']; $date2 = $row['date2']; $date3 = $row['date3']; $date4 = $row['date4']; $date5 = $row['date5']; $date6 = $row['date6']; $date7 = $row['date7']; $date8 = $row['date8']; ?> <form id="form1" name="form1" method="post" action=""> <table border='1' width='600'> <tr> <td width='300'> <?php for($i = 1; $i <= 8; $i++): $titleNum = "title$i"; $titleText = $$titleNum; if(!empty($titleText)): ?> <input type="text" name="<?php echo $titleNum; ?>" value="<?php echo $titleText; ?>" /> <?php endif; endfor; ?> <input type="hidden" name="eventid" value="<?php echo $eventid; ?>"> <input type="hidden" name="event" value="<?php echo $event; ?>"> <table width="323" border="1" cellspacing="2" cellpadding="2"> <tr> <th width="58" scope="col"> </th> <th width="245" scope="col"> </th> </tr> <tr> <td> </td> <td></td> </tr> <tr> <td><br /></td> <td> <?php $select = mysql_query("SELECT * FROM members ORDER BY userid ASC") or die(mysql_error()); while ($member = mysql_fetch_array($select)): $userid = $member['userid']; ?> <p> <input type="checkbox" name="event_members[]" value="<?php echo $userid; ?>"><?php echo $member['name']; ?><br> <input type="text" name="members[<?php echo $userid; ?>][name]" value="<?php echo $member['name']; ?>"> <input type="text" name="members[<?php echo $userid; ?>][email]" value="<?php echo $member['email']; ?>"> <input type="hidden" name="members[<?php echo $userid; ?>][id]" value="<?php echo $member['userid']; ?>,<?php echo $eventid; ?>"> </p> <?php endwhile; ?> </td> </tr> <tr> <td> </td> <td><!-- Textarea gets replaced with TinyMCE, remember HTML in a textarea should be encoded --></td> </tr> <tr> <td> </td> <td><input type="submit" name="submit" id="submit" value="Post" /></td> </tr> </table> </form> <?php } else { echo "Invalid event id"; } ?>
-
$str = "blah blah blah blah all 6 news updates blah blah blah all 999 news updates blah"; $str = preg_replace('/all (\d+) news updates/', '', $str); echo nl2br($str);
-
Use nl2br when sending the email.
-
This is why it is important to verify/sanitize any input from the user. If you do this properly then attackers will not be able to hack into your database.
-
if you're getting blank pages then you have an error somewhere. Check your servers error log. Or add these lines to the top of your php pages (user_login.php, members.php etc) <?php error_reporting(E_ALL); ini_set('display_errors', 'on'); ?> As for why my code I posted earlier didn't work I forgot to add ?> to the end of this line <?php if (!isset($_SESSION['username'])):
-
I assume you are storing the brand name of each product in a field called brand in your products table. If so maybe use a query like this SELECT * FROM products WHERE brand="$brand_name" Or if you don't have a brand field. You could perform search on the product name field something like SELECT * FROM products WHERE product_name LIKE %$brand_name%" It all depends on how you are storing your products. I cannot give a specific answer really.
-
You'll want to use regex $str = "all 6 news updates"; $number = preg_replace('/all (\d+) news updates/', '$1', $str); echo "Echo the number is: $number"; What do you want replace the number with?
-
Use a better edit which has bracket matching support.
-
How do I add this piece of code; to this piece of code?
wildteen88 replied to xwishmasterx's topic in PHP Coding Help
$buttons = "button+='<table height=\"40\" border=\"0\"id=\"table1\"cellspacing=\"0\"cellpadding=\"2\"><tr><td>document.getElementById('com').innerHTML=\"$gSurfMultiLoadedText\"+button2;</td><td valign=\"bottom\">';\n"; Like that? This document.getElementById('com').innerHTML=<?php echo $gSurfMultiLoadedText; ?>+button2; Is JavaScript if you want to execute that code, then you'll need to wrap it <script></script> tags. -
Just read your code from this post. Which I guess is the most recent version of your code. I didn't actually look at your code properly last time round. Now that I have reviewed it. I'm struggling to work out what you're trying to do. My first thought was you're editing multiple events for a specific user. But then I just spotted this <td><?php $select = mysql_query("SELECT * FROM members") or die(mysql_error()); while ($member = mysql_fetch_array($select)) { echo '<input type="checkbox" name="user[]" value="'.$member[name].'">'.$member[name].'<br><input type="hidden" name="email1[]" value="'.$member[email].'"><input type="text" name="userid1[]" value="'.$member[userid].'"><input type="text" name="id1[]" value="'.$member[userid].','.$eventid.'">'; } ?></td> which now makes me think your are trying to link multiple users to a specific event. Can you confirm what the script is supposed to do.
-
First result of what? In your registration table. If the userid field in that table is set to auto_increment then yes that may be why. You can reset the counter so it starts at 1 but that I do not recommend. Especially if you already have data in your registration and events table, as then there will be no correlation between a user and their events. I assume that's how you're linking an event to a user.