ahmed17 Posted September 13, 2006 Share Posted September 13, 2006 hello, i write this script but not add any joke to my database [code]<?php/* ============================================================= *//* *//* *//* Author:eng:ahmed _bohoty *//* *//* *//* *//* ============================================================= */?><html><head> <title>The Internet Joke Database</title></head><body><?php$host="localhost"; //the name of localhost$user=""; //username$pass=""; // mypasswd$database="ahmed17"; //database name which created$table="jokes"; // table nameif (isset($addjoke)): // If the user wants to add ajoke// Connect to the database server$link=mysql_connect($host,$user,$pass)or print"failed connection";// Select the jokes databasemysql_select_db($database,$link)or print"Could not open database";////////////////////////////////////////////////////////////////|\/*$sql = "CREATE TABLE Jokes ( \\ ID INT NOT NULL AUTO_INCREMENT PRIMARY KEY, \\ JokeText TEXT, \\ JokeDate DATE NOT NULL \\ )"; \\if ( @mysql_query($sql) ) { \\ echo("<p>Jokes table successfully \\created!</p>") \\} else { \\ echo("<p>Error creating Jokes table: " . mysql_error() \\. "</p>"); \\} \\///////////////////////////////////////////////////////////////*///******************************************************************************// If a joke has been submitted,// add it to the database.if($submitjoke==$SUBMIT){ $sql="INSERT INTO $table SET JokeText='$joketext',JokeDate='CURDATE()'"; if(mysql_query($sql)){ print("Your joke has been added.</p>");} else { print("Error adding submitted joke".mysql_error()); }}//******************************************************************************print"<p> Here are all the jokes in our database:</p> ";//******************************************************************************// Request the text of all the jokes$result=mysql_query("SELECT joketext FROM $table");if(!$result){ print"<b>Error Performing Query</b>".mysql_error(); exit();}//******************************************************************************// Display the text of each joke in a paragraphwhile($row=mysql_fetch_array($result)){ print("<p>" . $row["JokeText"] . "</p>");}//****************************************************************************** // When clicked, this link will load this page // with the joke submission form displayed.echo("<p><a href='$PHP_SELF?addjoke=1'>Add aJoke!</a></p>");//****************************************************************************** endif;?><form action="<?=$PHP_SELF?>"method="post"><p>Type your joke here:<br /><textarea name="joketext" rows="10" cols="40"wrap></textarea><br /><input type="submit" name="submitjoke" value="SUBMIT"/></p></form></body></html>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/20613-jokes-script-need-help/ Share on other sites More sharing options...
wildteen88 Posted September 13, 2006 Share Posted September 13, 2006 Looks like your server doesnt have register_globals enabled. So you'll need to use the superglobal arrays to access your user input.For example instead of using $PHP_SELF you should use $_SERVER['PHP_SELF'] instead. The same applies ot $joketext you shold use $_POST['joketext'] instead.You'll need to go through your code changing most of the variables to thier superglobal equivalent. Quote Link to comment https://forums.phpfreaks.com/topic/20613-jokes-script-need-help/#findComment-91012 Share on other sites More sharing options...
.josh Posted September 13, 2006 Share Posted September 13, 2006 either you have not set a whole bunch of variables, or else you seem to be coding with register_globals set to ON. I hope that you just didn't set a bunch of variables, because you shouldn't code with register_globals set to ON. if($submitjoke==$SUBMIT)if register_globals is on, then this needs to be if($submitjoke=='SUBMIT')if they are off (like they should be) then it needs to look like this:if($_POST['submitjoke']=='SUBMIT')if globals are off, then $joketext needs to be replaced with $_POST['joketext'] but either way, unless you want people to inject malicious sql coding into your query, you need to sanitize that variable, instead of inserting it directly into your query. Quote Link to comment https://forums.phpfreaks.com/topic/20613-jokes-script-need-help/#findComment-91013 Share on other sites More sharing options...
ahmed17 Posted September 13, 2006 Author Share Posted September 13, 2006 thanks wildteen.&.Crayon :)i try more but no benfit...wat i do ?if u can test script and tell me if script work or not ..and give me afree server which support php good Quote Link to comment https://forums.phpfreaks.com/topic/20613-jokes-script-need-help/#findComment-91205 Share on other sites More sharing options...
wildteen88 Posted September 13, 2006 Share Posted September 13, 2006 If you wnat to test your PHP scripts without it being hosted on the web then install AMP (Apache PHP and MySQL) by getting either WAMP (for Windows) or XAMPP (for Windows, Mac or Linix) both are free to use. Once installed you can goto http://localhost/ and you'll be able to run your PHP scripts of off your computer.Did you try our suggestions? If you did could you post the updated code here. Quote Link to comment https://forums.phpfreaks.com/topic/20613-jokes-script-need-help/#findComment-91214 Share on other sites More sharing options...
.josh Posted September 13, 2006 Share Posted September 13, 2006 uh...ahmed, that's not really how things work around here... "you try but no benefit" - so what is going wrong? repost your modified code. and...am i not understanding you, or did you just ask for free hosting? Quote Link to comment https://forums.phpfreaks.com/topic/20613-jokes-script-need-help/#findComment-91216 Share on other sites More sharing options...
ahmed17 Posted September 13, 2006 Author Share Posted September 13, 2006 I AM SORRY ..BUT I MADE ALL CAHNGES BUT NO DATA ADDED TO MY DATABASE Quote Link to comment https://forums.phpfreaks.com/topic/20613-jokes-script-need-help/#findComment-91342 Share on other sites More sharing options...
wildteen88 Posted September 13, 2006 Share Posted September 13, 2006 Thast why we are requesting to see your code. So we can see what chnages you ahve made to your code.So can you please repost the modified code here please so we can review it for any errors or problems we can see. Quote Link to comment https://forums.phpfreaks.com/topic/20613-jokes-script-need-help/#findComment-91345 Share on other sites More sharing options...
ahmed17 Posted September 14, 2006 Author Share Posted September 14, 2006 no jokes added to my database here's the code after changes[code]<!doctype html public "-//W3C//DTD HTML 4.0 //EN"><html><head> <title>Title here!</title></head><body><?php$host="localhost"; //the name of localhost$user="ahmed17"; //username$pass="123456"; // mypasswd$database="ahmed17"; //database name which created$table="jokes"; // table name$link = mysql_connect('localhost', "$user", "$pass")or print"failed connection"; mysql_select_db($database,$link)or print "not exists"; $sql="SELECT * FROM $table";$result= mysql_db_query($database,$sql,$link);$num=mysql_num_rows($result);print"<li>number of fields: $num<br><br></li>"; echo"**********************<br>";while($row=mysql_fetch_array($result)){ echo $row['id']; echo"<br>"; echo $row['JokeText']; echo"<br>"; echo $row['JokeDate']; echo"<br>"; echo"**********************<br>"; }?></body></html>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/20613-jokes-script-need-help/#findComment-91871 Share on other sites More sharing options...
karthikeyan_coder Posted September 14, 2006 Share Posted September 14, 2006 Try the below code<!doctype html public "-//W3C//DTD HTML 4.0 //EN"><html><head> <title>Title here!</title></head><body><?php$host="localhost"; //the name of localhost$user="ahmed17"; //username$pass="123456"; // mypasswd$database="ahmed17"; //database name which created$table="jokes"; // table name$link = mysql_connect('localhost', "$user", "$pass") or die(mysql_error()); mysql_select_db($database) or die(mysql_error()); $sql="SELECT * FROM '$table'";$result= mysql_db_query($database,$sql,$link);$num=mysql_num_rows($result);if($num > 0){print"<li>number of fields: $num<br><br></li>"; echo"**********************<br>";while($row=mysql_fetch_array($result)){ echo $row['id']; echo"<br>"; echo $row['JokeText']; echo"<br>"; echo $row['JokeDate']; echo"<br>"; echo"**********************<br>"; }}elseecho("There is no Jokes to be displayed");?></body></html> Quote Link to comment https://forums.phpfreaks.com/topic/20613-jokes-script-need-help/#findComment-91936 Share on other sites More sharing options...
ahmed17 Posted September 15, 2006 Author Share Posted September 15, 2006 code after changes ..but not work [code]<?php/* ============================================================= *//* *//* *//* Author:eng:ahmed _bohoty *//* *//* *//* *//* ============================================================= */?><html><head> <title>The Internet Joke Database</title></head><body><?php$host="localhost"; //the name of localhost$user="ahmed17"; //username$pass="123456"; // mypasswd$database="ahmed17"; //database name which created$table="jokes"; // table name//********************************************************if (isset($addjoke)): // If the user wants to add ajoke// Connect to the database server$link=mysql_connect($host,$user,$pass)or print"failed connection";// Select the jokes databasemysql_select_db($database,$link)or print"Could not open database";////////////////////////////////////////////////////////////////|\/*$sql = "CREATE TABLE Jokes ( \\ ID INT NOT NULL AUTO_INCREMENT PRIMARY KEY, \\ JokeText TEXT, \\ JokeDate DATE NOT NULL \\ )"; \\if ( @mysql_query($sql) ) { \\ echo("<p>Jokes table successfully \\created!</p>") \\} else { \\ echo("<p>Error creating Jokes table: " . mysql_error() \\. "</p>"); \\} \\///////////////////////////////////////////////////////////////*///******************************************************************************// If a joke has been submitted,// add it to the database.if($_POST['submitjoke']=='SUBMIT'){ $sql="INSERT INTO $table SET JokeText='$_POST['joketext'] ',JokeDate='CURDATE()'"; if(mysql_query($sql)){ print("Your joke has been added.</p>");} else { print("Error adding submitted joke".mysql_error()); }}//******************************************************************************print"<p> Here are all the jokes in our database:</p> ";//******************************************************************************// Request the text of all the jokes$result=mysql_query("SELECT joketext FROM $table");if(!$result){ print"<b>Error Performing Query</b>".mysql_error(); exit();}//******************************************************************************// Display the text of each joke in a paragraphwhile($row=mysql_fetch_array($result)){ print("<p>" . $row["JokeText"] . "</p>");}//****************************************************************************** // When clicked, this link will load this page // with the joke submission form displayed.echo("<p><a href='$PHP_SELF?addjoke=1'>Add aJoke!</a></p>");//****************************************************************************** endif;?><form action="<?=$_SERVER['PHP_SELF']?>"method="post"><p>Type your joke here:<br /><textarea name="joketext" rows="10" cols="40"wrap></textarea><br /><input type="submit" name="submitjoke" value="SUBMIT"/></p></form></body></html>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/20613-jokes-script-need-help/#findComment-92599 Share on other sites More sharing options...
ahmed17 Posted September 15, 2006 Author Share Posted September 15, 2006 ..............? Quote Link to comment https://forums.phpfreaks.com/topic/20613-jokes-script-need-help/#findComment-92712 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.