Jump to content

[SOLVED] PHP/MySQL problem


mohaakilla51

Recommended Posts

[random side note] Hello Everyone, I am MOHAAkilla516. I have been coding HTML/Javascript for about 4 years now. I finally decided to upgrade to CSS and PHP. That is why I am here [/side note]

 

OK, so I am trying to create a method for creating resources (Tutorial, Articles, etc.) From registered memberes of my site. Here is the code I am using to try to do this (Without all the formatting and etc.):

<html>
<head>
<?php mysql_connect("localhost","root",""); 
mysql_select_db("if_847191_resources"); ?>
<title><?php 
$title = $_GET['article'];
echo $title;
?>
</title>
</head>
<body>
<?php
$title = $_GET['article']; //Yeah yeah, I know that was unneccessary. Is this the proper syntax for a comment in PHP?
$article = mysql_query("SELECT * FROM article WHERE title==$title");

echo $article['body'];
echo "that was the article";
?>
</body>
</html>

I am able to connect to the database without problem. The only problem I get it that I only get a blank page, with no article! The URL I have is blah.com/resources.php?article=Test Where resources is the above page. Here is a screen shot of PHPMyAdmin:

image.php?a7e5a2c4a5.jpg

OR, If you can't see that: Click Here

So the table exists. THe Data Exists. What am I doing wrong?

Link to comment
Share on other sites

 

edited try now.

 

try that before i rewrite it all lol

<html>
<head>

<?php 

//if password exist.
$db=mysql_connect("localhost","root","password");
mysql_select_db("if_847191_resources",$db); 

?>

<title>
<?php 
$title = $_GET['article'];
echo $title;
?>
</title>
</head>
<body>
<?php

$title=$_POST['title'];

$query = "SELECT * FROM article";

$result-mysql_query($query) or die("mysql_error()");

while($article=mysql_fetch_assoc($result)){

$a=$article['body'];

echo "$a that was the article";

}
?>
</body>

</html>

Link to comment
Share on other sites

try now please

<?php 

$db=mysql_connect("localhost","root","");
mysql_select_db("if_847191_resources",$db); 

$query = "SELECT * FROM article";

$result-mysql_query($query) or die("mysql_error()");

while($article=mysql_fetch_assoc($result)){

$a=$article['body'];

echo "$a that was the article";

}
?>

Link to comment
Share on other sites

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\wamp\www\acdec\resource.php on line 28

I have no idea what that Mysql_fetch_assoc is so I do not know how to fix this... BTW, thanks for the help so far red arrow... YOU ROCK

Link to comment
Share on other sites

<?php 

$db=mysql_connect("localhost","root","");
mysql_select_db("if_847191_resources",$db); 

$query = "SELECT * FROM article";

$result=mysql_query($query) or die("mysql_error()");

while($article=mysql_fetch_assoc($result)){

$a=$article['body'];

echo "$a that was the article";

}
?>

Link to comment
Share on other sites

I think this part of code is wrong..

 


$title = $_GET['article']; //Yeah yeah, I know that was unneccessary. Is this the proper syntax for a comment in PHP?
$article = mysql_query("SELECT * FROM article WHERE title==$title");

 

try to change..

 


$title = $_GET['article']; //Yeah yeah, I know that was unneccessary. Is this the proper syntax for a comment in PHP?
$article = mysql_query("SELECT * FROM article WHERE title=$title");
$data = $mysql_fetch_array($article);
# check if there's query result
print_r($data); exit;

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.