User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 392,271 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,675 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 2737 | Replies: 4 | Solved
Reply
Join Date: May 2006
Posts: 4
Reputation: Fel is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Fel Fel is offline Offline
Newbie Poster

mysql errors, from submit.php and index.php

  #1  
May 28th, 2006
Hey, I've been trying to code my own news/ blogging script, by following a tutorial, but unfortunately I keep getting these mysql errors when I submit an entry, and on the page where I want it to be displayed. And I don't know how to recognize the errors just by looking at the number line, or how to fix it.

index.php
<?php 

//$hostname="placid1.placid-soul.org";
$user="xxx"; //user name to access database
$pass= "xxx"; //password 
$dbase="xxx"; //database name

$q = "select * from blog order by date desc "; 
$result= mysql_query($q, $connection) or die 
("Could not execute query : $q." . mysql_error()); 

// dynamic navigation variables 
$rows_per_page=1; // adjust the number here to display number of entries per page 
$total_records=mysql_num_rows($result); 
$pages = ceil($total_records / $rows_per_page); 

$screen = $_GET["screen"]; 
if (!isset($screen)) 
$screen=0; 
$start = $screen * $rows_per_page; 
$q .= "LIMIT $start, $rows_per_page"; 
$result= mysql_query($q, $connection) or die 
("Could not execute query : $q." . mysql_error()); 

while ($row=mysql_fetch_array($result)) 
{ 
    $id=$row["id"]; 
    $name=$row["name"]; 
    $email=$row["email"]; 
    $entry=$row["entry"]; 
    $date=$row["date"]; 
    $icon=$row["icon"]; 
    $title=$row["title"]; 

?> 

    <table width="345" border="0" cellspacing="1" cellpadding="0" class="updates"> 
    <tr> 
    <td><h1><?php echo "$title"; ?></h1></td> 
    </tr> 
    <tr> 
    <td> 
    <img src="<?php echo "$icon"; ?>" alt="icon" align="left"><?php echo "$entry"; ?>
    <p>Posted by <a href="mailto:<?php echo "$email"; ?>"><?php echo "$name"; ?> on <?php echo "$date"; ?>.</p> 
    </td> 
    </tr> 
    </table> 
     
    <div align="center"> 

<?php 
} #end of while 

// Display dynamic navigation here 

// create the dynamic links 
if ($screen > 0) { 
    $j = $screen - 1; 
    $url = "display.php?screen=$j"; 
    echo "<a href=\"$url\">Prev</a>"; 
} 

// page numbering links now 

for ($i = 0; $i < $pages; $i++) { 
    $url = "display.php?screen=" . $i; 
    $j = $i + 1; 
    echo " | <a href=\"$url\">$j</a> | "; 
} 

if ($screen < $pages-1) { 
    $j = $screen + 1; 
    $url = "display.php?screen=$j"; 
    echo "<a href=\"$url\">Next</a>"; 
} 

?> 

</div>

<?php include 'bottom.php'; ?>

submit.php
<?php //
$hostname="xxx";
$user="xxx"; //user name to access database
$pass= "xxx"; //password 
$dbase="xxx"; //database name
// For Global Registers off 

$name = strip_tags($_POST["name"]); 
$email = strip_tags($_POST["email"]); 
$entry = strip_tags($_POST["entry"]); 
$title = strip_tags($_POST["title"]); 
$icon =  strip_tags($_POST["icon"]); 

// Check if user submit blank entry 
if ($name == "" || $email == "" || $entry == "" || $title == "") 
{  
    die ("You must fill in all fields, please click back and try again."); 
} 

else { 
    $q="insert into blog (id,name,title,email,entry,date,icon) VALUES ('','$name','$title','$email','$entry',now(),'$icon')"; 
    $result = mysql_query($q); 
     
    if ($result)  
    { 
        echo "thank you, blog has been submitted."; 
    } 

}  
?>

And these are the errors:
index.php
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/.fiorello/felaigne/placid-soul.org/index.php on line 45
Could not execute query : select * from blog order by date desc .

submit.php
Warning: mysql_query(): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /home/.fiorello/felaigne/placid-soul.org/submit.php on line 22

Warning: mysql_query(): A link to the server could not be established in /home/.fiorello/felaigne/placid-soul.org/submit.php on line 22

I've tried looking through the search feature, and I couldn't find another thread with the same problem I have, so I thought I should create a new topic. I've tried my best to explain it, so that it's understandable at least. And if you need anymore information just let me know. =) Thank you, in advance.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: May 2006
Posts: 4
Reputation: Fel is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Fel Fel is offline Offline
Newbie Poster

Re: mysql errors, from submit.php and index.php

  #2  
May 29th, 2006
I can't seem to figure out how to edit my previous post. =\ So I'm sorry for double posting but anyways, I've solved my submission error problem, and I re-did the whole thing by using another tutorial. I had more success with it then the last one. (if you'd like the link let me know.) The only problem I'm getting now is that, my posts won't display, and it shows this instead:
Invalid ID specified.
I can't seem to figure out what's causing it to be invalid. I asked my friends about it, and they seem to think it's this line of code:
if(!isset($_GET['id']) || !is_numeric($_GET['id'])) {
    die("Invalid ID specified.");
}
There seems to something wrong with the top line, my friends and I were assuming that. Any suggestions? Also here's the new display code on index.php
<?php
mysql_connect ('xxx', 'xxx', 'xxx') ;
mysql_select_db ('xxx');

if(!isset($_GET['id']) || !is_numeric($_GET['id'])) {
    die("Invalid ID specified.");
}

$id = (int)$_GET['id'];
$sql = "SELECT * FROM php_blog WHERE id='$id' LIMIT 1";

$result = mysql_query($sql) or print ("Can't select entry from table php_blog.<br />" . $sql . "<br />" . mysql_error());

while($row = mysql_fetch_array($result)) {

    $date = date("l F d Y", $row['timestamp']);

    $title = $row['title'];
    $entry = $row['entry'];

    ?>

    <p><strong><?php echo $title; ?></strong><br /><br />
    <?php echo $entry; ?><br /><br />
    Posted on <?php echo $date; ?>
    </p>

    <?php
}

?>

<?php include 'bottom.php'; ?>	
Reply With Quote  
Join Date: May 2006
Location: Italy
Posts: 9
Reputation: Astegiano is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 1
Astegiano's Avatar
Astegiano Astegiano is offline Offline
Newbie Poster

Re: mysql errors, from submit.php and index.php

  #3  
May 29th, 2006
The problem is in the sintax of the if statement. When you write a if clause with two argument you shoulw write it like

if ( (firt argument) || (second argument) )

I think that's the problem with your code.
You should change your code to
[php]if ((!isset($_GET['id'])) || (!is_numeric($_GET['id']))) {
die("Invalid ID specified.");
}[/php]
Reply With Quote  
Join Date: May 2006
Posts: 4
Reputation: Fel is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Fel Fel is offline Offline
Newbie Poster

Re: mysql errors, from submit.php and index.php

  #4  
May 29th, 2006
Thanks for the input, but unfortunately, I've tried changing my code to that, and the entrie(s) still won't display. I still get this:
Invalid ID specified.
Reply With Quote  
Join Date: May 2006
Posts: 4
Reputation: Fel is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Fel Fel is offline Offline
Newbie Poster

Re: mysql errors, from submit.php and index.php

  #5  
May 30th, 2006
Nevermind, I found out my error, I kept going to the wrong location. xD;
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb PHP Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 8:06 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC