-
Posts
9,409 -
Joined
-
Last visited
-
Days Won
1
Everything posted by MadTechie
-
insert HTML code into sql table via php form
MadTechie replied to Alexhoward's topic in PHP Coding Help
ok remove the isset($_POST['submit']) && if(isset($_POST['user']) && isset($_POST['user2']))//updated { -
echo date('h:i:s A', $timestamp); see date remove the A to remove AM/PM
-
insert HTML code into sql table via php form
MadTechie replied to Alexhoward's topic in PHP Coding Help
//add this line to the start then do a submit print_r($_POST); if(isset($_POST['submit']) && isset($_POST['user']) && isset($_POST['user2']))//updated { //snip you see array ([user2] = "balr" etc post that back -
i think this is was you want i think 4 updates, basically had the "select" , "where" and "Limit" in 3 parts and reuse the "where" on the count <fieldset> <span class="navyboldtxt"> <label for="jobcatergory">Job Category: </label></span> <select name="jobcatergory"> <option value="Please Select">Please Select</option> <?php $jobcatergory_opts = array( "Accountancy and Finance", "Banking and Insurance", "Construction", "Customer Service", "Engineering", "Management", "Hotel and Catering", "Information Technology", "Legal", "Marketing", "Medical", "Retail", "Sales", "Secretarial", "Transport and Distribution", "Working from home", ); foreach($jobcatergory_opts as $opt){ $selected = $_POST['jobcatergory'] == $opt ? " selected=true":""; print "<option value=\"{$opt}\"{$selected}>{$opt}</option>"; } ?> </select><p></p> <p><label for="employmenttype"><span class="navyboldtxt">Employment Type:</label></span> <select name="employmenttype"> <option value="Please Select">Please Select</option> <?php $employmenttype_opts = array( "permanent fulltime", "permanent parttime", "temporary fulltime", "temporary parttime", ); foreach($employmenttype_opts as $opt){ $selected = $_POST["employmenttype"] == $opt ? " selected=true":""; echo "<option value=\"" . $opt . "\"" . $selected . ">" . $opt . "</option>"; } ?> </select><p></p> <input type="submit" value="Search" name="submit" /></p> </fieldset> </form> <?php // how many rows to show per page $rowsPerPage = 4; // by default we show first page $pageNum = 1; // if $_GET['page'] defined, use it as page number if(isset($_GET['page'])) { $pageNum = $_GET['page']; } // counting the offset $offset = ($pageNum - 1) * $rowsPerPage; if ($_POST['submit']){ $select = "SELECT * FROM users"; //MT:Updated + updated $sql = ""; //MT:Added $jobcat = mysql_real_escape_string(trim($_POST['jobcatergory'])); $emptype = mysql_real_escape_string(trim($_POST['employmenttype'])); if ($jobcat != '' && $emptype != '') { $sql .= " WHERE jobcatergory LIKE '$jobcat%' AND employmenttype LIKE '%$emptype%'"; } else if ($jobcat != '' && $emptype == '') { $sql .= " WHERE jobcatergory LIKE '%$jobcat%'"; } else if ($emptype != '' && $jobcat == '') { $sql .= " WHERE employmentype LIKE '%$emptype%'"; } $limit =" LIMIT $offset, $rowsPerPage"; //MT: ADDED + updated $query = mysql_query($select.$sql.$limit) or die(mysql_error()); //MT: updated if(mysql_num_rows($query) > 0) { while ($job = mysql_fetch_array($query)) { $username=$job["username"]; $jobcatergory=$job["jobcatergory"]; $employmenttype=$job["employmenttype"]; ?> <table class="sofT" cellspacing="0"> <tr> <td class="Header">Username</td> <td class="Header">Job Category</td> <td class="Header">Employment Type</td> <td class="Header">View CV</td> <td class="Header">Contact</td> </tr> <tr> <td class="Body"><?php echo $job["username"]; ?></td> <td class="Body"><?php echo $job["jobcatergory"]; ?></td> <td class="Body"><?php echo $job["employmenttype"]; ?></td> <td class="Body"><?php echo "<a href='searchcvview.php?username=$username'>View CV</a>"?></td> <td class="Body"><?php echo "<a href='searchcontactcv.php?username=$username'>Contact</a>"?></td> </tr> <br> </table> <?php } echo '<br>'; echo '<br>'; // how many rows we have in database $query = "SELECT COUNT(id) AS numrows FROM job"; $result = mysql_query($query.$sql) or die('Error, query failed'); //MT: updated $row = mysql_fetch_array($result, MYSQL_ASSOC); $numrows = $row['numrows']; // how many pages we have when using paging? $maxPage = ceil($numrows/$rowsPerPage); // print the link to access each page $self = $_SERVER['PHP_SELF']; $nav = ''; for($page = 1; $page <= $maxPage; $page++) { if ($page == $pageNum) { $nav .= " $page "; // no need to create a link to current page } else { $nav .= " <a href=\"$self?page=$page\">$page</a> "; } } // creating previous and next link // plus the link to go straight to // the first and last page if ($pageNum > 1) { $page = $pageNum - 1; $prev = " <a href=\"$self?page=$page\">[Prev]</a> "; $first = " <a href=\"$self?page=1\">[First Page]</a> "; } else { $prev = ' '; // we're on page one, don't print previous link $first = ' '; // nor the first page link } if ($pageNum < $maxPage) { $page = $pageNum + 1; $next = " <a href=\"$self?page=$page\">[Next]</a> "; $last = " <a href=\"$self?page=$maxPage\">[Last Page]</a> "; } else { $next = ' '; // we're on the last page, don't print next link $last = ' '; // nor the last page link } // print the navigation link echo $first . $prev . $nav . $next . $last; } } else { echo '<p>There are no search results with the search criteria you entered.</p>'; } ?>
-
insert HTML code into sql table via php form
MadTechie replied to Alexhoward's topic in PHP Coding Help
i may of made a mistake this was done very quickly <?php if(isset($_POST['submit']) && isset($_POST['user']) && isset($_POST['user2']))//updated { //check to see if link has already been added to username $user = mysql_real_escape_string($_POST['user']); $user2 = htmlspecialchars($_POST['user2'], ENT_QUOTES); $match = "SELECT link FROM memberlinks WHERE username = '$user' and link = '$user2'"; $qry = mysql_query($match) or die ("Could not match data because ".mysql_error()); $num_rows = mysql_num_rows($qry); if ($num_rows != 0) { echo "You've already added that link.<br>"; echo "<a href=change_password.php>choose another</a>"; //exit; //removed }else { // connect to the mysql server $link = mysql_connect($server, $db_user, $db_pass) or die ("Could not connect to mysql because ".mysql_error()); // select the database mysql_select_db($database) or die ("Could not select database because ".mysql_error()); // insert the data $user = mysql_real_escape_string($_POST['user']); $user2 = htmlspecialchars($_POST['user2'], ENT_QUOTES); $insert = mysql_query("insert into memberlinks values ('$user', '$user2')") or die("Could not insert data because ".mysql_error()); // print a success message echo "Your link has been added!<br>"; //unneeded below //echo "Now you can <a href=change_password.php>add another link</a>"; } } $mysite_username = $_COOKIE["mysite_username"]; $conn = mysql_connect($server, $db_user, $db_pass) or die ("could not connect to mysql"); #Connect to mysql $rs = mysql_select_db( $database, $conn ) or die ("Could not select database"); #select database $sql = "Select link FROM links"; //pull the users from the table $result= mysql_query($sql) or die(" Could not add style facts"); echo "<table align=center border=1>"; // display the users in table $c = 0; while($row = mysql_fetch_array($result)) { $user2 = htmlspecialchars($row['link'], ENT_QUOTES); $user3 = $row['link']; //$user2 = $row['link']; if($c%5 == 0) echo "<tr height=\"200px\">"; // If the counter has ticked 6 times, start a new row. $sql2 = "SELECT link FROM memberlinks WHERE username = '$mysite_username' and link = '$user2'"; $result2 = mysql_query($sql2) or die(" Could not add style facts"); //$qry2 = mysql_query($result2) //or die ("Could not match data because ".mysql_error()); $num_rows = mysql_num_rows($result2); if ($num_rows != 0) { //if(empty($result2)) //{ $button = "Link Added"; }else{ $button = "<input type='submit' value='Add Link'>"; } //<input type=submit> //UPDATEED: removed the action (action='addlinks.php') as we call ourself echo "<td><FORM method='post'><p><input type=HIDDEN name='user' value='$mysite_username'></p><p align=center><input type=HIDDEN name='user2' value='$user2'></p><p align=center>$user3</p><p align=center>rating script here</p><p align=center>$button</p></form>"; if($c%5 == 4) echo "</tr>"; // If we're drawing the 6th pic, end this row. $c++; } if($c%5 != 4) echo "</tr>"; // If there isn't a number of pics divisible by 6, end the row echo "</table>"; // end the table ?> -
insert HTML code into sql table via php form
MadTechie replied to Alexhoward's topic in PHP Coding Help
Sorry work calls.. review this updated version <?php //only use when submitted if(isset($_POST['submit']) && $_POST['submit'] == 'Add Link') { //you could just add the code from the addlink.php here but i don't know that code include "addlinks.php"; } $mysite_username = $_COOKIE["mysite_username"]; $conn = mysql_connect($server, $db_user, $db_pass) or die ("could not connect to mysql"); #Connect to mysql $rs = mysql_select_db( $database, $conn ) or die ("Could not select database"); #select database $sql = "Select link FROM links"; //pull the users from the table $result= mysql_query($sql) or die(" Could not add style facts"); echo "<table align=center border=1>"; // display the users in table $c = 0; while($row = mysql_fetch_array($result)) { $user2 = htmlspecialchars($row['link'], ENT_QUOTES); $user3 = $row['link']; //$user2 = $row['link']; if($c%5 == 0) echo "<tr height=\"200px\">"; // If the counter has ticked 6 times, start a new row. $sql2 = "SELECT link FROM memberlinks WHERE username = '$mysite_username' and link = '$user2'"; $result2 = mysql_query($sql2) or die(" Could not add style facts"); //$qry2 = mysql_query($result2) //or die ("Could not match data because ".mysql_error()); $num_rows = mysql_num_rows($result2); if ($num_rows != 0) { //if(empty($result2)) //{ $button = "Link Added"; }else{ $button = "<input type='submit' value='Add Link'>"; } //<input type=submit> //UPDATEED: removed the action (action='addlinks.php') as we call ourself echo "<td><FORM method='post'><p><input type=HIDDEN name='user' value='$mysite_username'></p><p align=center><input type=HIDDEN name='user2' value='$user2'></p><p align=center>$user3</p><p align=center>rating script here</p><p align=center>$button</p></form>"; if($c%5 == 4) echo "</tr>"; // If we're drawing the 6th pic, end this row. $c++; } if($c%5 != 4) echo "</tr>"; // If there isn't a number of pics divisible by 6, end the row echo "</table>"; // end the table ?> -
insert HTML code into sql table via php form
MadTechie replied to Alexhoward's topic in PHP Coding Help
how do they go back ? back button ?, the addlink.php file create the entry in the database if thats not too long can you post it -
well php says you shouldn't but mysql says you should.. unless your using mysqli, but it works eitherway thats line looks fine.. except it should be $username not $Username
-
missing the end ; $sql4 = "INSERT INTO `users` (`username`,`password`,`email`,`name`,`aim`) VALUES ('$username','".md5($password)."','$email','$name','$aim');";
-
erm.. okay can you echo the SQL and let me know what its dsiplays $sql .= " LIMIT $offset, $rowsPerPage"; //MT: ADDED echo $sql;//add this line
-
$sql4 = "INSERT INTO `users` (`username`,`password`,`email`,`name`,`aim`) ('$username','".md5($password)."','$email','$name','$aim');" should be $sql4 = "INSERT INTO `users` (`username`,`password`,`email`,`name`,`aim`) VALUES ('$username','".md5($password)."','$email','$name','$aim');" Note the word VALUES
-
Wrong section: see third party section.. or trace the code
-
After a quick review i updated 1 line and added another see the //MT: comments <?php // how many rows to show per page $rowsPerPage = 4; // by default we show first page $pageNum = 1; // if $_GET['page'] defined, use it as page number if(isset($_GET['page'])) { $pageNum = $_GET['page']; } // counting the offset $offset = ($pageNum - 1) * $rowsPerPage; if ($_POST['submit']){ $sql = "SELECT * FROM users"; //MT:Updated $jobcat = mysql_real_escape_string(trim($_POST['jobcatergory'])); $emptype = mysql_real_escape_string(trim($_POST['employmenttype'])); if ($jobcat != '' && $emptype != '') { $sql .= " WHERE jobcatergory LIKE '$jobcat%' AND employmenttype LIKE '%$emptype%'"; } else if ($jobcat != '' && $emptype == '') { $sql .= " WHERE jobcatergory LIKE '%$jobcat%'"; } else if ($emptype != '' && $jobcat == '') { $sql .= " WHERE employmentype LIKE '%$emptype%'"; } $sql .= " LIMIT $offset, $rowsPerPage"; //MT: ADDED $query = mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($query) > 0) { while ($job = mysql_fetch_array($query)) { $username=$job["username"]; $jobcatergory=$job["jobcatergory"]; $employmenttype=$job["employmenttype"]; ?> <table class="sofT" cellspacing="0"> <tr> <td class="Header">Username</td> <td class="Header">Job Category</td> <td class="Header">Employment Type</td> <td class="Header">View CV</td> <td class="Header">Contact</td> </tr> <tr> <td class="Body"><?php echo $job["username"]; ?></td> <td class="Body"><?php echo $job["jobcatergory"]; ?></td> <td class="Body"><?php echo $job["employmenttype"]; ?></td> <td class="Body"><?php echo "<a href='searchcvview.php?username=$username'>View CV</a>"?></td> <td class="Body"><?php echo "<a href='searchcontactcv.php?username=$username'>Contact</a>"?></td> </tr> <br> </table> <?php } echo '<br>'; echo '<br>'; // how many rows we have in database $query = "SELECT COUNT(id) AS numrows FROM job"; $result = mysql_query($query) or die('Error, query failed'); $row = mysql_fetch_array($result, MYSQL_ASSOC); $numrows = $row['numrows']; // how many pages we have when using paging? $maxPage = ceil($numrows/$rowsPerPage); // print the link to access each page $self = $_SERVER['PHP_SELF']; $nav = ''; for($page = 1; $page <= $maxPage; $page++) { if ($page == $pageNum) { $nav .= " $page "; // no need to create a link to current page } else { $nav .= " <a href=\"$self?page=$page\">$page</a> "; } } // creating previous and next link // plus the link to go straight to // the first and last page if ($pageNum > 1) { $page = $pageNum - 1; $prev = " <a href=\"$self?page=$page\">[Prev]</a> "; $first = " <a href=\"$self?page=1\">[First Page]</a> "; } else { $prev = ' '; // we're on page one, don't print previous link $first = ' '; // nor the first page link } if ($pageNum < $maxPage) { $page = $pageNum + 1; $next = " <a href=\"$self?page=$page\">[Next]</a> "; $last = " <a href=\"$self?page=$maxPage\">[Last Page]</a> "; } else { $next = ' '; // we're on the last page, don't print next link $last = ' '; // nor the last page link } // print the navigation link echo $first . $prev . $nav . $next . $last; } } else { echo '<p>There are no search results with the search criteria you entered.</p>'; } ?>
-
insert HTML code into sql table via php form
MadTechie replied to Alexhoward's topic in PHP Coding Help
i'm kinda confused.. am i correct in saying then they add a link they then need to refresh the page for it to change from "add a link" to "link added", if so you need to have add link sql statement before the code below -
insert HTML code into sql table via php form
MadTechie replied to Alexhoward's topic in PHP Coding Help
this code is proably being run after the pulling of data, move it up to above the get data, or post the page and i'll try to show you -
insert HTML code into sql table via php form
MadTechie replied to Alexhoward's topic in PHP Coding Help
Coding notes below <?php //i assume this just check if a link exists! (i think you mean $user2) $sql2 = "SELECT link FROM memberlinks WHERE username = 'mysql_username' and link = 'user2'"; $result2 = mysql_query($sql2) or die(" Could not add style facts"); if (mysql_num_rows($result2) == 0)//entry not in database so ask for one { $button = "<input type='submit' value='Add Link'>"; $link = ""; }else{ $button = "Link Added"; //the code below is kinda pointless, as we know that the link is user2 or $user2 $row = mysql_fetch_assoc($result2); //pull data (as we found something) $link = $row['link']; } //debug echo "$link $button"; ?> EDIT: please note the NEW comments -
insert HTML code into sql table via php form
MadTechie replied to Alexhoward's topic in PHP Coding Help
I need more info.. i don't know how your linking the tables (what fields) but if your using the links tables then all the entries are going to be linked try a Join ie SELECT *, Linkid as isLinked FROM `members` LEFT JOIN `Links` on members,linkid = Link.id if(empty($row['isLinked'])) -
insert HTML code into sql table via php form
MadTechie replied to Alexhoward's topic in PHP Coding Help
Okay 1. Erm.. 25% each ? of what the page width ? it sounds like a CSS/HTML issuse.. 2. if the field `Link` is Empty then change the value ie <?php if(empty($user3)) { $button = "<input type='submit' value='Add Link'>"; }else{ $button = "Link Added"; } echo "<td><FORM action='addlinks.php' method='post'> <p><input type=HIDDEN name='user' value='$mysite_username'></p> <p align=center><input type='HIDDEN' name='user2' value='$user2'></p> <p align=center>'$user3'</p> <p align=center>rating script here</p> <p align=center>$button</p></form>"; SideNote: maybe an idea to start a new thread for the Rating Script and in that thread include a link to this one, -
it timedout!!.. are the images stored on your webhost? also do you have the image file path, instead of the html path?
-
try something like this <?php list($width, $height) = getimagesize($row["Product_picurl"]); $long = ($width>$height)?"Width":"Height"; ?> <img name="" src="<?php echo $row["Product_picurl"];?>" alt="" <?php echo $long="150" ?> onclick="window.open('<?php echo $row["Product_picurl"];?>');">
-
insert HTML code into sql table via php form
MadTechie replied to Alexhoward's topic in PHP Coding Help
Okay this is wrong.. it should look something like this (sorry i am busy as hell today) -
insert HTML code into sql table via php form
MadTechie replied to Alexhoward's topic in PHP Coding Help
refer back to this post you need to compare the same way you set -
you need to append the data not re-set it <?php $x = ""; //add this for($i = 1; $i <= $numofpages; $i++){ if($i == $page){ //change to =. $xx =. "<div class='number'>".$i."</div>"; }else{ $xx =. "<div class='number'><a href=\"$PHP_SELF?town=$town&from_price=$from_price&to_price=$to_price&bedrooms=$bedrooms&page=$i\">$i</a></div>"; } } //end for ?> or as kenrbnsn says use an array..
-
thats code seams fine.. whats problem with the output
-
insert HTML code into sql table via php form
MadTechie replied to Alexhoward's topic in PHP Coding Help
i was going to say change $user2 = htmlspecialchars($row['link'], ENT_QUOTES); to $user2 = addslashes($row['link']); to stop the double encoding but decoding will work also