
leoric80
Members-
Posts
19 -
Joined
-
Last visited
leoric80's Achievements

Newbie (1/5)
0
Reputation
-
Ah this was me being an idiot! It was an issue with my foreach statement, thanks anyway
-
Oh and no errors are returned either, quite confused by all this!
-
Hi, sorry for being a complete noob but I am running the following query in PHP and it is not updating the database. mysql_query('INSERT INTO 1_outbox (destno, student_id, message) SELECT p1contact_no, contact_id_internal, "poo" FROM 1_contacts WHERE contact_id_internal=100;'); If I run the same command in the CLI it updates the database as expected.. mysql> INSERT INTO 1_outbox (destno, student_id, message) SELECT p1contact_no, contact_id_internal, "poo" FROM 1_contacts WHERE contact_id_internal=100; Query OK, 2 rows affected (0.01 sec) Records: 2 Duplicates: 0 Warnings: 0 This is not a permissions issue as other insert statements within the same form work fine, have I got my PHP syntax wrong by any chance? Thanks!
-
I thought I would try a loop to get the data out like following but that doesn't seem to help either foreach($_POST['selected'] as $value) { print $value['first_name']; }
-
Hi Thanks for your help, i am with you I think echo '<input type="checkbox" name="selected[] vaule="'.$row['student_id_internal'].'"/>'; This is what I have gone with, this is unique value from the query so should do the job, it still shows the following when I echo the $_POST.. Array ( [senderno] => 07500000000 [school_id] => 1 [destno] => [selected] => Array ( [0] => on [1] => on ) [message] => rgreg ) I assume that is because this is an array inside of an array($_POST), is my understanding of that correct? Thanks again
-
Hey Thanks guys. I have removed the value option from my checkbox and read up a little on arrays, would I be correct in saying that this is a multi-dimensional array in this particular instance? Think I need some coffee... Sorry I know I am being slow today, im VERY new to coding and this one seems to be busting my head open! Cheers
-
Hey, I am having difficulty viewing the data submitted by my web form, I would hugely appreciate any help with this. I am probably going about this the wrong way but hey. My code for main.php <form action="outbox.php" method="post"name="sendform"> <input type="hidden" value="07500000000" name="senderno"> <input type="hidden" value="<?php echo $school_id ?>" name="school_id"> <span align="left" class="label fix">To:</span><br> <input placeholder="Search name" id="searchInput" type="text" name="destno" autocomplete='off'><br> <p><button type=button class="btn1">Hide</button><button type=button class="btn2">Show</button></p> <boobies> <script src="table.js"></script> <script language="JavaScript"> function toggle(source) { checkboxes = document.getElementsByName('selected[]'); for(var i=0, n=checkboxes.length;i<n;i++) { checkboxes[i].checked = source.checked; } } </script> <?php # display returned data if (mysql_num_rows($result) > 0) { ?> <table style="border: 0px solid black cellpadding="5""> <tr><td><input type="checkbox" onClick="toggle(this)" /> </td></tr> <?php while ($row = mysql_fetch_assoc($result)) { echo '<tr><td>'; echo '<input type="checkbox" name="selected[]" value=""/>'; echo '</td>'; echo '<td>'.$row['first_name'].'</td>'; echo '<td>'.$row['last_name'].'</td>'; echo '<td>'.$row['year'].'</td>'; echo '<td>'.$row['class'].'</td>'; echo '<td>'.$row['p1_first_name'].' '.$row['p1_family_name'].'</td>'; echo '<td>'.$row['p1contact_no'].'</td>'; echo '</tr>'; } ?> </table> <?php } else echo '<p>No data</p>'; ?> outbox.php echo "<pre>"; print_r($_POST); echo "</pre>"; $_POST Output from outbox.php Array ( [senderno] => 07500000000 [school_id] => 1 [destno] => [selected] => Array ( [0] => ) [message] => dwqd ) The issue is I would like to be able to display the 'selected' items in outbox.php, the other variables are being displayed however I do not know how to get that array to display their values also, does that make any sense? Thanks
-
Thanks. I was just using that as an example of how I have achieved this previously (sorry i wasnt very clear on that). Basically I want to run a query that fetches a number of fields and then joins those fields into one string if possible? I need the string to match the value of all three fields combined not just one of the fields/values.
-
Hey i am using the following code which works great for me currently...basically I am using in_array to search an array which is generated by a web form ($post) $reg_group=mysql_query('select distinct class from '.$school_id.'_students'); while ($Row = mysql_fetch_array($reg_group)) { $class[] = $Row['class']; //reg groups elseif (in_array($destno, $class)) { $result = mysql_query("select ".$school_id."_students.class, ".$school_id."_students.student_id_internal, ".$school_id."_contacts.p1contact_no from ".$school_id."_students inner join ".$school_id."_contacts on ".$school_id."_contacts.contact_id_internal=".$school_id."_students.student_id_internal where class = '$destno';"); while ($row = mysql_fetch_assoc($result)) { $p1contact = $row["p1contact_no"]; $student_id_int = $row["student_id_internal"]; mysql_query("INSERT INTO ".$school_id."_outbox (senderno, destno, message, student_id) VALUES ('$senderno', '$p1contact', '$message', '$student_id_int')"); } } However what I would like to do now is search an array but instead of looking at one value (in this case $class) I would like to concat the values into one string to search for. eg. The array contains (first_name,last_name,class), I would like to join the results together to it appears as one string (firstnamelastnameclass) then use in_array to search for that string. Hopefully that makes some kind of sense? Any help would be gratefully appreciated. Cheers
-
Thank you so much, I have this working now I appreciate your time
-
Yeah I realise that, I was hoping to come up with a more dynamic way of using the entries that exist in the database somehow rather than searching for a pre-defined string as the entries will vary hugely and I cannot predict what they will be Thanks
-
Hi Thanks for that, I think that sounds about right...I have fumbled a good few attempts and wondered if you could show me an example of in_array with a foreach loop and boolean? I am using the following to build my array.... $reg_group=mysql_query('select distinct class from '.$school_id.'_students'); while ($Row = mysql_fetch_array($reg_group)) { $class = $Row['class']; Sorry its probably obvious what I need to do but its been a long day!
-
Hi I have a web form that posts the following to my PHP page.. <span align="left" class="label fix">To:</span><br><input type="text" name="destno"><br> This is the PHP page that receives the input... $destno = $_POST['destno']; //Year 7 message to all if ($destno == "Year7") { $result = mysql_query("select ".$school_id."_students.year, ".$school_id."_contacts.p1contact_no from ".$school_id."_students inner join ".$school_id."_contacts on ".$school_id."_contacts.contact_id_internal=".$school_id."_students.student_id_internal and ".$school_id."_students.year = 7;"); while ($row = mysql_fetch_assoc($result)) { $p1contact_year = $row["p1contact_no"]; mysql_query("INSERT INTO ".$school_id."_outbox (senderno, destno, message, student_id) VALUES ('$senderno', '$p1contact_year', '$message', '$student_id')"); } } This works perfectly fine however I need to statically define the value like this...... if ($destno == "Year7") What I would like to do is pull the data from my database and store in an array, I have no problem with that either... The problem is that I need to check the array for a matching string for $destno, I cant seem to do this with strpos and I think I have to use preg_match to achieve this but after hours of trying I am getting nowhere fast. Could anyone possibly tell me how they would do this or even better still provide me with an example if possible? Thanks
-
So I got this working as desired using the following code, thank you again for all your help! if ($destno == "WholeSchool") { $result = mysql_query("Select * FROM 1_contacts"); while ($row = mysql_fetch_assoc($result)) { $everyone = $row["p1contact_no"]; mysql_query("INSERT INTO ".$school_id."_outbox (senderno, destno, message, student_id) VALUES ('$senderno', '$everyone', '$message', '$student_id')"); } } else { mysql_query("INSERT INTO ".$school_id."_outbox (senderno, destno, message, student_id) VALUES ('$senderno', '$destno', '$message', '$student_id')"); }
-
Hi I get the following error message when i test this code..any ideas? php -l outbox.php PHP Parse error: syntax error, unexpected T_STRING, expecting ']' in outbox.php on line 23 Errors parsing outbox.php if ($destno == "WholeSchool") { $WholeSchool1 = mysql_query("Select * FROM 1_contacts"); while ($WholeSchool2 = mysql_fetch_assoc($WholeSchool1)) { $WholeSchool = "$WholeSchool$WholeSchool2[1_contacts]: $WholeSchool2[p1contact_no] , "; } $WholeSchool = substr($WholeSchool, 0, -2); mysql_query("INSERT INTO ".$school_id."_outbox (senderno, destno, message, student_id) VALUES ('$senderno', '$WholeSchool', '$message', '$student_id')"); } else { mysql_query("INSERT INTO ".$school_id."_outbox (senderno, destno, message, student_id) VALUES ('$senderno', '$destno', '$message', '$student_id')"); }