ChompGator
-
Posts
171 -
Joined
-
Last visited
Never
Posts posted by ChompGator
-
-
Nope, the script is running on the index.php
it shouldn't be an include, Ill find it and remove it
Heres the most updated code if you want to take a look
<?php
$con = mysql_connect("","","") or die('Could not connect: ' . mysql_error());
mysql_select_db("", $con);
$result = mysql_query("SELECT * FROM elections");
while($row = mysql_fetch_assoc($result)){
echo "ID: ".$row['id']." - ".$row['articlename']." -- ".$row['date']."<br/><br/> ".$row['description']."<br/><br/>";
} // end if
ini_set ("display_errors", "1");
error_reporting(E_ALL);
// find out how many rows are in the table
$sql = "SELECT COUNT(*) FROM elections";
$result = mysql_query($sql) or die(mysql_error());
$r = mysql_fetch_row($result);
$numrows = $r[0];
// number of rows to show per page
$rowsperpage = 1;
// find out total pages
$totalpages = ceil($numrows / $rowsperpage);
// get the current page or set a default
if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
// cast var as int
$currentpage = (int) $_GET['currentpage'];
} else {
// default page num
$currentpage = 1;
} // end if
// if current page is greater than total pages...
if ($currentpage > $totalpages) {
// set current page to last page
$currentpage = $totalpages;
} // end if
// if current page is less than first page...
if ($currentpage < 1) {
// set current page to first page
$currentpage = 1;
} // end if
// the offset of the list, based on current page
$offset = ($currentpage - 1) * $rowsperpage;
// get the info from the db
$sql = "SELECT id, number FROM elections LIMIT $offset, $rowsperpage";
$result = mysql_query($sql) or die(mysql_error());
// while there are rows to be fetched...
while ($list = mysql_fetch_assoc($result)) {
// echo data
echo $list['id'] . " : " . $list['number'] . "<br />";
} // end while
/****** build the pagination links ******/
// range of num links to show
$range = 3;
// if not on page 1, don't show back links
if ($currentpage > 1) {
// show << link to go back to page 1
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> ";
// get previous page num
$prevpage = $currentpage - 1;
// show < link to go back to 1 page
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> ";
} // end if
// loop to show links to range of pages around current page
for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
// if it's a valid page number...
if (($x > 0) && ($x <= $totalpages)) {
// if we're on current page...
if ($x == $currentpage) {
// 'highlight' it but don't make a link
echo " [<b>$x</b>] ";
// if not current page...
} else {
// make it a link
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> ";
} // end else
} // end if
} // end for
// if not on last page, show forward and last page links
if ($currentpage != $totalpages) {
// get next page
$nextpage = $currentpage + 1;
// echo forward link for next page
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> ";
// echo forward link for lastpage
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> ";
} // end if
/****** end build pagination links ******/
?>
-
your script is only 100 lines long but it's saying the error is on line 242... if that was the complete code you posted, is this file being included in some other file? If not, then perhaps you're trying to run the wrong script.
Hey,
thanks for your input so far, the script is only infact 100 lines long...
So why its saying there is an error on line 242, is beyond me.
Ive since gotten all the page numbers to appear and all the errors to disappear, the only thing Im fighting with now, is its still showing all the news articles in the database on one page, I need it to only show 4 per page, and right now its showing all the articles in the database on one page, then when you click to page two, it shows all the articles again, and so on..
But the page numbers are showing and they are working so thats a step forward
-
Ok, I got it all fixed...
The problem is now, its showing the page numbers ie:
[1], [2] etc..
But its showing them like this:
3:3
4:4
5:5
And its still displaying all the news articles on one page, not 4 on each page.
Thanks everyone fior all the input, any more help would be great
-
Here is the new code, double-check it to make sure I did what you said properly...
I made that replacement, but Im still getting the Fatal Error:
<?php $con = mysql_connect("***","***","***") or die('Could not connect: ' . mysql_error()); mysql_select_db("legion", $con); $result = mysql_query("SELECT * FROM elections"); while($row = mysql_fetch_assoc($result)){ echo "ID: ".$row['id']." - ".$row['articlename']." -- ".$row['date']."<br/><br/> ".$row['description']."<br/><br/>"; } // end if ini_set ("display_errors", "1"); error_reporting(E_ALL); // find out how many rows are in the table $sql = "SELECT COUNT(*) FROM elections"; $result = mysql_query($sql) or die(mysql_error()); $r = mysql_fetch_row($result); $numrows = $r[0]; // number of rows to show per page $rowsperpage = 10; // find out total pages $totalpages = ceil($numrows / $rowsperpage); // get the current page or set a default if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) { // cast var as int $currentpage = (int) $_GET['currentpage']; } else { // default page num $currentpage = 1; } // end if // if current page is greater than total pages... if ($currentpage > $totalpages) { // set current page to last page $currentpage = $totalpages; } // end if // if current page is less than first page... if ($currentpage < 1) { // set current page to first page $currentpage = 1; } // end if // the offset of the list, based on current page $offset = ($currentpage - 1) * $rowsperpage; // get the info from the db $sql = "SELECT id, number FROM elections LIMIT $offset, $rowsperpage"; $result = mysql_query($sql) or trigger_error("SQL", E_USER_ERROR); // while there are rows to be fetched... while ($list = mysql_fetch_assoc($result)) { // echo data echo $list['id'] . " : " . $list['number'] . "<br />"; } // end while /****** build the pagination links ******/ // range of num links to show $range = 3; // if not on page 1, don't show back links if ($currentpage > 1) { // show << link to go back to page 1 echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> "; // get previous page num $prevpage = $currentpage - 1; // show < link to go back to 1 page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> "; } // end if // loop to show links to range of pages around current page for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) { // if it's a valid page number... if (($x > 0) && ($x <= $totalpages)) { // if we're on current page... if ($x == $currentpage) { // 'highlight' it but don't make a link echo " [<b>$x</b>] "; // if not current page... } else { // make it a link echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> "; } // end else } // end if } // end for // if not on last page, show forward and last page links if ($currentpage != $totalpages) { // get next page $nextpage = $currentpage + 1; // echo forward link for next page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> "; // echo forward link for lastpage echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> "; } // end if /****** end build pagination links ******/ ?>
-
Ok, the errors are gone, the only error left is
Fatal error: SQL in D:\hosting\member\264legion\site1\elections\index.php on line 242
PHP Fatal error: SQL in D:\hosting\member\264legion\site1\elections\index.php on line 242
-
ou onl,y need to use
mysql_query($sql);
since mysql_query will use the current open conection.
you ca use if(isset($variable)){ /* do somethign with this variable */ }
to rid yourself of those "PHP Notice: Undefined variable" errors.
I fixed that portion, the error is still appearing though
-
Ok, done,
Now its displaying the news articles, but its not creating the pagination, here are the errors its returning:
The weird thing is this script is only 100 lines, it doesn't go to 208
Notice: Undefined variable: conn in D:\hosting\member\264legion\site1\elections\index.php on line 208
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in D:\hosting\member\264legion\site1\elections\index.php on line 208
Fatal error: SQL in D:\hosting\member\264legion\site1\elections\index.php on line 208
PHP Notice: Undefined variable: conn in D:\hosting\member\264legion\site1\elections\index.php on line 208 PHP Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in D:\hosting\member\264legion\site1\elections\index.php on line 208 PHP Fatal error: SQL in D:\hosting\member\264legion\site1\elections\index.php on line 208
-
Hey,
Yeah I quickly read through the tutorial to get an idea of what it is that needs to be done...Then I applied it to my code..I believe error reporting is turned...But here is the code, if you want to check it out
<?php $con = mysql_connect("","","") or die('Could not connect: ' . mysql_error()); mysql_select_db("legion", $con); $result = mysql_query("SELECT * FROM elections"); while($row = mysql_fetch_assoc($result)){ echo "ID: ".$row['id']." - ".$row['articlename']." -- ".$row['date']."<br/><br/> ".$row['description']."<br/><br/>"; } // end if // find out how many rows are in the table $sql = "SELECT COUNT(*) FROM elections"; $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); $r = mysql_fetch_row($result); $numrows = $r[0]; // number of rows to show per page $rowsperpage = 10; // find out total pages $totalpages = ceil($numrows / $rowsperpage); // get the current page or set a default if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) { // cast var as int $currentpage = (int) $_GET['currentpage']; } else { // default page num $currentpage = 1; } // end if // if current page is greater than total pages... if ($currentpage > $totalpages) { // set current page to last page $currentpage = $totalpages; } // end if // if current page is less than first page... if ($currentpage < 1) { // set current page to first page $currentpage = 1; } // end if // the offset of the list, based on current page $offset = ($currentpage - 1) * $rowsperpage; // get the info from the db $sql = "SELECT id, number FROM elections LIMIT $offset, $rowsperpage"; $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); // while there are rows to be fetched... while ($list = mysql_fetch_assoc($result)) { // echo data echo $list['id'] . " : " . $list['number'] . "<br />"; } // end while /****** build the pagination links ******/ // range of num links to show $range = 3; // if not on page 1, don't show back links if ($currentpage > 1) { // show << link to go back to page 1 echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> "; // get previous page num $prevpage = $currentpage - 1; // show < link to go back to 1 page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> "; } // end if // loop to show links to range of pages around current page for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) { // if it's a valid page number... if (($x > 0) && ($x <= $totalpages)) { // if we're on current page... if ($x == $currentpage) { // 'highlight' it but don't make a link echo " [<b>$x</b>] "; // if not current page... } else { // make it a link echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> "; } // end else } // end if } // end for // if not on last page, show forward and last page links if ($currentpage != $totalpages) { // get next page $nextpage = $currentpage + 1; // echo forward link for next page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> "; // echo forward link for lastpage echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> "; } // end if ?>
-
Hey there,
Ok tried out this tutorial, customized it to my db...and applied it to my page, but its not displaying any
news articles at all. Im not getting any errors from the script, my page is just coming up blank..
-
Hello,
I have a real simple question, I have a php script that displays news articles on a page...Im curious as to what would I add to this script to tell it after every 4 articles, add a new page - and Id just want it to start creating page numbers like:
Page: [1], [2], [3]
<?php $con = mysql_connect("***","***","****") or die('Could not connect: ' . mysql_error()); mysql_select_db("***", $con); $result = mysql_query("SELECT * FROM elections"); while($row = mysql_fetch_assoc($result)){ echo "ID: ".$row['id']." - ".$row['articlename']." -- ".$row['date']."<br/><br/> ".$row['description']."<br/><br/>"; } ?><
Any help is appreciated - thanks!
-
Thanks You!
-
Hello,
I have a script, that retrieves a record from a MySQL database,but right now its displaying all the information it retrieves on one line...But I want it to display the ID and Article Name on one line, then the "Article" on the line below that...So How would I create like a line break after the article name, so the description displays below ID and Article Name
Code:
<?php $con = mysql_connect("","","") or die('Could not connect: ' . mysql_error()); mysql_select_db("legion", $con); $result = mysql_query("SELECT * FROM signalscadet"); while($row = mysql_fetch_assoc($result)){ echo "ID: ".$row['id'].", Article Name:".$row['articlename'] .", Date:".$row['date'].", Description:".$row['description']."<br/>"; } ?>
Thanks,
-
Hello,
I recently developed a PHP script that allows users to upload files into a MySQL database.
My next step is having a PHP page that shows the files by
ID | File Name
And the File Name should be linked to the file so when a user clicks on the file name, it starts downloading the file....
Ive tried doing it a few different ways, but none of my methods seem to work...I was wondering if anyone had any advice (my script is below, and the script that inserts the file into the db)
This script does not link the file name to the file, I couldn't seem to get that part to work!
Thanks
Display.php
<?php // Connects to your Database mysql_connect("", "", "") or die(mysql_error()); mysql_select_db("Database_Name") or die(mysql_error()); $data = mysql_query("SELECT * FROM uploads") or die(mysql_error()); Print "<table border cellpadding=3>"; while($info = mysql_fetch_array( $data )) { Print "<tr>"; Print "<th>ID:</th> <td>".$info['id'] . "</td> "; Print "<th>File Name:</th> <td>".$info['filename'] . " </td></tr>"; } Print "</table>"; ?>
Insert-Into-Db.php
<?php mysql_connect("","",""); mysql_select_db(""); $data = addslashes(fread(fopen($form_data, "r"), filesize($form_data))); $result=MYSQL_QUERY("INSERT INTO uploads (description, data,filename,filesize,filetype) ". "VALUES ('$form_description','$data','$form_data_name','$form_data_size','$form_data_type')"); $id= mysql_insert_id(); print "<p>File ID: <b>$id</b><br>"; print "<p>File Name: <b>$form_data_name</b><br>"; print "<p>File Size: <b>$form_data_size</b><br>"; print "<p>File Type: <b>$form_data_type</b><p>"; print "To upload another file"; ?>
-
You know what
Duh, duh duh! lol - I should have noticed that, what silly mistake...You know sometimes it happens
I appreciate your input, it certainly was useful
-
Hmm, ok I did an echo "$sql"; and the page was just blank.
I fixed the html form where the article name is and changed it to articlename
instead of what it was(I think it was title)...
And the name or date still isn't submitting
Well the date is, its just submitting as 0000-00-00
-
<form name="input" action="cadethandle.php" method="post"> <p><strong>Article Name: <Article Date:<br> </strong> <input class="pretty" style="WIDTH: 155px" maxLength="100" size="10" name="title"> <input class="pretty" style="WIDTH: 155px" maxLength="100" size="10" value="YYYY-MM-DD" name="date1"><br> <br> </p> <p><strong>Event: <br> </strong> <textarea style="WIDTH: 296px; HEIGHT: 104px" name="description" rows="1" cols="50">Event Description </textarea></p> <p style="margin-left: 10; margin-right: 10; margin-top: 10" class="style5"> <input type="submit" value="Submit The Event">
-
Hello,
I have an html form that users fill out the following fields: <article-name><article-date><article-description>
Im testing it out and when you submit the form, article-description submits into the data base, and article-name submits into the database, and article-date does as well...However for some reason if I put 2008-10-05 in the text box it submits into the database as 0000-00-00, and the article name isn't submitting at all
Would anyone know why that is happening? Ive included the SQL from the table I have created in PHPMyAdmin, and the php code that does the inserting...thanks!
CREATE TABLE `legion`.`cadet_Testing` ( `id` INT( 4 ) NOT NULL AUTO_INCREMENT PRIMARY KEY , `articlename` TEXT NOT NULL , `date` DATE NOT NULL , `description` VARCHAR( 100 ) NOT NULL ) ENGINE = MYISAM
Here is the script that inserts the data into the MySQL db
<?php $con = mysql_connect("***","***","***") or die('Could not connect: ' . mysql_error()); mysql_select_db("***", $con); $sql="INSERT INTO cadet_Testing (articlename, date, description) VALUES ('".$_POST['articlename']."','".$_POST['date']."','".$_POST['description']."')"; $query = mysql_query($sql,$con) or die('Error: ' . mysql_error()); if ($query) { echo "Your Event has been added";mysql_close($con); } else { echo "Not added."; } ?>
-
The date is still submitting into the database as 0000-00-00
Any thought
-
I have a script that users fill out a simple form > it inserts into the database, but the date field is not submitting into the database...Well it is submitted, except the date is being inserted into the database as all zeros in this format 00-00-0000.
Does anyone know why its submitting the date is submitting into my database in PHPMyAdmin like that?
In PHPMyAdmin I have selected as "Date" from the drop down for the date field.
Here is the script that inserts the values: Incase it helps
- Note, Im not getting any errors submitting the only problem is the script is submitting the date as 00-00-0000 into the table in phpmyadmin
<?php $con = mysql_connect("","",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("legion", $con); $sql="INSERT INTO cadet_events (eventname, eventdate, eventdescription) VALUES ('$_POST[eventname]','$_POST[eventdate]','$_POST[eventdescription]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "The Event Has Been Added - Thank You"; mysql_close($con) ?>
-
That looks right Ill try it, - Make sure Im not backwards here...the form field for changing the password is called
password...
The column in the database where the passwords are stored is called pass
so should it be like this:
$sql = "UPDATE users SET password = pass('$pass') WHERE uid = '{$_SESSION['uid']}'";
Or should it be the way you put it?
$sql = "UPDATE users SET pass = pass('$pass') WHERE uid = '{$_SESSION['uid']}'";
-
Oh, Yep
Mchl is right...
My script will ONLY work if you are retrieving data from an SQL database, if you just have a table with data on a webpage - this query wont work he is right!
Thanks!
-
Ok, thank god because I still haven't got it working - and that didn't work- so I changed it all back...Yeah I removed the .
Here is the current script if you want to take a stab at it..I also included the form that the user fills out:
update.php
<?php session_start(); ?> <form action="require.php" method="POST"> Old Password:<br> <font face="Verdana" size="2"> <input title="Your Google Toolbar can fill this in for you. Select AutoFill" tabindex="4" maxlength="90" size="39" name="oldpassword" style="height: 22px;" type="oldpassword"><br> <br> New Password</font>: font face="Verdana" size="2"> <input title="Your Google Toolbar can fill this in for you. Select AutoFill" tabindex="4" maxlength="90" size="39" name="password" style="height: 22px;" type="password">
require.php
<?php session_start(); $host=""; // Host name $username=""; // Mysql username $password=""; // Mysql password $db_name=""; // Database name // Connect to DB mysql_connect ( $host, $username, $password, $db_name)or die("Could not connect: ".mysql_error()); mysql_select_db($db_name); $password=$_POST['password']; $sql = "UPDATE users SET pas = pass('$pass')". WHERE uid = '{$_SESSION['uid']}'"; // Step 3 $result = mysql_query($sql) or die ( mysql_error() ); ?>
-
Yep use something like this
<tr> <td style="width: 279px"> <table class="top"> <tr> <td style="width: 95px" class="style10"><strong>Resturant</strong></td> <td style="width: 93px" class="style10"><strong>Stores</strong> </td> <td style="width: 93px" class="style10"><strong>Officies</strong></td> </tr> <? mysql_connect("***","**","**");//database connection mysql_select_db("legion"); $order = "SELECT * FROM tbl_name ORDER BY RESTURANT"; // Where I put Resturant you can change that to stories, offices etc.. $result = mysql_query($order); while($data = mysql_fetch_row($result)){ echo("<tr><td>$data[0]</td><td>$data[6]</td><td>$data[7]</td><td>$data[1]</td></tr>"); } ?>
Above where you see the <Td>$data[0]</td>
where you see the number in the brackets, change that to the column number of whatever columns in your my-sql db
-
Oh, I see I see
- so - the script things Im calling $password from above when I declared it to connect to the database, when Im not calling that...
Thanks!!
- Jeff
Indexing Pages
in PHP Coding Help
Posted
Hey,
Ok, well that makes sense, echo the query...but after thats done how would I alter the query - so that it only displays four news-article entries per-page.
This is a first for doing pagination for me, so I appreciate all the help
thanks!