Jump to content

infrabyte

New Members
  • Posts

    8
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

infrabyte's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thank you for your help. After looking up a bit on session_start(); on php.net and what you said, I got it working. I just put session_start(); at the top of each page and called $mobile = $_SESSION['mobile']; on the second one Works like a charm. Thank you
  2. Hi, Can you give us an example of the form
  3. Hi All, I have a file that passes on a mobile number eg 0123456789 in the url as follows http://domain.com/image.php?mobile=0824929698 in my file image.php I use the $mobile = $_GET['mobile']; this works great if I echo the result and it works. My problem is I want to use the $mobile further down in my script to write a filename using the number in my images folder. For some reason it just looses the value of $mobile when I want to use it. Can someone please help me to understand why it disappears. Thank you in advance. here is my code... <?php $mobile = $_GET['mobile']; define ("MAX_SIZE","2048"); //This function reads the extension of the file. It is used to determine if the file is an image by checking the extension. function getExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; } $errors=0; //checks if the form has been submitted if(isset($_POST['Submit'])) { $image=$_FILES['image']['name']; if ($image) { //get the original name of the file from the clients machine $filename = stripslashes($_FILES['image']['name']); $extension = getExtension($filename); $extension = strtolower($extension); if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) { //print error message echo '<h1>Unknown extension!</h1>'; $errors=1; } else { //get the size of the image in bytes $size=filesize($_FILES['image']['tmp_name']); if ($size > MAX_SIZE*1024) { echo '<h1>You have exceeded the size limit!</h1>'; $errors=1; } $image_name=$mobile.'.'.$extension; $newname="images/".$image_name; $copied = copy($_FILES['image']['tmp_name'], $newname); if (!$copied) { echo '<h1>Copy unsuccessfull!</h1>'; $errors=1; }}}} if(isset($_POST['Submit']) && !$errors) { echo $mobile; echo "<h1>Thanks for entering the Search. Good Luck.</h1>"; } ?> <form name="newad" method="post" enctype="multipart/form-data" action="image.php"> <table> <tr><td><b>Please upload a head and shoulders photo of yourself - Maximum size: 2Mb Jpeg </b><input type="file" name="image"></td></tr> <tr><td><input name="Submit" type="submit" value="Upload image"></td></tr> </table> </form> The problem area is here...$image_name=$mobile.'.'.$extension;
  4. Hi Guys, I have these two files one is a form with questions and the other is a results.php file. The form has 8 questions with 4 possible answers for each one namely a,b,c,d I have managed to get the results and display them but I want to say to the user that if mostly a's were selected then it must display what is given in my if..elseif...else loop for a and likewise for b,c or d here is my results file so far: <?php $title = "Quiz Results"; echo "<title>$title</title>"; // Below gets the answers from the page before // if (isset ($_POST['submit'])) { $q1 = $_POST['q1']; $q2 = $_POST['q2']; $q3 = $_POST['q3']; $q4 = $_POST['q4']; $q5 = $_POST['q5']; $q6 = $_POST['q6']; $q7 = $_POST['q7']; $q8 = $_POST['q8']; } // Below checks to see if you forgot anything // if ($q1 == "") { die ("You forgot something, go back and check over your quiz."); } if ($q2 == "") { die ("You forgot something, go back and check over your quiz."); } if ($q3 == "") { die ("You forgot something, go back and check over your quiz."); } if ($q4 == "") { die ("You forgot something, go back and check over your quiz."); } if ($q5 == "") { die ("You forgot something, go back and check over your quiz."); } if ($q6 == "") { die ("You forgot something, go back and check over your quiz."); } if ($q7 == "") { die ("You forgot something, go back and check over your quiz."); } if ($q8 == "") { die ("You forgot something, go back and check over your quiz."); } // Below is where the answers are actually displayed // { echo<<<EOT <p>Results:<br> 1.) $q1<br> 2.) $q2<br> 3.) $q3<br> 4.) $q4<br> 5.) $q5<br> 6.) $q6<br> 7.) $q7<br> 8.) $q8</p> <p> EOT; } // This will give me a,b,c or d from each question $str1 = substr($q1, 0, 1); $str2 = substr($q2, 0, 1); $str3 = substr($q3, 0, 1); $str4 = substr($q4, 0, 1); $str5 = substr($q5, 0, 1); $str6 = substr($q6, 0, 1); $str7 = substr($q7, 0, 1); $str8 = substr($q8, 0, 1); // **************** Issue is from here on ******************************** $array = array($str1, $str2, $str3, $str4, $str5, $str6, $str7, $str8); $val = (array_count_values($array)); print_r ($val); // $val = min(array($str1, $str2, $str3, $str4, $str5, $str6, $str7, $str8)); // print_r ($val); if ($val=="a") echo "Mostly 'A's: IT. Looks like you're a bit of a tech-head. You should check out IT at Monash South Africa."; elseif ($val=="b") echo "Mostly 'B's: Business & Economics. Whoa, look out business world! You should check out Business & Economics at Monash South Africa."; elseif ($val=="c") echo "Mostly 'C's: Health Sciences. Open up and say, 'Aaaah.' You should check out Health Sciences at Monash South Africa."; elseif ($val=="d") echo "Mostly 'D's: Arts. Your engine runs on creative juice. You should check out the Arts at Monash South Africa."; else echo "You are a rare person with above normal interests, You should check out Monash South Africa."; ?> I have been trying various things but I think I am complicating the code to much or something....Please help me...much appreciated
  5. Hi, I really, really thank you for that...It solved my problem that I have been trying to work around since last night. Thank you
  6. Hi Guys, I'm not sure what to do here. I have a variable that is passed on via a url. I have a database table that has a field called 'publish'. This field contains either a Yes or a No. All I want to do is check the field an if it is Yes then make it No, and likewise if it is No then make it Yes. Here is my code. It changes one way but not the other. The value of $publish seems to stay the same...please help...Thank you. <?php // connect to the database include('connect-db.php'); // get id value $id = $_GET['id']; echo "$id"; $publish = $_GET['publish']; echo "$publish"; $sql="SELECT * FROM events WHERE ID='$id'"; $result=mysql_query($sql); if ($publish='Yes') { $publish=='No'; } else { $publish=='Yes'; } // echo "<p>$publish</p>"; $sqltwo = "UPDATE events SET publish='$publish' WHERE ID='$id'"; $resulttwo = mysql_query($sqltwo); // sleep(2); // header("Location: beacon.php"); ?>
  7. Hi, Thanx for the feedback. That doesn't seem to change anything. I just want to change the published field from Yes to No if I click on Update or visa versa It must be a simple thing but I'm just not seeing it at the mo. This is supposed to be a script that changes a row in the database from published to unpublished (ie Yes/No)
  8. Hi All, Please can someone help me with this bit of code. I have a mysql database with a table called 'events'. I have six fields namely 'ID, mxitID, type, message, ts, publish'. I am trying to update the field 'publish' from Yes --> No or if it is already No then back to Yes again. I have two files then main one beacon.php and publish.php Here is the code: beacon.php <?php // connect to the database include('connect-db.php'); // display data in table // echo "<p><b>View All</b> | <a href='view-paginated.php?page=1'>View by Page</a></p>"; // echo "Select your Carousel: "; // get results from database $result = mysql_query("SELECT * FROM events WHERE type='beacon'") or die(mysql_error()); echo "<table border='1' cellpadding='10'>"; echo "<a href='index.php'>b Back</a><br><br>"; echo "<tr> <th>ID</th> <th>mxitID</th> <th>Type</th> <th>Message</th> <th>Timestamp</th> <th>Published</th> <th>Modify</th></tr>"; // loop through results of database query, displaying them in the table while($row = mysql_fetch_array( $result )) { // echo out the contents of each row into a table echo "<tr>"; echo '<td>' . $row['ID'] . '</td>'; echo '<td>' . $row['mxitID'] . '</td>'; echo '<td>' . $row['type'] . '</td>'; echo '<td>' . $row['message'] . '</td>'; echo '<td>' . $row['ts'] . '</td>'; echo '<td>' . $row['publish'] . '</td>'; echo '<td><a href="publish.php?id=' . $row['ID'] . '"><input name="update" type="submit" id="update" value="Update"></a></td>'; echo "</tr>"; } // close table> echo "</table>"; ?> publish.php <?php // connect to the database include('connect-db.php'); // get id value $id = $_GET['id']; echo "$id"; $sql="SELECT * FROM events WHERE type='beacon'"; $result=mysql_query($sql); $active=($result['publish']=='')?'Yes':'No'; echo "$active"; if ($active='Yes') { $active='No'; } else { $active='Yes'; } $sql = "UPDATE events SET publish='$active' WHERE ID='$id'"; $result = mysql_query($sql); // header("Location: beacon.php"); ?> I cant seem to change the value...any help would be much appreciated. Thank you in advance. MOD EDIT: code tags added.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.