careym1989 Posted September 20, 2008 Share Posted September 20, 2008 Hello, I'm here to bother you guys again! When I use my homegrown CMS and add a press hit, it enters it into the MySQL database "press" Is there anyway I could have all of the information stored under that $id in the database be displayed on a page. Perhaps, archive.php?id=$id of record in database? A tutorial or a code snippet would be great. I assume I'm using the $_GET variable but I'm still learning. Regards, Carey Link to comment https://forums.phpfreaks.com/topic/125030-add-press-hit-as-archivephpidid/ Share on other sites More sharing options...
careym1989 Posted September 20, 2008 Author Share Posted September 20, 2008 And when I say database "press" I mean table "press." My mistake. Link to comment https://forums.phpfreaks.com/topic/125030-add-press-hit-as-archivephpidid/#findComment-646122 Share on other sites More sharing options...
dropfaith Posted September 20, 2008 Share Posted September 20, 2008 <?php // includes include("../template/conf.php"); // open database connection $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); // select database mysql_select_db($db) or die ("Unable to select database!"); // generate and execute query $Id = mysql_escape_string($_GET['Id']); $query = "SELECT * FROM blog WHERE Id = '$Id'"; $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error()); // get resultset as object $row = mysql_fetch_object($result); // print details if ($row) { ?> Echo out the content here <?php } else { ?> <p> <font size="-1"> could not be located in our database.</font> <?php } // close database connection mysql_close($connection); ?> Link to comment https://forums.phpfreaks.com/topic/125030-add-press-hit-as-archivephpidid/#findComment-646129 Share on other sites More sharing options...
careym1989 Posted September 20, 2008 Author Share Posted September 20, 2008 Hey man, Thanks for the speedy reply, but: I've changed all the information (connect, database, table, etc) and I've fiddled with the code a little bit, but all it's echoing back to me is "could not be located in our database." Regards, Carey Link to comment https://forums.phpfreaks.com/topic/125030-add-press-hit-as-archivephpidid/#findComment-646141 Share on other sites More sharing options...
xtopolis Posted September 20, 2008 Share Posted September 20, 2008 Be sure your link is correct, or change the code provided... I noticed your original post has a lowercase $id, while the code provided to you had an uppercase $Id which is not the same variable to php. That may be it. Link to comment https://forums.phpfreaks.com/topic/125030-add-press-hit-as-archivephpidid/#findComment-646143 Share on other sites More sharing options...
careym1989 Posted September 20, 2008 Author Share Posted September 20, 2008 Thanks for the heads-up. I did change that stuff in my script. As previously stated, I still get "could not connect..." -Carey Link to comment https://forums.phpfreaks.com/topic/125030-add-press-hit-as-archivephpidid/#findComment-646149 Share on other sites More sharing options...
dropfaith Posted September 20, 2008 Share Posted September 20, 2008 you need conf.php where that include is it includes the connection details replace your include with this <?php // conf.php - configuration parameters // database configuration $host = "localhost"; $user = "Username"; $pass = "Password"; $db = "Database"; ?> Link to comment https://forums.phpfreaks.com/topic/125030-add-press-hit-as-archivephpidid/#findComment-646230 Share on other sites More sharing options...
careym1989 Posted September 20, 2008 Author Share Posted September 20, 2008 Okay. I've fixed the record doesn't exist problem. Now, it displays nothing. I did alternate the code a little bit: <?php // includes include("includes/conf.php"); // open database connection $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); // select database mysql_select_db($db) or die ("Unable to select database!"); // generate and execute query $id = mysql_escape_string($_GET['id']); $query = "SELECT * FROM press WHERE id = '$id'"; $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error()); // get resultset as object $row = mysql_fetch_object($result); // print details if ($row) { echo "$row[id]"; } else { echo "This record does not exist in our database. Go back and try again!"; } mysql_close($connection); ?> EDIT: I added in: error_reporting(E_ALL); And there are no errors. Link to comment https://forums.phpfreaks.com/topic/125030-add-press-hit-as-archivephpidid/#findComment-646618 Share on other sites More sharing options...
redarrow Posted September 20, 2008 Share Posted September 20, 2008 or die (mysql_error()) also echo the select out .... looks like the id not there cheek Link to comment https://forums.phpfreaks.com/topic/125030-add-press-hit-as-archivephpidid/#findComment-646682 Share on other sites More sharing options...
careym1989 Posted September 20, 2008 Author Share Posted September 20, 2008 Sorry, I should echo out select, meaning the $query string? -Carey Link to comment https://forums.phpfreaks.com/topic/125030-add-press-hit-as-archivephpidid/#findComment-646710 Share on other sites More sharing options...
careym1989 Posted September 21, 2008 Author Share Posted September 21, 2008 For some reason I can't modify my previous post. My current issue is that when I visit the page that I used the script in, nothing is displayed. Error reporting is on ALL and no errors come up. Help would be appreciated. Link to comment https://forums.phpfreaks.com/topic/125030-add-press-hit-as-archivephpidid/#findComment-646778 Share on other sites More sharing options...
chronister Posted September 21, 2008 Share Posted September 21, 2008 $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error()); // get resultset as object echo mysql_num_rows($result); // add this to see if you have any data returned from the query. $row = mysql_fetch_object($result); // print details Note the mysql_num_rows line.... this will tell you if you are getting results from the database. Post back with the result. It will be a number 0 or greater. Link to comment https://forums.phpfreaks.com/topic/125030-add-press-hit-as-archivephpidid/#findComment-646779 Share on other sites More sharing options...
careym1989 Posted September 21, 2008 Author Share Posted September 21, 2008 I do press_archive.php?id=21 and it displays a "1." For the ones that do not have a record it displays 0, which makes sense! There you go, man! lol -Carey Link to comment https://forums.phpfreaks.com/topic/125030-add-press-hit-as-archivephpidid/#findComment-646786 Share on other sites More sharing options...
redarrow Posted September 21, 2008 Share Posted September 21, 2008 where ur code man the recent one please post whole code........... Link to comment https://forums.phpfreaks.com/topic/125030-add-press-hit-as-archivephpidid/#findComment-646809 Share on other sites More sharing options...
chronister Posted September 21, 2008 Share Posted September 21, 2008 So if your getting data from the DB, then it is a matter of showing it. Post the code you use for displaying the data. Nate Link to comment https://forums.phpfreaks.com/topic/125030-add-press-hit-as-archivephpidid/#findComment-646837 Share on other sites More sharing options...
careym1989 Posted September 21, 2008 Author Share Posted September 21, 2008 Here it is: <?php error_reporting(E_ALL); // includes include("includes/conf.php"); // open database connection $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); // select database mysql_select_db($db) or die ("Unable to select database!"); // generate and execute query $id = mysql_escape_string($_GET['id']); $query = "SELECT * FROM press WHERE id = '$id'"; $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error()); echo mysql_num_rows($result); // add this to see if you have any data returned from the query. // get resultset as object $row = mysql_fetch_object($result); // print details if ($row) { echo "$row[id]"; // obviously I want more to show up, this was just a test to see if it was working. Doesn't echo record id back. } else { echo "This record does not exist in our database. Go back and try again!"; } mysql_close($connection); ?> Link to comment https://forums.phpfreaks.com/topic/125030-add-press-hit-as-archivephpidid/#findComment-646857 Share on other sites More sharing options...
redarrow Posted September 21, 2008 Share Posted September 21, 2008 are u sure that the url got the id in it.......... echo the get out while trying Link to comment https://forums.phpfreaks.com/topic/125030-add-press-hit-as-archivephpidid/#findComment-646880 Share on other sites More sharing options...
chronister Posted September 21, 2008 Share Posted September 21, 2008 $row = mysql_fetch_object($result); // print details if ($row) { echo "$row[id]"; // obviously I want more to show up, this was just a test to see if it was working. Doesn't echo record id back. } else { echo "This record does not exist in our database. Go back and try again!"; } Here is your problem.... your using mysql_fetch_object and then trying to display the result as an array. I suggest doing this.. while($row = mysql_fetch_object($result)) { echo $row->id.'<br>'; } This basically is saying while there are rows to fetch as objects, echo them. take a look at the manual at the mysql_fetch_* functions. There are several of them. Your trying to echo the data as if you used mysql_fetch_assoc(); Nate Link to comment https://forums.phpfreaks.com/topic/125030-add-press-hit-as-archivephpidid/#findComment-646883 Share on other sites More sharing options...
redarrow Posted September 21, 2008 Share Posted September 21, 2008 i missed that dam lol Link to comment https://forums.phpfreaks.com/topic/125030-add-press-hit-as-archivephpidid/#findComment-646884 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.