Jump to content

Is it possible to continue with the rest of the code on an mysql error?


flit

Recommended Posts

Hi there,

 

I don't know how to explain this:

I have some id's saved in a session

I used the foreach (idArray as $id) to execute the following mysql query

 

$query = "SELECT * FROM books where id=$id";

 

When I echo $id I see 1,2,3, and the last , makes mysql give me an error

Is it possible to continue with the rest of my code after an mysql error or is there some

other way to prevent this? I want to get rid of the , so the code can continue

Link to comment
Share on other sites

Thanks both solutions worked, but now I have another problem

When I run the code I do not receive an error message any more but the

output is not what I wanted. I receive something like this

 

Title:  //without anything

Author: //without anything

ISBN: //without anything

 

Link to comment
Share on other sites

foreach ($idArray as $id);

{

$query = "SELECT * FROM books where id=$id";

$result = mysql_query($query) or $id = trim($id, ',');

$row = mysql_fetch_array($result);

 

echo "Title: ".$row['title'];

echo "<br>";

echo "Author : ".$row['author'];

echo "<br>";

echo "ISBN: ".$row['isbn'];

 

.........

 

 

 

Link to comment
Share on other sites

Ow sorry Barrand. I don't understand what you mean.

 

But the program is supposed to run like this

There are some session id's in a session file

sessionvar|s:7:"3,2,1";

 

The code creates a session id

-> foreach

The code echos for every id in the session info from an msql data

 

echo "Title :".$row['id'];

 

But when I press to refresh in my browser, there comes some

info, but no mysql data

 

I don't know if I understood you correctly but is this what you meant??

Link to comment
Share on other sites

It outputs,

 

1 Connected Successfully Array([0]=>1[1] =>1)

 

 

-->

Array

(

      [0] => 1

      [1] => 1

      [2] =>

      [3] =>

 

)

 

The program works fine until I refresh the page

 

 

 

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.