[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Submit

Posted on 2002-04-02
6
Medium Priority
?
165 Views
Last Modified: 2006-11-17
the following code doesn't work :'( plzzzzz help me with it..
---------------------------------------------------------
<?
 mysql_connect("localhost","","") or  die ("Unable to connect to database");
 mysql_select_db("test_toaster") or die ("Unable to select database test_toaster");

 if ($Private!="Y") { $Private="N";}

 $question_insert = mysql_query("INSERT INTO question VALUES ('','$Content','Fill in','','','$Private',4,$Difficulty_Level,1111,2222)");
 $id=mysql_insert_id ();

   if ($answer1!="")
   $answer1_insert=mysql_query("INSERT INTO question_correct_answers (question_id,correct_answer) VALUES ($id,'$answer1')");
   if ($answer2!="")
   $answer2_insert=mysql_query("INSERT INTO question_correct_answers (question_id,correct_answer) VALUES ($id,'$answer2')");
   if ($answer3!="")
   $answer3_insert=mysql_query("INSERT INTO question_correct_answers (question_id,correct_answer) VALUES ($id,'$answer3')");   $answer_insert=mysql_query("INSERT INTO question_correct_answers (question_id,correct_answer) VALUES ($id,'$answer1')");
   if ($answer4!="")
   $answer4_insert=mysql_query("INSERT INTO question_correct_answers (question_id,correct_answer) VALUES ($id,'$answer4')");

 if (($question_insert== TRUE) and (($answer1_insert==TRUE) || ($answer2_insert==TRUE) || ($answer3_insert==TRUE) ||($answer4_insert==TRUE))
 {
   print "Your question has be successfully stored<BR>";
 }
 mysql_close();
?>
0
Comment
Question by:almaha
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 5

Accepted Solution

by:
andriv earned 40 total points
ID: 6913036
did you remove your username and password from the following line for security or there isn't any.

mysql_connect("localhost","","") or  die ("Unable to connect to database");

mysql_select_db("test_toaster",$dblink) or die ("Unable to select database test_toaster");

If it's because you don't have any set then use:

mysql_connect("localhost")

Also store the return link to a variable and use it within the other mysql queries:

$dblink = mysql_connect("localhost")

$question_insert = mysql_query("INSERT INTO question VALUES ('','$Content','Fill in','','','$Private',4,$Difficulty_Level,1111,2222),$dblink");

And do the same for the other queries.

If this is not the problem tell me what error message you are getting or what is not happening.



0
 
LVL 2

Expert Comment

by:Marsman_
ID: 6913078
You really do not need to save the return thing from the database, php does this automatically when you only have one db-connection.

I see something very wrong in your script:

if (($question_insert== TRUE) and (($answer1_insert==TRUE) || ($answer2_insert==TRUE) || ($answer3_insert==TRUE)
||($answer4_insert==TRUE))

This of course should be:

if (($question_insert== TRUE) && (($answer1_insert==TRUE) || ($answer2_insert==TRUE) || ($answer3_insert==TRUE)
||($answer4_insert==TRUE))

Php doesn't recognize "and" instead use "&&" 

 
0
 

Author Comment

by:almaha
ID: 6913438
ThX andriv. the query syntax was part of the problem. the major problem was the the conditional statement with one and the 4 or's.
Marsman, PHP recognizes "and"! it works with me in another scripts..
Finally the code is working with me. here you go:
-------------------------------------------
<?
 mysql_connect("localhost","","") or  die ("Unable to connect to database");
 mysql_select_db("test_toaster") or die ("Unable to select database test_toaster");

 if ($Private!="Y") { $Private="N";}

 $question_insert = mysql_query("INSERT INTO question VALUES ('','$Content','Fill in','','','$Private',4,$Difficulty_Level,1111,2222)");
 $id=mysql_insert_id ();

   if ($answer1!="")
   $answer1_insert=mysql_query("INSERT INTO question_correct_answers (question_id,correct_answer) VALUES ($id,'$answer1')");
   if ($answer2!="")
   $answer2_insert=mysql_query("INSERT INTO question_correct_answers (question_id,correct_answer) VALUES ($id,'$answer2')");
   if ($answer3!="")
   $answer3_insert=mysql_query("INSERT INTO question_correct_answers (question_id,correct_answer) VALUES ($id,'$answer3')");
   if ($answer4!="")
   $answer4_insert=mysql_query("INSERT INTO question_correct_answers (question_id,correct_answer) VALUES ($id,'$answer4')");

 //if (($question_insert== TRUE) and ((((($answer1_insert==TRUE) || ($answer2_insert==TRUE)) || (($answer3_insert==TRUE))) ||($answer4_insert==TRUE))
 $first_two = ($answer1_insert==TRUE) || ($answer2_insert==TRUE);
 $second_two = ($answer3_insert==TRUE) || ($answer4_insert==TRUE);
 $answers_insert = ($first_two==TRUE) || ($second_two==TRUE);

 if  (($question_insert== TRUE) and  ($answers_insert==TRUE))
 {
   print "Your question has be successfully stored<BR>";
 }
 mysql_close();
?>
-------------------------------------------------------
ThX guys,
that was really helpful :)
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 5

Expert Comment

by:andriv
ID: 6913449
Glad we can help
0
 
LVL 2

Expert Comment

by:Marsman_
ID: 6913905
It does!?
That's pretty weird!
0
 
LVL 5

Expert Comment

by:andriv
ID: 6913966
Marsman you can also use "or" instead of ||

most people do not use "and" or "or" because it makes it harder to spot an error.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question