Jump to content

zaneosak

New Members
  • Posts

    7
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

zaneosak's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hello, I was curious if anybody could help me with making this code I wrote today choose a random image out of 3 that I have (image1.jpg, image2.jpg and image3.jpg) instead of just the image I have on the screen whenever I click to add an image. Currently I am just using 1 image and would like to make it choose 1 of 3 possible choices when I click to add. Also if anybody has any idea why the images arent adding at the spot of the cursor when I click I would be interested in hearing, but I know I need an array but do not know how to get the src of the images randomly. Thanks if anybody can help Code is below: <html> <head> <style> <!-- .dragme{position:relative;} --> </style> <script> var ie=document.all; var nn6=document.getElementById&&!document.all; var isdrag=false; var x,y; var dobj; function movemouse(e) { if (isdrag) { dobj.style.left = nn6 ? tx + e.clientX - x : tx + event.clientX - x; dobj.style.top = nn6 ? ty + e.clientY - y : ty + event.clientY - y; return false; } } function selectmouse(e) { var fobj = nn6 ? e.target : event.srcElement; var topelement = nn6 ? "HTML" : "BODY"; while (fobj.tagName != topelement && fobj.className != "dragme") { fobj = nn6 ? fobj.parentNode : fobj.parentElement; } if (fobj.className=="dragme") { isdrag = true; dobj = fobj; tx = parseInt(dobj.style.left+0); ty = parseInt(dobj.style.top+0); x = nn6 ? e.clientX : event.clientX; y = nn6 ? e.clientY : event.clientY; document.onmousemove=movemouse; return false; } } document.onmousedown=selectmouse; document.onmouseup=new Function("isdrag=false"); </script> <style> img{position:absolute} </style> <script> document.onclick=add function add(e){ if (window.event){ e=window.event t=e.srcElement } else{ t=e.target } if (t.nodeName=="IMG"){ if(e.type=="mouseover") t.style.border="2px solid red" else if(e.type=="mouseout") t.style.border="0px " } else{ var H=document.getElementById("img1") var C=H.cloneNode("true") C.style.left=e.clientX C.style.top=e.clientY document.body.appendChild(C) } } function tellus(){ } </script></head><body> Click to add an image, Click Image to drag<br><br> <img style="border: 0px none ;" src="image1.jpg" onmouseover="add(event)" onmouseout="add(event)" ondragstart="tellus()" id="img1" alt="" border="0" class="dragme"> </body></html>
  2. Not letting me edit my original post but here is the code that actually seems to output something, but all I get is my error that the record wasnt added to the table in the database <? $time=$_POST["time"]; $person=$_POST["user"]; $conn = mysql_connect("localhost", "username"); if (!$conn) die("Error in connecting to MySQL database server"); @mysql_select_db("database", $conn) or die("Error in selecting database"); $addrecord = "INSERT INTO regtable (Time, User) VALUES (".$_POST["time"]." , ".$_POST["user"].")"; $report = mysql_query($addrecord, $conn); if(!$report) { die("Error in retrieving information"); } if($report) { echo "<br>Time: $time"; echo "<br>Name: $person"; } ?> Output: Error retieving information
  3. well that was rather dumb, thanks for the heads up. I fixed it and my output is my error message here: if(!$report) { die("Error in retrieving information"); } which I am guessing means its not inserting the information into the table at all, am I correct in that assumption?
  4. Hello, I created a php program last week that took in a time from a drop down menu and a persons name from a text box and store it in a text file. Also when submitted the form echo'd the Time and Persons name or echo'd if either the time was already taken or the name was already taken. The names and times were stored in a text file. I am trying to make the same program but using a MySQL database in place of the text file. I am kind of new using MySQL with PHP but thought maybe someone could steer me in the right direction. Basically transforming 1 PHP program into the same one with a different method. Below is the code from the working program using the text file and the new one I am currently working on. Any help would be appreciated, but currently I am getting an "Call to undefined function: msysql_connect()" error but I also know the rest isnt going to work as totally intended. Using just PHP working as inteded <? $time=$_POST["time"]; $person=$_POST["user"]; if (file_exists("register.txt")) { $fileCheck = file("register.txt"); } else { $fileCheck = array(); } $file = fopen("register.txt", "a+"); $newperson = "$time , $person\n"; $infile = false; foreach ($fileCheck as $line) { if (stristr($line, $time) !== false) { echo "The timeslot is taken"; $infile = true; } if (stristr($line, $person) !== false) { echo "The name is taken"; $infile = true; } } if (!$infile) { fwrite($file, $newperson); echo "<br>Time: $time"; echo "<br> Name: $person"; } ?> Attempting to use MySQL to do the same thing: <? $time=$_POST["time"]; $person=$_POST["user"]; $conn = msysql_connect("localhost", "username"); if (!$conn) die("Error in connecting to MySQL database server"); @mysql_select_db("database", $conn) or die("Error in selecting database"); $addrecord = "INSERT INTO regtable (Time, User) VALUES (".$_POST["time"]." , ".$_POST["user"].")"; $report = mysql_query($addrecord, $conn); if(!$report) { die("Error in retrieving information"); } if($report) { echo "<br>Time: $time"; echo "<br>Name: $person"; } ?>
  5. Ahh thanks to both of you, both ways work just fine. I appreciate the fast responses. Have a good one!
  6. I tried this and It gave me a warning about file_get_contents wanting its first parameter to be a string. I tried it the way premiso suggested and it seems to work if the timeslot is taken but repeats itself a few times "The time slot is takenThe time slot is taken" and still echo's the name. but if the text file is empty (first entry) it gives me 2 warnings: Warning: file(register.txt): failed to open stream: No such file or directory in /project.php on line 12 Warning: Invalid argument supplied for foreach() in project.php on line 18
  7. Hello, I am trying to write some php code that searches a text file for a string. The webpage is a registration form and has a drop down of 5 times and a text box to input the users name. The time and name get posted to the php and I am trying to write some code that searches the text file for the time or person's name and gives a error message that the time or person is taken. In the code below I only have the time check which doesn't work but I get no errors and the file writes fine, the check just doesnt run. The text file writes like this "Time , Name" and starts a new line every write. I think I am missing something simple, as I thought this project would be quite easy. Any hints, tips or advice would be appreciated <? $time=$_POST["time"]; $person=$_POST["user"]; $file = fopen("register.txt", "a+"); $newperson = "$time , $person\n"; if (strstr($file, $time)) { echo "The timeslot is taken"; } else fwrite($file, $newperson); echo "Time: $time"; echo "<br> Name: $person"; fclose($file); ?>
×
×
  • 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.